setup.py 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import codecs
  2. import glob
  3. import os
  4. import re
  5. import grpc_tools.protoc
  6. from pkg_resources import parse_requirements
  7. from setuptools import setup, find_packages
  8. from setuptools.command.develop import develop
  9. from setuptools.command.install import install
  10. def proto_compile(output_path):
  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='mryabinin@hse.ru',
  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. install_requires=install_requires,
  60. extras_require=extras,
  61. classifiers=[
  62. 'Development Status :: 4 - Beta',
  63. 'Intended Audience :: Developers',
  64. 'Intended Audience :: Science/Research',
  65. 'License :: OSI Approved :: MIT License',
  66. 'Programming Language :: Python :: 3',
  67. 'Programming Language :: Python :: 3.8',
  68. 'Topic :: Scientific/Engineering',
  69. 'Topic :: Scientific/Engineering :: Mathematics',
  70. 'Topic :: Scientific/Engineering :: Artificial Intelligence',
  71. 'Topic :: Software Development',
  72. 'Topic :: Software Development :: Libraries',
  73. 'Topic :: Software Development :: Libraries :: Python Modules',
  74. ],
  75. entry_points={
  76. 'console_scripts': ['hivemind-server = scripts.run_server:main', ]
  77. },
  78. # What does your project relate to?
  79. keywords='pytorch, deep learning, machine learning, gpu, distributed computing, volunteer computing, dht',
  80. )