xref: /aosp_15_r20/external/grpc-grpc/src/python/grpcio_testing/setup.py (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
1# Copyright 2017 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 gRPC Python's testing package."""
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 that we can find same-directory 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
47PACKAGE_DIRECTORIES = {
48    "": ".",
49}
50
51INSTALL_REQUIRES = (
52    "protobuf>=5.26.1,<6.0dev",
53    "grpcio>={version}".format(version=grpc_version.VERSION),
54)
55
56try:
57    import testing_commands as _testing_commands
58
59    # we are in the build environment, otherwise the above import fails
60    COMMAND_CLASS = {
61        # Run preprocess from the repository *before* doing any packaging!
62        "preprocess": _testing_commands.Preprocess,
63    }
64except ImportError:
65    COMMAND_CLASS = {
66        # wire up commands to no-op not to break the external dependencies
67        "preprocess": _NoOpCommand,
68    }
69
70setuptools.setup(
71    name="grpcio-testing",
72    version=grpc_version.VERSION,
73    license="Apache License 2.0",
74    description="Testing utilities for gRPC Python",
75    long_description=open(_README_PATH, "r").read(),
76    author="The gRPC Authors",
77    author_email="[email protected]",
78    url="https://grpc.io",
79    package_dir=PACKAGE_DIRECTORIES,
80    packages=setuptools.find_packages("."),
81    install_requires=INSTALL_REQUIRES,
82    cmdclass=COMMAND_CLASS,
83)
84