setup.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import codecs
  2. import glob
  3. import os
  4. import re
  5. from pkg_resources import parse_requirements
  6. from setuptools import setup, find_packages
  7. from setuptools.command.develop import develop
  8. from setuptools.command.install import install
  9. def proto_compile(output_path):
  10. import grpc_tools.protoc
  11. cli_args = ['grpc_tools.protoc',
  12. '--proto_path=hivemind/proto', f'--python_out={output_path}',
  13. f'--grpc_python_out={output_path}'] + glob.glob('hivemind/proto/*.proto')
  14. code = grpc_tools.protoc.main(cli_args)
  15. if code: # hint: if you get this error in jupyter, run in console for richer error message
  16. raise ValueError(f"{' '.join(cli_args)} finished with exit code {code}")
  17. # Make pb2 imports in generated scripts relative
  18. for script in glob.iglob(f'{output_path}/*.py'):
  19. with open(script, 'r+') as file:
  20. code = file.read()
  21. file.seek(0)
  22. file.write(re.sub(r'\n(import .+_pb2.*)', 'from . \\1', code))
  23. file.truncate()
  24. class ProtoCompileInstall(install):
  25. def run(self):
  26. proto_compile(os.path.join(self.build_lib, 'hivemind', 'proto'))
  27. super().run()
  28. class ProtoCompileDevelop(develop):
  29. def run(self):
  30. proto_compile(os.path.join('hivemind', 'proto'))
  31. super().run()
  32. here = os.path.abspath(os.path.dirname(__file__))
  33. with open('requirements.txt') as requirements_file:
  34. install_requires = list(map(str, parse_requirements(requirements_file)))
  35. # loading version from setup.py
  36. with codecs.open(os.path.join(here, 'hivemind/__init__.py'), encoding='utf-8') as init_file:
  37. version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", init_file.read(), re.M)
  38. version_string = version_match.group(1)
  39. extras = {}
  40. with open('requirements-dev.txt') as dev_requirements_file:
  41. extras['dev'] = list(map(str, parse_requirements(dev_requirements_file)))
  42. with open('requirements-docs.txt') as docs_requirements_file:
  43. extras['docs'] = list(map(str, parse_requirements(docs_requirements_file)))
  44. extras['all'] = extras['dev'] + extras['docs']
  45. setup(
  46. name='hivemind',
  47. version=version_string,
  48. cmdclass={'install': ProtoCompileInstall, 'develop': ProtoCompileDevelop},
  49. description='Decentralized deep learning in PyTorch',
  50. long_description='Decentralized deep learning in PyTorch. Built to train giant models on '
  51. 'thousands of volunteers across the world.',
  52. author='Learning@home & contributors',
  53. author_email='mryabinin0@gmail.com',
  54. url="https://github.com/learning-at-home/hivemind",
  55. packages=find_packages(exclude=['tests']),
  56. package_data={'hivemind': ['proto/*']},
  57. include_package_data=True,
  58. license='MIT',
  59. setup_requires=['grpcio-tools'],
  60. install_requires=install_requires,
  61. extras_require=extras,
  62. classifiers=[
  63. 'Development Status :: 4 - Beta',
  64. 'Intended Audience :: Developers',
  65. 'Intended Audience :: Science/Research',
  66. 'License :: OSI Approved :: MIT License',
  67. 'Programming Language :: Python :: 3',
  68. 'Programming Language :: Python :: 3.7',
  69. 'Programming Language :: Python :: 3.8',
  70. 'Programming Language :: Python :: 3.9',
  71. 'Topic :: Scientific/Engineering',
  72. 'Topic :: Scientific/Engineering :: Mathematics',
  73. 'Topic :: Scientific/Engineering :: Artificial Intelligence',
  74. 'Topic :: Software Development',
  75. 'Topic :: Software Development :: Libraries',
  76. 'Topic :: Software Development :: Libraries :: Python Modules',
  77. ],
  78. entry_points={
  79. 'console_scripts': ['hivemind-server = hivemind.hivemind_cli.run_server:main', ]
  80. },
  81. # What does your project relate to?
  82. keywords='pytorch, deep learning, machine learning, gpu, distributed computing, volunteer computing, dht',
  83. )