squeaknode/setup.py
Jonathan Zernik f587acc095
Use typedconfig with repr function (#1255)
* Use typedconfig with repr function

* Pin version of typedconfig in requirements.txt
2021-09-09 18:06:14 -07:00

135 lines
4.2 KiB
Python

# MIT License
#
# Copyright (c) 2020 Jonathan Zernik
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import os
import sys
from typing import List
from typing import Tuple
import pkg_resources
import setuptools.command.build_py
import setuptools.command.test
from grpc_tools import protoc
from setuptools import Command
from setuptools import find_packages
from setuptools import setup
from squeaknode import __version__
PACKAGE_DIRECTORIES = {
'': '.',
}
class BuildPyCommand(setuptools.command.build_py.build_py):
"""Custom build command."""
def run(self):
self.run_command('build_proto_modules')
setuptools.command.build_py.build_py.run(self)
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))
class BuildPackageProtos(Command):
"""Command to generate project *_pb2.py modules from proto files."""
description = 'build grpc protobuf modules'
user_options: List[Tuple[str, str, str]] = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
# import grpc_tools.command
# grpc_tools.command.build_package_protos('.')
build_package_protos('.')
setup(
name="squeaknode",
version=__version__,
url="https://github.com/yzernik/squeaknode",
description="Server for squeak protocol.",
packages=find_packages(),
# package_dir=PACKAGE_DIRECTORIES,
include_package_data=True,
zip_safe=False,
install_requires=[
'squeakpy>=0.7.3',
'importlib_resources',
'argparse',
'googleapis-common-protos',
'grpcio>=1.34.0',
'grpcio-tools',
'mypy-protobuf',
'psycopg2',
'requests',
'SQLAlchemy>=1.3.0,<1.4.0',
'Flask',
'protobuf',
'flask-login',
'Flask-WTF',
'flask-cors',
'alembic',
'PySocks',
'typed-config>=0.2.2,<2.3.0',
],
extras_require={"test": ["pytest", "coverage"]},
entry_points={
'console_scripts': [
'squeaknode = squeaknode.main:main',
],
},
cmdclass={
'build_proto_modules': BuildPackageProtos,
'build_py': BuildPyCommand,
},
)