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 | |
| 20 | from distutils.spawn import find_executable |
| 21 | import os |
| 22 | import subprocess |
| 23 | import sys |
| 24 | |
| 25 | import setuptools |
| 26 | |
| 27 | ACLOUD_DIR = os.path.realpath(os.path.dirname(__file__)) |
| 28 | |
| 29 | try: |
| 30 | with open("README.md", "r") as fh: |
| 31 | LONG_DESCRIPTION = fh.read() |
| 32 | except IOError: |
| 33 | LONG_DESCRIPTION = "" |
| 34 | |
| 35 | # Find the Protocol Compiler. (Taken from protobuf/python/setup.py) |
| 36 | if "PROTOC" in os.environ and os.path.exists(os.environ["PROTOC"]): |
| 37 | PROTOC = os.environ["PROTOC"] |
| 38 | else: |
| 39 | PROTOC = find_executable("protoc") |
| 40 | |
| 41 | |
herbertxue | a369fc5 | 2019-11-07 20:28:33 +0800 | [diff] [blame] | 42 | def GenerateProto(source): |
Erwin Jansen | 9555924 | 2018-11-08 15:38:18 -0800 | [diff] [blame] | 43 | """Generate a _pb2.py from a .proto file. |
| 44 | |
| 45 | Invokes the Protocol Compiler to generate a _pb2.py from the given |
| 46 | .proto file. Does nothing if the output already exists and is newer than |
| 47 | the input. |
| 48 | |
| 49 | Args: |
| 50 | source: The source proto file that needs to be compiled. |
| 51 | """ |
| 52 | |
| 53 | output = source.replace(".proto", "_pb2.py") |
| 54 | |
| 55 | if (not os.path.exists(output) or (os.path.exists(source) and |
| 56 | os.path.getmtime(source) > os.path.getmtime(output))): |
herbertxue | a369fc5 | 2019-11-07 20:28:33 +0800 | [diff] [blame] | 57 | print("Generating %s..." % output) |
Erwin Jansen | 9555924 | 2018-11-08 15:38:18 -0800 | [diff] [blame] | 58 | |
| 59 | if not os.path.exists(source): |
| 60 | sys.stderr.write("Can't find required file: %s\n" % source) |
| 61 | sys.exit(-1) |
| 62 | |
| 63 | if PROTOC is None: |
| 64 | sys.stderr.write( |
| 65 | "protoc is not found. Please compile it " |
| 66 | "or install the binary package.\n") |
| 67 | sys.exit(-1) |
| 68 | |
herbertxue | a369fc5 | 2019-11-07 20:28:33 +0800 | [diff] [blame] | 69 | protoc_command = [PROTOC, "-I%s" % ACLOUD_DIR, "--python_out=.", source] |
Erwin Jansen | 9555924 | 2018-11-08 15:38:18 -0800 | [diff] [blame] | 70 | if subprocess.call(protoc_command) != 0: |
| 71 | sys.exit(-1) |
| 72 | |
| 73 | |
| 74 | # Generate the protobuf files that we depend on. |
herbertxue | a369fc5 | 2019-11-07 20:28:33 +0800 | [diff] [blame] | 75 | GenerateProto(os.path.join(ACLOUD_DIR, "internal/proto/user_config.proto")) |
| 76 | GenerateProto(os.path.join(ACLOUD_DIR, "internal/proto/internal_config.proto")) |
Erwin Jansen | 9555924 | 2018-11-08 15:38:18 -0800 | [diff] [blame] | 77 | open(os.path.join(ACLOUD_DIR, "internal/proto/__init__.py"), "a").close() |
| 78 | |
| 79 | setuptools.setup( |
| 80 | python_requires=">=2", |
| 81 | name="acloud", |
| 82 | version="1.0", |
Erwin Jansen | f39798d | 2019-05-14 21:06:44 -0700 | [diff] [blame] | 83 | setup_requires=["pytest-runner"], |
| 84 | tests_require=["pytest", "mock"], |
Erwin Jansen | 9555924 | 2018-11-08 15:38:18 -0800 | [diff] [blame] | 85 | author="Kevin Cheng, Keun Soo Yim", |
| 86 | author_email="kevcheng@google.com, yim@google.com", |
| 87 | description="Acloud is a command line tool that assists users to " |
| 88 | "create an Android Virtual Device (AVD).", |
| 89 | long_description=LONG_DESCRIPTION, |
| 90 | long_description_content_type="text/markdown", |
| 91 | packages=[ |
| 92 | "acloud", "acloud.internal", "acloud.public", "acloud.delete", |
| 93 | "acloud.create", "acloud.setup", "acloud.metrics", |
| 94 | "acloud.internal.lib", "acloud.internal.proto", "acloud.public.data", |
Erwin Jansen | dcf99f5 | 2019-03-29 14:14:27 -0700 | [diff] [blame] | 95 | "acloud.public.acloud_kernel", "acloud.public.actions", "acloud.reconnect", |
| 96 | "acloud.list", |
Erwin Jansen | 9555924 | 2018-11-08 15:38:18 -0800 | [diff] [blame] | 97 | ], |
| 98 | package_dir={ |
| 99 | "acloud": ".", |
Erwin Jansen | 9555924 | 2018-11-08 15:38:18 -0800 | [diff] [blame] | 100 | }, |
| 101 | package_data={"acloud.public.data": ["default.config"]}, |
| 102 | include_package_data=True, |
| 103 | platforms="POSIX", |
| 104 | entry_points={ |
| 105 | "console_scripts": ["acloud=acloud.public.acloud_main:main"], |
| 106 | }, |
| 107 | install_requires=[ |
| 108 | "google-api-python-client", "oauth2client==3.0.0", "protobuf", |
| 109 | "python-dateutil" |
| 110 | ], |
| 111 | license="Apache License, Version 2.0", |
| 112 | classifiers=[ |
| 113 | "Programming Language :: Python :: 2", |
| 114 | "Programming Language :: Python :: 3", |
| 115 | "License :: OSI Approved :: Apache Software License", |
| 116 | "Natural Language :: English", |
| 117 | "Environment :: Console", |
| 118 | "Intended Audience :: Developers", |
| 119 | "Topic :: Utilities", |
| 120 | ]) |