setup.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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='',
  44. long_description='',
  45. author='Learning@home authors',
  46. author_email='mryabinin@hse.ru',
  47. url="https://github.com/learning-at-home/hivemind",
  48. packages=find_packages(exclude=['tests']),
  49. package_data={'hivemind': ['proto/*']},
  50. include_package_data=True,
  51. license='MIT',
  52. install_requires=install_requires,
  53. classifiers=[
  54. 'Development Status :: 4 - Beta',
  55. 'Intended Audience :: Developers',
  56. 'Intended Audience :: Science/Research',
  57. 'License :: OSI Approved :: MIT License',
  58. 'Programming Language :: Python :: 3',
  59. 'Programming Language :: Python :: 3.8',
  60. 'Topic :: Scientific/Engineering',
  61. 'Topic :: Scientific/Engineering :: Mathematics',
  62. 'Topic :: Scientific/Engineering :: Artificial Intelligence',
  63. 'Topic :: Software Development',
  64. 'Topic :: Software Development :: Libraries',
  65. 'Topic :: Software Development :: Libraries :: Python Modules',
  66. ],
  67. # What does your project relate to?
  68. keywords='pytorch, deep learning, machine learning, gpu, distributed computing',
  69. )