setup.py 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 = [str(requirement) for requirement in 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. setup(
  40. name='hivemind',
  41. version=version_string,
  42. cmdclass={'install': ProtoCompileInstall, 'develop': ProtoCompileDevelop},
  43. description='Decentralized deep learning framework in pytorch.',
  44. long_description='Decentralized deep learning framework in pytorch. Built to train giant models on '
  45. 'thousands on volunteers across the world. ',
  46. author='Learning@home & contributors',
  47. author_email='mryabinin@hse.ru',
  48. url="https://github.com/learning-at-home/hivemind",
  49. packages=find_packages(exclude=['tests']),
  50. package_data={'hivemind': ['proto/*']},
  51. include_package_data=True,
  52. license='MIT',
  53. install_requires=install_requires,
  54. classifiers=[
  55. 'Development Status :: 4 - Beta',
  56. 'Intended Audience :: Developers',
  57. 'Intended Audience :: Science/Research',
  58. 'License :: OSI Approved :: MIT License',
  59. 'Programming Language :: Python :: 3',
  60. 'Programming Language :: Python :: 3.8',
  61. 'Topic :: Scientific/Engineering',
  62. 'Topic :: Scientific/Engineering :: Mathematics',
  63. 'Topic :: Scientific/Engineering :: Artificial Intelligence',
  64. 'Topic :: Software Development',
  65. 'Topic :: Software Development :: Libraries',
  66. 'Topic :: Software Development :: Libraries :: Python Modules',
  67. ],
  68. # What does your project relate to?
  69. keywords='pytorch, deep learning, machine learning, gpu, distributed computing, volunteer computing, dht',
  70. )