|
@@ -1,8 +1,43 @@
|
|
-from pkg_resources import parse_requirements
|
|
|
|
-from setuptools import setup
|
|
|
|
import codecs
|
|
import codecs
|
|
-import re
|
|
|
|
|
|
+import glob
|
|
import os
|
|
import os
|
|
|
|
+import re
|
|
|
|
+
|
|
|
|
+import grpc_tools.protoc
|
|
|
|
+from pkg_resources import parse_requirements
|
|
|
|
+from setuptools import setup, find_packages
|
|
|
|
+from setuptools.command.develop import develop
|
|
|
|
+from setuptools.command.install import install
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def proto_compile(output_path):
|
|
|
|
+ cli_args = ['grpc_tools.protoc',
|
|
|
|
+ '--proto_path=hivemind/proto', f'--python_out={output_path}',
|
|
|
|
+ f'--grpc_python_out={output_path}'] + glob.glob('hivemind/proto/*.proto')
|
|
|
|
+
|
|
|
|
+ code = grpc_tools.protoc.main(cli_args)
|
|
|
|
+ if code: # hint: if you get this error in jupyter, run in console for richer error message
|
|
|
|
+ raise ValueError(f"{' '.join(cli_args)} finished with exit code {code}")
|
|
|
|
+ # Make pb2 imports in generated scripts relative
|
|
|
|
+ for script in glob.iglob(f'{output_path}/*.py'):
|
|
|
|
+ with open(script, 'r+') as file:
|
|
|
|
+ code = file.read()
|
|
|
|
+ file.seek(0)
|
|
|
|
+ file.write(re.sub(r'\n(import .+_pb2.*)', 'from . \\1', code))
|
|
|
|
+ file.truncate()
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+class ProtoCompileInstall(install):
|
|
|
|
+ def run(self):
|
|
|
|
+ proto_compile(os.path.join(self.build_lib, 'hivemind', 'proto'))
|
|
|
|
+ super().run()
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+class ProtoCompileDevelop(develop):
|
|
|
|
+ def run(self):
|
|
|
|
+ proto_compile(os.path.join('hivemind', 'proto'))
|
|
|
|
+ super().run()
|
|
|
|
+
|
|
|
|
|
|
here = os.path.abspath(os.path.dirname(__file__))
|
|
here = os.path.abspath(os.path.dirname(__file__))
|
|
|
|
|
|
@@ -17,12 +52,15 @@ with codecs.open(os.path.join(here, 'hivemind/__init__.py'), encoding='utf-8') a
|
|
setup(
|
|
setup(
|
|
name='hivemind',
|
|
name='hivemind',
|
|
version=version_string,
|
|
version=version_string,
|
|
|
|
+ cmdclass={'install': ProtoCompileInstall, 'develop': ProtoCompileDevelop},
|
|
description='',
|
|
description='',
|
|
long_description='',
|
|
long_description='',
|
|
author='Learning@home authors',
|
|
author='Learning@home authors',
|
|
author_email='mryabinin@hse.ru',
|
|
author_email='mryabinin@hse.ru',
|
|
url="https://github.com/learning-at-home/hivemind",
|
|
url="https://github.com/learning-at-home/hivemind",
|
|
- packages=['hivemind'],
|
|
|
|
|
|
+ packages=find_packages(exclude=['tests']),
|
|
|
|
+ package_data={'hivemind': ['proto/*']},
|
|
|
|
+ include_package_data=True,
|
|
license='MIT',
|
|
license='MIT',
|
|
install_requires=install_requires,
|
|
install_requires=install_requires,
|
|
classifiers=[
|
|
classifiers=[
|