xref: /aosp_15_r20/external/grpc-grpc/src/python/grpcio_reflection/setup.py (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
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 grpc_version
29
30
31class _NoOpCommand(setuptools.Command):
32    """No-op command."""
33
34    description = ""
35    user_options = []
36
37    def initialize_options(self):
38        pass
39
40    def finalize_options(self):
41        pass
42
43    def run(self):
44        pass
45
46
47CLASSIFIERS = [
48    "Development Status :: 5 - Production/Stable",
49    "Programming Language :: Python",
50    "Programming Language :: Python :: 3",
51    "Programming Language :: Python :: 3.8",
52    "Programming Language :: Python :: 3.9",
53    "Programming Language :: Python :: 3.10",
54    "Programming Language :: Python :: 3.11",
55    "Programming Language :: Python :: 3.12",
56    "License :: OSI Approved :: Apache Software License",
57]
58
59PACKAGE_DIRECTORIES = {
60    "": ".",
61}
62
63INSTALL_REQUIRES = (
64    "protobuf>=5.26.1,<6.0dev",
65    "grpcio>={version}".format(version=grpc_version.VERSION),
66)
67
68try:
69    import reflection_commands as _reflection_commands
70
71    # we are in the build environment, otherwise the above import fails
72    SETUP_REQUIRES = (
73        "grpcio-tools=={version}".format(version=grpc_version.VERSION),
74    )
75    COMMAND_CLASS = {
76        # Run preprocess from the repository *before* doing any packaging!
77        "preprocess": _reflection_commands.Preprocess,
78        "build_package_protos": _reflection_commands.BuildPackageProtos,
79    }
80except ImportError:
81    SETUP_REQUIRES = ()
82    COMMAND_CLASS = {
83        # wire up commands to no-op not to break the external dependencies
84        "preprocess": _NoOpCommand,
85        "build_package_protos": _NoOpCommand,
86    }
87
88setuptools.setup(
89    name="grpcio-reflection",
90    version=grpc_version.VERSION,
91    license="Apache License 2.0",
92    description="Standard Protobuf Reflection Service for gRPC",
93    long_description=open(_README_PATH, "r").read(),
94    author="The gRPC Authors",
95    author_email="[email protected]",
96    classifiers=CLASSIFIERS,
97    url="https://grpc.io",
98    package_dir=PACKAGE_DIRECTORIES,
99    packages=setuptools.find_packages("."),
100    python_requires=">=3.8",
101    install_requires=INSTALL_REQUIRES,
102    setup_requires=SETUP_REQUIRES,
103    cmdclass=COMMAND_CLASS,
104)
105