blob: f1435475c1099c5ac61f36566fe8d9bb1cf8c499 [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
Benny Peakee7fd9292016-09-28 14:26:36 -070020import pip
Benny Peake914ce732016-09-26 12:53:03 -070021import shutil
22import setuptools
23from setuptools.command import test
Alexander Dorokhine5eb366e2016-03-14 12:04:40 -070024import sys
25
Alexander Dorokhine5eb366e2016-03-14 12:04:40 -070026install_requires = [
Alexander Dorokhine5eb366e2016-03-14 12:04:40 -070027 'future',
28 # 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',
32]
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')
Ang Li73697b32015-12-03 00:41:53 +000039
Ang Lieb5e5052016-06-24 18:07:11 -070040
Benny Peake914ce732016-09-26 12:53:03 -070041class PyTest(test.test):
Ang Lieb5e5052016-06-24 18:07:11 -070042 """Class used to execute unit tests using PyTest. This allows us to execute
43 unit tests without having to install the package.
44 """
Benny Peake914ce732016-09-26 12:53:03 -070045
Ang Lieb5e5052016-06-24 18:07:11 -070046 def finalize_options(self):
Benny Peake914ce732016-09-26 12:53:03 -070047 test.test.finalize_options(self)
Ang Lieb5e5052016-06-24 18:07:11 -070048 self.test_args = ['-x', "tests"]
49 self.test_suite = True
50
51 def run_tests(self):
52 import pytest
53 errno = pytest.main(self.test_args)
54 sys.exit(errno)
55
56
Benny Peakee7fd9292016-09-28 14:26:36 -070057class ActsInstallDependencies(cmd.Command):
58 """Installs only required packages
59
60 Installs all required packages for acts to work. Rather than using the
61 normal install system which creates links with the python egg, pip is
62 used to install the packages.
63 """
64
65 description = 'Install dependencies needed for acts to run on this machine.'
66 user_options = []
67
68 def initialize_options(self):
69 pass
70
71 def finalize_options(self):
72 pass
73
74 def run(self):
75 required_packages = self.distribution.install_requires
76
77 for package in required_packages:
78 self.announce('Installing %s...' % package, log.INFO)
79 pip.main(['install', package])
80
81 self.announce('Dependencies installed.')
82
83
Benny Peake914ce732016-09-26 12:53:03 -070084class ActsUninstall(cmd.Command):
85 """Acts uninstaller.
86
87 Uninstalls acts from the current version of python. This will attempt to
88 import acts from any of the python egg locations. If it finds an import
89 it will use the modules file location to delete it. This is repeated until
90 acts can no longer be imported and thus is uninstalled.
91 """
92
93 description = 'Uninstall acts from the local machine.'
94 user_options = []
95
96 def initialize_options(self):
97 pass
98
99 def finalize_options(self):
100 pass
101
102 def uninstall_acts_module(self, acts_module):
103 """Uninstalls acts from a module.
104
105 Args:
106 acts_module: The acts module to uninstall.
107 """
108 acts_install_dir = os.path.dirname(acts_module.__file__)
109
110 self.announce('Deleting acts from: %s' % acts_install_dir, log.INFO)
111 shutil.rmtree(acts_install_dir)
112
113 def run(self):
114 """Entry point for the uninstaller."""
115 # Remove the working directory from the python path. This ensures that
116 # Source code is not accidently tarageted.
117 if os.getcwd() in sys.path:
118 sys.path.remove(os.getcwd())
119
120 try:
121 import acts as acts_module
122 except ImportError:
123 self.announce('Acts is not installed, nothing to uninstall.',
124 level=log.ERROR)
125 return
126
127 while acts_module:
128 self.uninstall_acts_module(acts_module)
129 try:
130 del sys.modules['acts']
131 import acts as acts_module
132 except ImportError:
133 acts_module = None
134
135 self.announce('Finished uninstalling acts.')
136
137
Benny Peakee7fd9292016-09-28 14:26:36 -0700138def main():
139 setuptools.setup(name='acts',
140 version='0.9',
141 description='Android Comms Test Suite',
142 license='Apache2.0',
143 packages=setuptools.find_packages(),
144 include_package_data=False,
145 tests_require=['pytest'],
146 install_requires=install_requires,
147 scripts=['acts/bin/act.py', 'acts/bin/monsoon.py'],
148 cmdclass={'test': PyTest,
149 'install_deps': ActsInstallDependencies,
150 'uninstall': ActsUninstall},
151 url="http://www.android.com/")
152
153
154if __name__ == '__main__':
155 main()