blob: 0a8eba6e1f097033ab51895693f40e39a969b84b [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
chojoyce6e30cc52019-11-04 16:18:09 +080020try:
21 from distutils.spawn import find_executable
22except ImportError:
23 from shutil import which as find_executable
Erwin Jansen95559242018-11-08 15:38:18 -080024import 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
herbertxuea369fc52019-11-07 20:28:33 +080045def GenerateProto(source):
Erwin Jansen95559242018-11-08 15:38:18 -080046 """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
Erwin Jansen28f51632019-11-25 10:18:51 -080058 if not os.path.exists(output) or (
chojoyce6e30cc52019-11-04 16:18:09 +080059 os.path.exists(source) and
60 os.path.getmtime(source) > os.path.getmtime(output)):
herbertxuea369fc52019-11-07 20:28:33 +080061 print("Generating %s..." % output)
Erwin Jansen95559242018-11-08 15:38:18 -080062
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 "
Erwin Jansen28f51632019-11-25 10:18:51 -080070 "or install the binary package.\n"
71 )
Erwin Jansen95559242018-11-08 15:38:18 -080072 sys.exit(-1)
73
herbertxuea369fc52019-11-07 20:28:33 +080074 protoc_command = [PROTOC, "-I%s" % ACLOUD_DIR, "--python_out=.", source]
Erwin Jansen95559242018-11-08 15:38:18 -080075 if subprocess.call(protoc_command) != 0:
76 sys.exit(-1)
77
78
79# Generate the protobuf files that we depend on.
herbertxuea369fc52019-11-07 20:28:33 +080080GenerateProto(os.path.join(ACLOUD_DIR, "internal/proto/user_config.proto"))
81GenerateProto(os.path.join(ACLOUD_DIR, "internal/proto/internal_config.proto"))
Erwin Jansen95559242018-11-08 15:38:18 -080082open(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",
Erwin Jansenf39798d2019-05-14 21:06:44 -070088 setup_requires=["pytest-runner"],
89 tests_require=["pytest", "mock"],
Erwin Jansen95559242018-11-08 15:38:18 -080090 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 "
Erwin Jansen28f51632019-11-25 10:18:51 -080093 "create an Android Virtual Device (AVD).",
Erwin Jansen95559242018-11-08 15:38:18 -080094 long_description=LONG_DESCRIPTION,
95 long_description_content_type="text/markdown",
96 packages=[
Erwin Jansen28f51632019-11-25 10:18:51 -080097 "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",
Erwin Jansendcf99f52019-03-29 14:14:27 -0700111 "acloud.list",
Erwin Jansen95559242018-11-08 15:38:18 -0800112 ],
Erwin Jansen28f51632019-11-25 10:18:51 -0800113 package_dir={"acloud": ".",},
Erwin Jansen95559242018-11-08 15:38:18 -0800114 package_data={"acloud.public.data": ["default.config"]},
115 include_package_data=True,
116 platforms="POSIX",
Erwin Jansen28f51632019-11-25 10:18:51 -0800117 entry_points={"console_scripts": ["acloud=acloud.public.acloud_main:main"],},
Erwin Jansen95559242018-11-08 15:38:18 -0800118 install_requires=[
Erwin Jansen28f51632019-11-25 10:18:51 -0800119 "google-api-python-client",
120 "oauth2client==3.0.0",
121 "protobuf",
122 "python-dateutil",
Erwin Jansen95559242018-11-08 15:38:18 -0800123 ],
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",
Erwin Jansen28f51632019-11-25 10:18:51 -0800133 ],
134)