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