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"""setup.py to generate pb2.py from proto files.""" 17 18from __future__ import print_function 19 20try: 21 from distutils.spawn import find_executable 22except ImportError: 23 from shutil import which as find_executable 24import os 25import subprocess 26import sys 27 28import setuptools 29 30ACLOUD_DIR = os.path.realpath(os.path.dirname(__file__)) 31 32try: 33 with open("README.md", "r") as fh: 34 LONG_DESCRIPTION = fh.read() 35except IOError: 36 LONG_DESCRIPTION = "" 37 38# Find the Protocol Compiler. (Taken from protobuf/python/setup.py) 39if "PROTOC" in os.environ and os.path.exists(os.environ["PROTOC"]): 40 PROTOC = os.environ["PROTOC"] 41else: 42 PROTOC = find_executable("protoc") 43 44 45def GenerateProto(source): 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 58 if not os.path.exists(output) or ( 59 os.path.exists(source) and 60 os.path.getmtime(source) > os.path.getmtime(output)): 61 print("Generating %s..." % output) 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 " 70 "or install the binary package.\n" 71 ) 72 sys.exit(-1) 73 74 protoc_command = [PROTOC, "-I%s" % ACLOUD_DIR, "--python_out=.", source] 75 if subprocess.call(protoc_command) != 0: 76 sys.exit(-1) 77 78 79# Generate the protobuf files that we depend on. 80GenerateProto(os.path.join(ACLOUD_DIR, "internal/proto/user_config.proto")) 81GenerateProto(os.path.join(ACLOUD_DIR, "internal/proto/internal_config.proto")) 82open(os.path.join(ACLOUD_DIR, "internal/proto/__init__.py"), "a").close() 83 84setuptools.setup( 85 python_requires=">=2", 86 name="acloud", 87 version="1.0", 88 setup_requires=["pytest-runner"], 89 tests_require=["pytest", "mock"], 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 " 93 "create an Android Virtual Device (AVD).", 94 long_description=LONG_DESCRIPTION, 95 long_description_content_type="text/markdown", 96 packages=[ 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", 111 "acloud.list", 112 ], 113 package_dir={"acloud": ".",}, 114 package_data={"acloud.public.data": ["default.config"]}, 115 include_package_data=True, 116 platforms="POSIX", 117 entry_points={"console_scripts": ["acloud=acloud.public.acloud_main:main"],}, 118 install_requires=[ 119 "google-api-python-client", 120 "oauth2client==3.0.0", 121 "protobuf", 122 "python-dateutil", 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", 133 ], 134) 135