xref: /aosp_15_r20/tools/acloud/setup.py (revision 800a58d989c669b8eb8a71d8df53b1ba3d411444)
1*800a58d9SAndroid Build Coastguard Worker#!/usr/bin/env python
2*800a58d9SAndroid Build Coastguard Worker#
3*800a58d9SAndroid Build Coastguard Worker# Copyright 2018 - The Android Open Source Project
4*800a58d9SAndroid Build Coastguard Worker#
5*800a58d9SAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License");
6*800a58d9SAndroid Build Coastguard Worker# you may not use this file except in compliance with the License.
7*800a58d9SAndroid Build Coastguard Worker# You may obtain a copy of the License at
8*800a58d9SAndroid Build Coastguard Worker#
9*800a58d9SAndroid Build Coastguard Worker#     http://www.apache.org/licenses/LICENSE-2.0
10*800a58d9SAndroid Build Coastguard Worker#
11*800a58d9SAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software
12*800a58d9SAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS,
13*800a58d9SAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14*800a58d9SAndroid Build Coastguard Worker# See the License for the specific language governing permissions and
15*800a58d9SAndroid Build Coastguard Worker# limitations under the License.
16*800a58d9SAndroid Build Coastguard Worker"""setup.py to generate pb2.py from proto files."""
17*800a58d9SAndroid Build Coastguard Worker
18*800a58d9SAndroid Build Coastguard Workerfrom __future__ import print_function
19*800a58d9SAndroid Build Coastguard Worker
20*800a58d9SAndroid Build Coastguard Workertry:
21*800a58d9SAndroid Build Coastguard Worker    from distutils.spawn import find_executable
22*800a58d9SAndroid Build Coastguard Workerexcept ImportError:
23*800a58d9SAndroid Build Coastguard Worker    from shutil import which as find_executable
24*800a58d9SAndroid Build Coastguard Workerimport os
25*800a58d9SAndroid Build Coastguard Workerimport subprocess
26*800a58d9SAndroid Build Coastguard Workerimport sys
27*800a58d9SAndroid Build Coastguard Worker
28*800a58d9SAndroid Build Coastguard Workerimport setuptools
29*800a58d9SAndroid Build Coastguard Worker
30*800a58d9SAndroid Build Coastguard WorkerACLOUD_DIR = os.path.realpath(os.path.dirname(__file__))
31*800a58d9SAndroid Build Coastguard Worker
32*800a58d9SAndroid Build Coastguard Workertry:
33*800a58d9SAndroid Build Coastguard Worker    with open("README.md", "r") as fh:
34*800a58d9SAndroid Build Coastguard Worker        LONG_DESCRIPTION = fh.read()
35*800a58d9SAndroid Build Coastguard Workerexcept IOError:
36*800a58d9SAndroid Build Coastguard Worker    LONG_DESCRIPTION = ""
37*800a58d9SAndroid Build Coastguard Worker
38*800a58d9SAndroid Build Coastguard Worker# Find the Protocol Compiler. (Taken from protobuf/python/setup.py)
39*800a58d9SAndroid Build Coastguard Workerif "PROTOC" in os.environ and os.path.exists(os.environ["PROTOC"]):
40*800a58d9SAndroid Build Coastguard Worker    PROTOC = os.environ["PROTOC"]
41*800a58d9SAndroid Build Coastguard Workerelse:
42*800a58d9SAndroid Build Coastguard Worker    PROTOC = find_executable("protoc")
43*800a58d9SAndroid Build Coastguard Worker
44*800a58d9SAndroid Build Coastguard Worker
45*800a58d9SAndroid Build Coastguard Workerdef GenerateProto(source):
46*800a58d9SAndroid Build Coastguard Worker    """Generate a _pb2.py from a .proto file.
47*800a58d9SAndroid Build Coastguard Worker
48*800a58d9SAndroid Build Coastguard Worker    Invokes the Protocol Compiler to generate a _pb2.py from the given
49*800a58d9SAndroid Build Coastguard Worker    .proto file.  Does nothing if the output already exists and is newer than
50*800a58d9SAndroid Build Coastguard Worker    the input.
51*800a58d9SAndroid Build Coastguard Worker
52*800a58d9SAndroid Build Coastguard Worker    Args:
53*800a58d9SAndroid Build Coastguard Worker      source: The source proto file that needs to be compiled.
54*800a58d9SAndroid Build Coastguard Worker    """
55*800a58d9SAndroid Build Coastguard Worker
56*800a58d9SAndroid Build Coastguard Worker    output = source.replace(".proto", "_pb2.py")
57*800a58d9SAndroid Build Coastguard Worker
58*800a58d9SAndroid Build Coastguard Worker    if not os.path.exists(output) or (
59*800a58d9SAndroid Build Coastguard Worker            os.path.exists(source) and
60*800a58d9SAndroid Build Coastguard Worker            os.path.getmtime(source) > os.path.getmtime(output)):
61*800a58d9SAndroid Build Coastguard Worker        print("Generating %s..." % output)
62*800a58d9SAndroid Build Coastguard Worker
63*800a58d9SAndroid Build Coastguard Worker        if not os.path.exists(source):
64*800a58d9SAndroid Build Coastguard Worker            sys.stderr.write("Can't find required file: %s\n" % source)
65*800a58d9SAndroid Build Coastguard Worker            sys.exit(-1)
66*800a58d9SAndroid Build Coastguard Worker
67*800a58d9SAndroid Build Coastguard Worker        if PROTOC is None:
68*800a58d9SAndroid Build Coastguard Worker            sys.stderr.write(
69*800a58d9SAndroid Build Coastguard Worker                "protoc is not found.  Please compile it "
70*800a58d9SAndroid Build Coastguard Worker                "or install the binary package.\n"
71*800a58d9SAndroid Build Coastguard Worker            )
72*800a58d9SAndroid Build Coastguard Worker            sys.exit(-1)
73*800a58d9SAndroid Build Coastguard Worker
74*800a58d9SAndroid Build Coastguard Worker        protoc_command = [PROTOC, "-I%s" % ACLOUD_DIR, "--python_out=.", source]
75*800a58d9SAndroid Build Coastguard Worker        if subprocess.call(protoc_command) != 0:
76*800a58d9SAndroid Build Coastguard Worker            sys.exit(-1)
77*800a58d9SAndroid Build Coastguard Worker
78*800a58d9SAndroid Build Coastguard Worker
79*800a58d9SAndroid Build Coastguard Worker# Generate the protobuf files that we depend on.
80*800a58d9SAndroid Build Coastguard WorkerGenerateProto(os.path.join(ACLOUD_DIR, "internal/proto/user_config.proto"))
81*800a58d9SAndroid Build Coastguard WorkerGenerateProto(os.path.join(ACLOUD_DIR, "internal/proto/internal_config.proto"))
82*800a58d9SAndroid Build Coastguard Workeropen(os.path.join(ACLOUD_DIR, "internal/proto/__init__.py"), "a").close()
83*800a58d9SAndroid Build Coastguard Worker
84*800a58d9SAndroid Build Coastguard Workersetuptools.setup(
85*800a58d9SAndroid Build Coastguard Worker    python_requires=">=2",
86*800a58d9SAndroid Build Coastguard Worker    name="acloud",
87*800a58d9SAndroid Build Coastguard Worker    version="1.0",
88*800a58d9SAndroid Build Coastguard Worker    setup_requires=["pytest-runner"],
89*800a58d9SAndroid Build Coastguard Worker    tests_require=["pytest", "mock"],
90*800a58d9SAndroid Build Coastguard Worker    author="Kevin Cheng, Keun Soo Yim",
91*800a58d9SAndroid Build Coastguard Worker    author_email="[email protected], [email protected]",
92*800a58d9SAndroid Build Coastguard Worker    description="Acloud is a command line tool that assists users to "
93*800a58d9SAndroid Build Coastguard Worker    "create an Android Virtual Device (AVD).",
94*800a58d9SAndroid Build Coastguard Worker    long_description=LONG_DESCRIPTION,
95*800a58d9SAndroid Build Coastguard Worker    long_description_content_type="text/markdown",
96*800a58d9SAndroid Build Coastguard Worker    packages=[
97*800a58d9SAndroid Build Coastguard Worker        "acloud",
98*800a58d9SAndroid Build Coastguard Worker        "acloud.internal",
99*800a58d9SAndroid Build Coastguard Worker        "acloud.public",
100*800a58d9SAndroid Build Coastguard Worker        "acloud.delete",
101*800a58d9SAndroid Build Coastguard Worker        "acloud.create",
102*800a58d9SAndroid Build Coastguard Worker        "acloud.setup",
103*800a58d9SAndroid Build Coastguard Worker        "acloud.metrics",
104*800a58d9SAndroid Build Coastguard Worker        "acloud.internal.lib",
105*800a58d9SAndroid Build Coastguard Worker        "acloud.internal.proto",
106*800a58d9SAndroid Build Coastguard Worker        "acloud.public.data",
107*800a58d9SAndroid Build Coastguard Worker        "acloud.public.acloud_kernel",
108*800a58d9SAndroid Build Coastguard Worker        "acloud.public.actions",
109*800a58d9SAndroid Build Coastguard Worker        "acloud.pull",
110*800a58d9SAndroid Build Coastguard Worker        "acloud.reconnect",
111*800a58d9SAndroid Build Coastguard Worker        "acloud.list",
112*800a58d9SAndroid Build Coastguard Worker    ],
113*800a58d9SAndroid Build Coastguard Worker    package_dir={"acloud": ".",},
114*800a58d9SAndroid Build Coastguard Worker    package_data={"acloud.public.data": ["default.config"]},
115*800a58d9SAndroid Build Coastguard Worker    include_package_data=True,
116*800a58d9SAndroid Build Coastguard Worker    platforms="POSIX",
117*800a58d9SAndroid Build Coastguard Worker    entry_points={"console_scripts": ["acloud=acloud.public.acloud_main:main"],},
118*800a58d9SAndroid Build Coastguard Worker    install_requires=[
119*800a58d9SAndroid Build Coastguard Worker        "google-api-python-client",
120*800a58d9SAndroid Build Coastguard Worker        "oauth2client==3.0.0",
121*800a58d9SAndroid Build Coastguard Worker        "protobuf",
122*800a58d9SAndroid Build Coastguard Worker        "python-dateutil",
123*800a58d9SAndroid Build Coastguard Worker    ],
124*800a58d9SAndroid Build Coastguard Worker    license="Apache License, Version 2.0",
125*800a58d9SAndroid Build Coastguard Worker    classifiers=[
126*800a58d9SAndroid Build Coastguard Worker        "Programming Language :: Python :: 2",
127*800a58d9SAndroid Build Coastguard Worker        "Programming Language :: Python :: 3",
128*800a58d9SAndroid Build Coastguard Worker        "License :: OSI Approved :: Apache Software License",
129*800a58d9SAndroid Build Coastguard Worker        "Natural Language :: English",
130*800a58d9SAndroid Build Coastguard Worker        "Environment :: Console",
131*800a58d9SAndroid Build Coastguard Worker        "Intended Audience :: Developers",
132*800a58d9SAndroid Build Coastguard Worker        "Topic :: Utilities",
133*800a58d9SAndroid Build Coastguard Worker    ],
134*800a58d9SAndroid Build Coastguard Worker)
135