blob: 51fa13d3d354ca307ede34750d27f92543bcc999 [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 = [
Alexander Dorokhine5eb366e2016-03-14 12:04:40 -070026 'future',
27 # mock-1.0.1 is the last version compatible with setuptools <17.1,
28 # which is what comes with Ubuntu 14.04 LTS.
29 'mock<=1.0.1',
30 'pyserial',
Christopher Wileyfe382762016-11-07 09:58:32 -080031 'shellescape',
Alexander Dorokhine5eb366e2016-03-14 12:04:40 -070032]
Ang Lieb5e5052016-06-24 18:07:11 -070033
34if sys.version_info < (3, ):
Alexander Dorokhine5eb366e2016-03-14 12:04:40 -070035 install_requires.append('enum34')
Etan Cohen10200962016-10-06 10:56:52 -070036 install_requires.append('statistics')
Ang Lia7a30692016-09-21 13:25:53 -070037 # "futures" is needed for py2 compatibility and it only works in 2.7
38 install_requires.append('futures')
Benny Peakea5deae42016-10-07 19:40:12 -070039 install_requires.append('py2-ipaddress')
Christopher Wileyfe382762016-11-07 09:58:32 -080040 install_requires.append('subprocess32')
Ang Li73697b32015-12-03 00:41:53 +000041
Ang Lieb5e5052016-06-24 18:07:11 -070042
Benny Peake914ce732016-09-26 12:53:03 -070043class PyTest(test.test):
Ang Lieb5e5052016-06-24 18:07:11 -070044 """Class used to execute unit tests using PyTest. This allows us to execute
45 unit tests without having to install the package.
46 """
Benny Peake914ce732016-09-26 12:53:03 -070047
Ang Lieb5e5052016-06-24 18:07:11 -070048 def finalize_options(self):
Benny Peake914ce732016-09-26 12:53:03 -070049 test.test.finalize_options(self)
Ang Lieb5e5052016-06-24 18:07:11 -070050 self.test_args = ['-x', "tests"]
51 self.test_suite = True
52
53 def run_tests(self):
54 import pytest
55 errno = pytest.main(self.test_args)
56 sys.exit(errno)
57
58
Benny Peakee7fd9292016-09-28 14:26:36 -070059class ActsInstallDependencies(cmd.Command):
60 """Installs only required packages
61
62 Installs all required packages for acts to work. Rather than using the
63 normal install system which creates links with the python egg, pip is
64 used to install the packages.
65 """
66
67 description = 'Install dependencies needed for acts to run on this machine.'
68 user_options = []
69
70 def initialize_options(self):
71 pass
72
73 def finalize_options(self):
74 pass
75
76 def run(self):
Benny Peakeb7fa2022016-10-13 11:24:58 -070077 import pip
78
Benny Peakee7fd9292016-09-28 14:26:36 -070079 required_packages = self.distribution.install_requires
80
81 for package in required_packages:
82 self.announce('Installing %s...' % package, log.INFO)
83 pip.main(['install', package])
84
85 self.announce('Dependencies installed.')
86
87
Benny Peake914ce732016-09-26 12:53:03 -070088class ActsUninstall(cmd.Command):
89 """Acts uninstaller.
90
91 Uninstalls acts from the current version of python. This will attempt to
92 import acts from any of the python egg locations. If it finds an import
93 it will use the modules file location to delete it. This is repeated until
94 acts can no longer be imported and thus is uninstalled.
95 """
96
97 description = 'Uninstall acts from the local machine.'
98 user_options = []
99
100 def initialize_options(self):
101 pass
102
103 def finalize_options(self):
104 pass
105
106 def uninstall_acts_module(self, acts_module):
107 """Uninstalls acts from a module.
108
109 Args:
110 acts_module: The acts module to uninstall.
111 """
112 acts_install_dir = os.path.dirname(acts_module.__file__)
113
114 self.announce('Deleting acts from: %s' % acts_install_dir, log.INFO)
115 shutil.rmtree(acts_install_dir)
116
117 def run(self):
118 """Entry point for the uninstaller."""
119 # Remove the working directory from the python path. This ensures that
120 # Source code is not accidently tarageted.
Benny Peakeb4cd8952016-10-13 19:47:16 -0700121 our_dir = os.path.abspath(os.path.dirname(__file__))
122 if our_dir in sys.path:
123 sys.path.remove(our_dir)
124
Benny Peake914ce732016-09-26 12:53:03 -0700125 if os.getcwd() in sys.path:
126 sys.path.remove(os.getcwd())
127
128 try:
129 import acts as acts_module
130 except ImportError:
131 self.announce('Acts is not installed, nothing to uninstall.',
132 level=log.ERROR)
133 return
134
135 while acts_module:
136 self.uninstall_acts_module(acts_module)
137 try:
138 del sys.modules['acts']
139 import acts as acts_module
140 except ImportError:
141 acts_module = None
142
143 self.announce('Finished uninstalling acts.')
144
145
Benny Peakee7fd9292016-09-28 14:26:36 -0700146def main():
147 setuptools.setup(name='acts',
148 version='0.9',
149 description='Android Comms Test Suite',
150 license='Apache2.0',
151 packages=setuptools.find_packages(),
152 include_package_data=False,
153 tests_require=['pytest'],
154 install_requires=install_requires,
155 scripts=['acts/bin/act.py', 'acts/bin/monsoon.py'],
156 cmdclass={'test': PyTest,
157 'install_deps': ActsInstallDependencies,
158 'uninstall': ActsUninstall},
159 url="http://www.android.com/")
160
161
162if __name__ == '__main__':
163 main()