blob: 3ec3d9b7f28e87436c01f2a0328205546185dbd3 [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 """
Benny Peakec973e292016-11-09 13:43:39 -0800112 for acts_install_dir in acts_module.__path__:
113 self.announce('Deleting acts from: %s' % acts_install_dir, log.INFO)
114 shutil.rmtree(acts_install_dir)
Benny Peake914ce732016-09-26 12:53:03 -0700115
116 def run(self):
117 """Entry point for the uninstaller."""
118 # Remove the working directory from the python path. This ensures that
119 # Source code is not accidently tarageted.
Benny Peakeb4cd8952016-10-13 19:47:16 -0700120 our_dir = os.path.abspath(os.path.dirname(__file__))
121 if our_dir in sys.path:
122 sys.path.remove(our_dir)
123
Benny Peake914ce732016-09-26 12:53:03 -0700124 if os.getcwd() in sys.path:
125 sys.path.remove(os.getcwd())
126
127 try:
128 import acts as acts_module
129 except ImportError:
130 self.announce('Acts is not installed, nothing to uninstall.',
131 level=log.ERROR)
132 return
133
134 while acts_module:
135 self.uninstall_acts_module(acts_module)
136 try:
137 del sys.modules['acts']
138 import acts as acts_module
139 except ImportError:
140 acts_module = None
141
142 self.announce('Finished uninstalling acts.')
143
144
Benny Peakee7fd9292016-09-28 14:26:36 -0700145def main():
146 setuptools.setup(name='acts',
147 version='0.9',
148 description='Android Comms Test Suite',
149 license='Apache2.0',
150 packages=setuptools.find_packages(),
151 include_package_data=False,
152 tests_require=['pytest'],
153 install_requires=install_requires,
154 scripts=['acts/bin/act.py', 'acts/bin/monsoon.py'],
155 cmdclass={'test': PyTest,
156 'install_deps': ActsInstallDependencies,
157 'uninstall': ActsUninstall},
158 url="http://www.android.com/")
159
160
161if __name__ == '__main__':
162 main()