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