2020-02-22 19:33:40 -08:00
|
|
|
import io
|
2020-12-26 01:00:58 -08:00
|
|
|
import os
|
|
|
|
|
import pkg_resources
|
|
|
|
|
import sys
|
2020-02-22 19:33:40 -08:00
|
|
|
|
2020-08-20 04:41:35 -07:00
|
|
|
import setuptools.command.build_py
|
2020-12-25 20:17:54 -08:00
|
|
|
import setuptools.command.test
|
2020-09-26 01:51:41 -07:00
|
|
|
from setuptools import find_packages, setup
|
2020-10-28 14:26:25 -04:00
|
|
|
from setuptools import Command
|
2020-08-20 04:41:35 -07:00
|
|
|
|
2020-12-26 01:00:58 -08:00
|
|
|
from grpc_tools import protoc
|
|
|
|
|
|
|
|
|
|
|
2020-08-20 04:41:35 -07:00
|
|
|
PACKAGE_DIRECTORIES = {
|
|
|
|
|
'': '.',
|
|
|
|
|
}
|
2020-02-22 19:33:40 -08:00
|
|
|
|
2020-07-02 21:18:10 -07:00
|
|
|
with io.open("README.md", "rt", encoding="utf8") as f:
|
2020-02-22 19:33:40 -08:00
|
|
|
readme = f.read()
|
|
|
|
|
|
2020-08-20 04:41:35 -07:00
|
|
|
|
|
|
|
|
class BuildPyCommand(setuptools.command.build_py.build_py):
|
2020-09-26 01:51:41 -07:00
|
|
|
"""Custom build command."""
|
2020-08-20 04:41:35 -07:00
|
|
|
|
2020-09-26 01:51:41 -07:00
|
|
|
def run(self):
|
|
|
|
|
self.run_command('build_proto_modules')
|
|
|
|
|
setuptools.command.build_py.build_py.run(self)
|
2020-08-20 04:41:35 -07:00
|
|
|
|
|
|
|
|
|
2020-12-26 01:00:58 -08:00
|
|
|
def build_package_protos(package_root, strict_mode=False):
|
|
|
|
|
proto_files = []
|
|
|
|
|
inclusion_root = os.path.abspath(package_root)
|
|
|
|
|
for root, _, files in os.walk(inclusion_root):
|
|
|
|
|
for filename in files:
|
|
|
|
|
if filename.endswith('.proto'):
|
|
|
|
|
proto_files.append(os.path.abspath(os.path.join(root,
|
|
|
|
|
filename)))
|
|
|
|
|
|
|
|
|
|
well_known_protos_include = pkg_resources.resource_filename(
|
|
|
|
|
'grpc_tools', '_proto')
|
|
|
|
|
|
|
|
|
|
for proto_file in proto_files:
|
|
|
|
|
command = [
|
|
|
|
|
'grpc_tools.protoc',
|
|
|
|
|
'--proto_path={}'.format(inclusion_root),
|
|
|
|
|
'--proto_path={}'.format(well_known_protos_include),
|
|
|
|
|
'--python_out={}'.format(inclusion_root),
|
|
|
|
|
'--grpc_python_out={}'.format(inclusion_root),
|
|
|
|
|
'--mypy_out={}'.format(inclusion_root),
|
|
|
|
|
] + [proto_file]
|
|
|
|
|
if protoc.main(command) != 0:
|
|
|
|
|
if strict_mode:
|
|
|
|
|
raise Exception('error: {} failed'.format(command))
|
|
|
|
|
else:
|
|
|
|
|
sys.stderr.write('warning: {} failed'.format(command))
|
2020-12-25 20:17:54 -08:00
|
|
|
|
|
|
|
|
|
2020-10-28 14:26:25 -04:00
|
|
|
class BuildPackageProtos(Command):
|
|
|
|
|
"""Command to generate project *_pb2.py modules from proto files."""
|
|
|
|
|
|
|
|
|
|
description = 'build grpc protobuf modules'
|
|
|
|
|
user_options = []
|
|
|
|
|
|
|
|
|
|
def initialize_options(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def finalize_options(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def run(self):
|
2020-12-26 01:00:58 -08:00
|
|
|
# import grpc_tools.command
|
|
|
|
|
# grpc_tools.command.build_package_protos('.')
|
|
|
|
|
build_package_protos('.')
|
2020-10-28 14:26:25 -04:00
|
|
|
|
2020-02-22 19:33:40 -08:00
|
|
|
setup(
|
2020-10-29 14:35:17 -04:00
|
|
|
name="squeaknode",
|
2020-02-22 19:33:40 -08:00
|
|
|
version="1.0.0",
|
2020-10-29 14:35:17 -04:00
|
|
|
url="https://github.com/yzernik/squeaknode",
|
2020-06-04 17:10:00 -07:00
|
|
|
description="Server for squeak protocol.",
|
2020-02-22 19:33:40 -08:00
|
|
|
long_description=readme,
|
|
|
|
|
packages=find_packages(),
|
2020-10-28 14:26:25 -04:00
|
|
|
#package_dir=PACKAGE_DIRECTORIES,
|
2020-02-22 19:33:40 -08:00
|
|
|
include_package_data=True,
|
|
|
|
|
zip_safe=False,
|
|
|
|
|
extras_require={"test": ["pytest", "coverage"]},
|
2020-03-01 00:15:24 -08:00
|
|
|
entry_points={
|
|
|
|
|
'console_scripts': [
|
2020-10-29 14:35:17 -04:00
|
|
|
'runsqueaknode = squeaknode.main:main',
|
2020-03-01 00:15:24 -08:00
|
|
|
],
|
|
|
|
|
},
|
2020-08-20 04:41:35 -07:00
|
|
|
cmdclass={
|
|
|
|
|
'build_proto_modules': BuildPackageProtos,
|
|
|
|
|
'build_py': BuildPyCommand,
|
|
|
|
|
},
|
2020-02-22 19:33:40 -08:00
|
|
|
)
|