blob: 131f5de36f349ac8d9dc7f2bf314ff672dd18e15 [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 = [
markdr81044bc2017-04-26 12:12:39 -070027 # Future needs to have a newer version that contains urllib.
28 'future>=0.16.0',
Alexander Dorokhine5eb366e2016-03-14 12:04:40 -070029 # mock-1.0.1 is the last version compatible with setuptools <17.1,
30 # which is what comes with Ubuntu 14.04 LTS.
31 'mock<=1.0.1',
32 'pyserial',
Christopher Wileyfe382762016-11-07 09:58:32 -080033 'shellescape',
Jack Hee4787832017-01-24 22:31:18 -080034 'protobuf',
Alexander Dorokhine5eb366e2016-03-14 12:04:40 -070035]
Ang Lieb5e5052016-06-24 18:07:11 -070036
37if sys.version_info < (3, ):
Alexander Dorokhine5eb366e2016-03-14 12:04:40 -070038 install_requires.append('enum34')
Etan Cohen10200962016-10-06 10:56:52 -070039 install_requires.append('statistics')
Ang Lia7a30692016-09-21 13:25:53 -070040 # "futures" is needed for py2 compatibility and it only works in 2.7
41 install_requires.append('futures')
Benny Peakea5deae42016-10-07 19:40:12 -070042 install_requires.append('py2-ipaddress')
Christopher Wileyfe382762016-11-07 09:58:32 -080043 install_requires.append('subprocess32')
Ang Li73697b32015-12-03 00:41:53 +000044
Ang Lieb5e5052016-06-24 18:07:11 -070045
Benny Peake914ce732016-09-26 12:53:03 -070046class PyTest(test.test):
Ang Lieb5e5052016-06-24 18:07:11 -070047 """Class used to execute unit tests using PyTest. This allows us to execute
48 unit tests without having to install the package.
49 """
Benny Peake914ce732016-09-26 12:53:03 -070050
Ang Lieb5e5052016-06-24 18:07:11 -070051 def finalize_options(self):
Benny Peake914ce732016-09-26 12:53:03 -070052 test.test.finalize_options(self)
Ang Lieb5e5052016-06-24 18:07:11 -070053 self.test_args = ['-x', "tests"]
54 self.test_suite = True
55
56 def run_tests(self):
57 import pytest
58 errno = pytest.main(self.test_args)
59 sys.exit(errno)
60
61
Benny Peakee7fd9292016-09-28 14:26:36 -070062class ActsInstallDependencies(cmd.Command):
63 """Installs only required packages
64
65 Installs all required packages for acts to work. Rather than using the
66 normal install system which creates links with the python egg, pip is
67 used to install the packages.
68 """
69
70 description = 'Install dependencies needed for acts to run on this machine.'
71 user_options = []
72
73 def initialize_options(self):
74 pass
75
76 def finalize_options(self):
77 pass
78
79 def run(self):
Kris Rambish4bc048b2017-05-31 14:14:24 -070080 import pip
81 pip.main(['install', '--upgrade', 'pip'])
Benny Peakee7fd9292016-09-28 14:26:36 -070082 required_packages = self.distribution.install_requires
83
84 for package in required_packages:
85 self.announce('Installing %s...' % package, log.INFO)
86 pip.main(['install', package])
87
88 self.announce('Dependencies installed.')
89
90
Benny Peake914ce732016-09-26 12:53:03 -070091class ActsUninstall(cmd.Command):
92 """Acts uninstaller.
93
94 Uninstalls acts from the current version of python. This will attempt to
95 import acts from any of the python egg locations. If it finds an import
96 it will use the modules file location to delete it. This is repeated until
97 acts can no longer be imported and thus is uninstalled.
98 """
99
100 description = 'Uninstall acts from the local machine.'
101 user_options = []
102
103 def initialize_options(self):
104 pass
105
106 def finalize_options(self):
107 pass
108
109 def uninstall_acts_module(self, acts_module):
110 """Uninstalls acts from a module.
111
112 Args:
113 acts_module: The acts module to uninstall.
114 """
Benny Peakec973e292016-11-09 13:43:39 -0800115 for acts_install_dir in acts_module.__path__:
Jack Hee4787832017-01-24 22:31:18 -0800116 self.announce('Deleting acts from: %s' % acts_install_dir,
117 log.INFO)
Benny Peakec973e292016-11-09 13:43:39 -0800118 shutil.rmtree(acts_install_dir)
Benny Peake914ce732016-09-26 12:53:03 -0700119
120 def run(self):
121 """Entry point for the uninstaller."""
122 # Remove the working directory from the python path. This ensures that
123 # Source code is not accidently tarageted.
Benny Peakefe6113c2016-10-13 19:47:16 -0700124 our_dir = os.path.abspath(os.path.dirname(__file__))
125 if our_dir in sys.path:
126 sys.path.remove(our_dir)
127
Benny Peake914ce732016-09-26 12:53:03 -0700128 if os.getcwd() in sys.path:
129 sys.path.remove(os.getcwd())
130
131 try:
132 import acts as acts_module
133 except ImportError:
Jack Hee4787832017-01-24 22:31:18 -0800134 self.announce(
135 'Acts is not installed, nothing to uninstall.',
136 level=log.ERROR)
Benny Peake914ce732016-09-26 12:53:03 -0700137 return
138
139 while acts_module:
140 self.uninstall_acts_module(acts_module)
141 try:
142 del sys.modules['acts']
143 import acts as acts_module
144 except ImportError:
145 acts_module = None
146
147 self.announce('Finished uninstalling acts.')
148
149
Benny Peakee7fd9292016-09-28 14:26:36 -0700150def main():
Jack Hee4787832017-01-24 22:31:18 -0800151 setuptools.setup(
152 name='acts',
153 version='0.9',
154 description='Android Comms Test Suite',
155 license='Apache2.0',
156 packages=setuptools.find_packages(),
157 include_package_data=False,
158 tests_require=['pytest'],
159 install_requires=install_requires,
160 scripts=['acts/bin/act.py', 'acts/bin/monsoon.py'],
161 cmdclass={
162 'test': PyTest,
163 'install_deps': ActsInstallDependencies,
164 'uninstall': ActsUninstall
165 },
166 url="http://www.android.com/")
Benny Peakee7fd9292016-09-28 14:26:36 -0700167
168
169if __name__ == '__main__':
170 main()