blob: a7241af83ec8b9d456244a752d02d16ccb953f91 [file] [log] [blame]
tturney1bdf77d2015-12-28 17:46:13 -08001#!/usr/bin/env python3.4
Ang Lieb5e5052016-06-24 18:07:11 -07002#
3# Copyright 2016 - 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
Benny Peake914ce732016-09-26 12:53:03 -070017from distutils import cmd
18from distutils import log
19import os
20import shutil
21import setuptools
22from setuptools.command import test
Alexander Dorokhine5eb366e2016-03-14 12:04:40 -070023import sys
24
Alexander Dorokhine5eb366e2016-03-14 12:04:40 -070025install_requires = [
markdr81044bc2017-04-26 12:12:39 -070026 # Future needs to have a newer version that contains urllib.
27 'future>=0.16.0',
Alexander Dorokhine5eb366e2016-03-14 12:04:40 -070028 # mock-1.0.1 is the last version compatible with setuptools <17.1,
29 # which is what comes with Ubuntu 14.04 LTS.
30 'mock<=1.0.1',
31 'pyserial',
Christopher Wileyfe382762016-11-07 09:58:32 -080032 'shellescape',
Jack Hee4787832017-01-24 22:31:18 -080033 'protobuf',
Alexander Dorokhine5eb366e2016-03-14 12:04:40 -070034]
Ang Lieb5e5052016-06-24 18:07:11 -070035
36if sys.version_info < (3, ):
Alexander Dorokhine5eb366e2016-03-14 12:04:40 -070037 install_requires.append('enum34')
Etan Cohen10200962016-10-06 10:56:52 -070038 install_requires.append('statistics')
Ang Lia7a30692016-09-21 13:25:53 -070039 # "futures" is needed for py2 compatibility and it only works in 2.7
40 install_requires.append('futures')
Benny Peakea5deae42016-10-07 19:40:12 -070041 install_requires.append('py2-ipaddress')
Christopher Wileyfe382762016-11-07 09:58:32 -080042 install_requires.append('subprocess32')
Ang Li73697b32015-12-03 00:41:53 +000043
Ang Lieb5e5052016-06-24 18:07:11 -070044
Benny Peake914ce732016-09-26 12:53:03 -070045class PyTest(test.test):
Ang Lieb5e5052016-06-24 18:07:11 -070046 """Class used to execute unit tests using PyTest. This allows us to execute
47 unit tests without having to install the package.
48 """
Benny Peake914ce732016-09-26 12:53:03 -070049
Ang Lieb5e5052016-06-24 18:07:11 -070050 def finalize_options(self):
Benny Peake914ce732016-09-26 12:53:03 -070051 test.test.finalize_options(self)
Ang Lieb5e5052016-06-24 18:07:11 -070052 self.test_args = ['-x', "tests"]
53 self.test_suite = True
54
55 def run_tests(self):
56 import pytest
57 errno = pytest.main(self.test_args)
58 sys.exit(errno)
59
60
Benny Peakee7fd9292016-09-28 14:26:36 -070061class ActsInstallDependencies(cmd.Command):
62 """Installs only required packages
63
64 Installs all required packages for acts to work. Rather than using the
65 normal install system which creates links with the python egg, pip is
66 used to install the packages.
67 """
68
69 description = 'Install dependencies needed for acts to run on this machine.'
70 user_options = []
71
72 def initialize_options(self):
73 pass
74
75 def finalize_options(self):
76 pass
77
78 def run(self):
Benny Peakeb7fa2022016-10-13 11:24:58 -070079 import pip
80
Benny Peakee7fd9292016-09-28 14:26:36 -070081 required_packages = self.distribution.install_requires
82
83 for package in required_packages:
84 self.announce('Installing %s...' % package, log.INFO)
85 pip.main(['install', package])
86
87 self.announce('Dependencies installed.')
88
89
Benny Peake914ce732016-09-26 12:53:03 -070090class ActsUninstall(cmd.Command):
91 """Acts uninstaller.
92
93 Uninstalls acts from the current version of python. This will attempt to
94 import acts from any of the python egg locations. If it finds an import
95 it will use the modules file location to delete it. This is repeated until
96 acts can no longer be imported and thus is uninstalled.
97 """
98
99 description = 'Uninstall acts from the local machine.'
100 user_options = []
101
102 def initialize_options(self):
103 pass
104
105 def finalize_options(self):
106 pass
107
108 def uninstall_acts_module(self, acts_module):
109 """Uninstalls acts from a module.
110
111 Args:
112 acts_module: The acts module to uninstall.
113 """
Benny Peakec973e292016-11-09 13:43:39 -0800114 for acts_install_dir in acts_module.__path__:
Jack Hee4787832017-01-24 22:31:18 -0800115 self.announce('Deleting acts from: %s' % acts_install_dir,
116 log.INFO)
Benny Peakec973e292016-11-09 13:43:39 -0800117 shutil.rmtree(acts_install_dir)
Benny Peake914ce732016-09-26 12:53:03 -0700118
119 def run(self):
120 """Entry point for the uninstaller."""
121 # Remove the working directory from the python path. This ensures that
122 # Source code is not accidently tarageted.
Benny Peakeb4cd8952016-10-13 19:47:16 -0700123 our_dir = os.path.abspath(os.path.dirname(__file__))
124 if our_dir in sys.path:
125 sys.path.remove(our_dir)
126
Benny Peake914ce732016-09-26 12:53:03 -0700127 if os.getcwd() in sys.path:
128 sys.path.remove(os.getcwd())
129
130 try:
131 import acts as acts_module
132 except ImportError:
Jack Hee4787832017-01-24 22:31:18 -0800133 self.announce(
134 'Acts is not installed, nothing to uninstall.',
135 level=log.ERROR)
Benny Peake914ce732016-09-26 12:53:03 -0700136 return
137
138 while acts_module:
139 self.uninstall_acts_module(acts_module)
140 try:
141 del sys.modules['acts']
142 import acts as acts_module
143 except ImportError:
144 acts_module = None
145
146 self.announce('Finished uninstalling acts.')
147
148
Benny Peakee7fd9292016-09-28 14:26:36 -0700149def main():
Jack Hee4787832017-01-24 22:31:18 -0800150 setuptools.setup(
151 name='acts',
152 version='0.9',
153 description='Android Comms Test Suite',
154 license='Apache2.0',
155 packages=setuptools.find_packages(),
156 include_package_data=False,
157 tests_require=['pytest'],
158 install_requires=install_requires,
159 scripts=['acts/bin/act.py', 'acts/bin/monsoon.py'],
160 cmdclass={
161 'test': PyTest,
162 'install_deps': ActsInstallDependencies,
163 'uninstall': ActsUninstall
164 },
165 url="http://www.android.com/")
Benny Peakee7fd9292016-09-28 14:26:36 -0700166
167
168if __name__ == '__main__':
169 main()