• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2016 gRPC authors.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14"""Setup module for the GRPC Python package's optional reflection."""
15
16import os
17import sys
18
19import setuptools
20
21_PACKAGE_PATH = os.path.realpath(os.path.dirname(__file__))
22_README_PATH = os.path.join(_PACKAGE_PATH, "README.rst")
23
24# Ensure we're in the proper directory whether or not we're being used by pip.
25os.chdir(os.path.dirname(os.path.abspath(__file__)))
26
27# Break import-style to ensure we can actually find our local modules.
28import python_version
29
30import grpc_version
31
32
33class _NoOpCommand(setuptools.Command):
34    """No-op command."""
35
36    description = ""
37    user_options = []
38
39    def initialize_options(self):
40        pass
41
42    def finalize_options(self):
43        pass
44
45    def run(self):
46        pass
47
48
49CLASSIFIERS = (
50    [
51        "Development Status :: 5 - Production/Stable",
52        "Programming Language :: Python",
53        "Programming Language :: Python :: 3",
54    ]
55    + [
56        f"Programming Language :: Python :: {x}"
57        for x in python_version.SUPPORTED_PYTHON_VERSIONS
58    ]
59    + ["License :: OSI Approved :: Apache Software License"]
60)
61
62PACKAGE_DIRECTORIES = {
63    "": ".",
64}
65
66INSTALL_REQUIRES = (
67    "protobuf>=5.26.1,<6.0dev",
68    "grpcio>={version}".format(version=grpc_version.VERSION),
69)
70
71try:
72    import reflection_commands as _reflection_commands
73
74    # we are in the build environment, otherwise the above import fails
75    SETUP_REQUIRES = (
76        "grpcio-tools=={version}".format(version=grpc_version.VERSION),
77    )
78    COMMAND_CLASS = {
79        # Run preprocess from the repository *before* doing any packaging!
80        "preprocess": _reflection_commands.Preprocess,
81        "build_package_protos": _reflection_commands.BuildPackageProtos,
82    }
83except ImportError:
84    SETUP_REQUIRES = ()
85    COMMAND_CLASS = {
86        # wire up commands to no-op not to break the external dependencies
87        "preprocess": _NoOpCommand,
88        "build_package_protos": _NoOpCommand,
89    }
90
91setuptools.setup(
92    name="grpcio-reflection",
93    version=grpc_version.VERSION,
94    license="Apache License 2.0",
95    description="Standard Protobuf Reflection Service for gRPC",
96    long_description=open(_README_PATH, "r").read(),
97    author="The gRPC Authors",
98    author_email="grpc-io@googlegroups.com",
99    classifiers=CLASSIFIERS,
100    url="https://grpc.io",
101    package_dir=PACKAGE_DIRECTORIES,
102    packages=setuptools.find_packages("."),
103    python_requires=f">={python_version.MIN_PYTHON_VERSION}",
104    install_requires=INSTALL_REQUIRES,
105    setup_requires=SETUP_REQUIRES,
106    cmdclass=COMMAND_CLASS,
107)
108