blob: 8ef9c55ee767203414023d8932ad64a6f6c5789a [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.
16
17from distutils.spawn import find_executable
18import os
19import subprocess
20import sys
21
22import setuptools
23
24ACLOUD_DIR = os.path.realpath(os.path.dirname(__file__))
25
26try:
27 with open("README.md", "r") as fh:
28 LONG_DESCRIPTION = fh.read()
29except IOError:
30 LONG_DESCRIPTION = ""
31
32# Find the Protocol Compiler. (Taken from protobuf/python/setup.py)
33if "PROTOC" in os.environ and os.path.exists(os.environ["PROTOC"]):
34 PROTOC = os.environ["PROTOC"]
35else:
36 PROTOC = find_executable("protoc")
37
38
39def 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.
72generate_proto(os.path.join(ACLOUD_DIR, "internal/proto/user_config.proto"))
73generate_proto(os.path.join(ACLOUD_DIR, "internal/proto/internal_config.proto"))
74open(os.path.join(ACLOUD_DIR, "internal/proto/__init__.py"), "a").close()
75
76setuptools.setup(
77 python_requires=">=2",
78 name="acloud",
79 version="1.0",
Erwin Jansenf39798d2019-05-14 21:06:44 -070080 setup_requires=["pytest-runner"],
81 tests_require=["pytest", "mock"],
Erwin Jansen95559242018-11-08 15:38:18 -080082 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 Jansendcf99f52019-03-29 14:14:27 -070092 "acloud.public.acloud_kernel", "acloud.public.actions", "acloud.reconnect",
93 "acloud.list",
Erwin Jansen95559242018-11-08 15:38:18 -080094 ],
95 package_dir={
96 "acloud": ".",
Erwin Jansen95559242018-11-08 15:38:18 -080097 },
98 package_data={"acloud.public.data": ["default.config"]},
99 include_package_data=True,
100 platforms="POSIX",
101 entry_points={
102 "console_scripts": ["acloud=acloud.public.acloud_main:main"],
103 },
104 install_requires=[
105 "google-api-python-client", "oauth2client==3.0.0", "protobuf",
106 "python-dateutil"
107 ],
108 license="Apache License, Version 2.0",
109 classifiers=[
110 "Programming Language :: Python :: 2",
111 "Programming Language :: Python :: 3",
112 "License :: OSI Approved :: Apache Software License",
113 "Natural Language :: English",
114 "Environment :: Console",
115 "Intended Audience :: Developers",
116 "Topic :: Utilities",
117 ])