blob: 0535dfede623c659369829e42d1b228800a22b54 [file] [log] [blame]
Erwin Jansen95559242018-11-08 15:38:18 -08001#!/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.
herbertxuea369fc52019-11-07 20:28:33 +080016"""setup.py to generate pb2.py from proto files."""
17
18from __future__ import print_function
Erwin Jansen95559242018-11-08 15:38:18 -080019
20from distutils.spawn import find_executable
21import os
22import subprocess
23import sys
24
25import setuptools
26
27ACLOUD_DIR = os.path.realpath(os.path.dirname(__file__))
28
29try:
30 with open("README.md", "r") as fh:
31 LONG_DESCRIPTION = fh.read()
32except IOError:
33 LONG_DESCRIPTION = ""
34
35# Find the Protocol Compiler. (Taken from protobuf/python/setup.py)
36if "PROTOC" in os.environ and os.path.exists(os.environ["PROTOC"]):
37 PROTOC = os.environ["PROTOC"]
38else:
39 PROTOC = find_executable("protoc")
40
41
herbertxuea369fc52019-11-07 20:28:33 +080042def GenerateProto(source):
Erwin Jansen95559242018-11-08 15:38:18 -080043 """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))):
herbertxuea369fc52019-11-07 20:28:33 +080057 print("Generating %s..." % output)
Erwin Jansen95559242018-11-08 15:38:18 -080058
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
herbertxuea369fc52019-11-07 20:28:33 +080069 protoc_command = [PROTOC, "-I%s" % ACLOUD_DIR, "--python_out=.", source]
Erwin Jansen95559242018-11-08 15:38:18 -080070 if subprocess.call(protoc_command) != 0:
71 sys.exit(-1)
72
73
74# Generate the protobuf files that we depend on.
herbertxuea369fc52019-11-07 20:28:33 +080075GenerateProto(os.path.join(ACLOUD_DIR, "internal/proto/user_config.proto"))
76GenerateProto(os.path.join(ACLOUD_DIR, "internal/proto/internal_config.proto"))
Erwin Jansen95559242018-11-08 15:38:18 -080077open(os.path.join(ACLOUD_DIR, "internal/proto/__init__.py"), "a").close()
78
79setuptools.setup(
80 python_requires=">=2",
81 name="acloud",
82 version="1.0",
Erwin Jansenf39798d2019-05-14 21:06:44 -070083 setup_requires=["pytest-runner"],
84 tests_require=["pytest", "mock"],
Erwin Jansen95559242018-11-08 15:38:18 -080085 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 Jansendcf99f52019-03-29 14:14:27 -070095 "acloud.public.acloud_kernel", "acloud.public.actions", "acloud.reconnect",
96 "acloud.list",
Erwin Jansen95559242018-11-08 15:38:18 -080097 ],
98 package_dir={
99 "acloud": ".",
Erwin Jansen95559242018-11-08 15:38:18 -0800100 },
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 ])