blob: 4996ad435c4c1096fa7f36acc1f69e184ec0f3a5 [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',
markdr78faf622017-09-12 11:37:16 -070035 'roman',
Alexander Dorokhine5eb366e2016-03-14 12:04:40 -070036]
Ang Lieb5e5052016-06-24 18:07:11 -070037
38if sys.version_info < (3, ):
Alexander Dorokhine5eb366e2016-03-14 12:04:40 -070039 install_requires.append('enum34')
Etan Cohen10200962016-10-06 10:56:52 -070040 install_requires.append('statistics')
Ang Lia7a30692016-09-21 13:25:53 -070041 # "futures" is needed for py2 compatibility and it only works in 2.7
42 install_requires.append('futures')
Benny Peakea5deae42016-10-07 19:40:12 -070043 install_requires.append('py2-ipaddress')
Christopher Wileyfe382762016-11-07 09:58:32 -080044 install_requires.append('subprocess32')
Ang Li73697b32015-12-03 00:41:53 +000045
Ang Lieb5e5052016-06-24 18:07:11 -070046
Benny Peake914ce732016-09-26 12:53:03 -070047class PyTest(test.test):
Ang Lieb5e5052016-06-24 18:07:11 -070048 """Class used to execute unit tests using PyTest. This allows us to execute
49 unit tests without having to install the package.
50 """
Benny Peake914ce732016-09-26 12:53:03 -070051
Ang Lieb5e5052016-06-24 18:07:11 -070052 def finalize_options(self):
Benny Peake914ce732016-09-26 12:53:03 -070053 test.test.finalize_options(self)
Ang Lieb5e5052016-06-24 18:07:11 -070054 self.test_args = ['-x', "tests"]
55 self.test_suite = True
56
57 def run_tests(self):
58 import pytest
59 errno = pytest.main(self.test_args)
60 sys.exit(errno)
61
62
Benny Peakee7fd9292016-09-28 14:26:36 -070063class ActsInstallDependencies(cmd.Command):
64 """Installs only required packages
65
66 Installs all required packages for acts to work. Rather than using the
67 normal install system which creates links with the python egg, pip is
68 used to install the packages.
69 """
70
71 description = 'Install dependencies needed for acts to run on this machine.'
72 user_options = []
73
74 def initialize_options(self):
75 pass
76
77 def finalize_options(self):
78 pass
79
80 def run(self):
Kris Rambish4bc048b2017-05-31 14:14:24 -070081 import pip
82 pip.main(['install', '--upgrade', 'pip'])
Benny Peakee7fd9292016-09-28 14:26:36 -070083 required_packages = self.distribution.install_requires
84
85 for package in required_packages:
86 self.announce('Installing %s...' % package, log.INFO)
87 pip.main(['install', package])
88
89 self.announce('Dependencies installed.')
90
91
Benny Peake914ce732016-09-26 12:53:03 -070092class ActsUninstall(cmd.Command):
93 """Acts uninstaller.
94
95 Uninstalls acts from the current version of python. This will attempt to
96 import acts from any of the python egg locations. If it finds an import
97 it will use the modules file location to delete it. This is repeated until
98 acts can no longer be imported and thus is uninstalled.
99 """
100
101 description = 'Uninstall acts from the local machine.'
102 user_options = []
103
104 def initialize_options(self):
105 pass
106
107 def finalize_options(self):
108 pass
109
110 def uninstall_acts_module(self, acts_module):
111 """Uninstalls acts from a module.
112
113 Args:
114 acts_module: The acts module to uninstall.
115 """
Benny Peakec973e292016-11-09 13:43:39 -0800116 for acts_install_dir in acts_module.__path__:
Jack Hee4787832017-01-24 22:31:18 -0800117 self.announce('Deleting acts from: %s' % acts_install_dir,
118 log.INFO)
Benny Peakec973e292016-11-09 13:43:39 -0800119 shutil.rmtree(acts_install_dir)
Benny Peake914ce732016-09-26 12:53:03 -0700120
121 def run(self):
122 """Entry point for the uninstaller."""
123 # Remove the working directory from the python path. This ensures that
markdrb2e826a2017-08-04 21:42:08 -0700124 # Source code is not accidentally targeted.
Benny Peakefe6113c2016-10-13 19:47:16 -0700125 our_dir = os.path.abspath(os.path.dirname(__file__))
126 if our_dir in sys.path:
127 sys.path.remove(our_dir)
128
Benny Peake914ce732016-09-26 12:53:03 -0700129 if os.getcwd() in sys.path:
130 sys.path.remove(os.getcwd())
131
132 try:
133 import acts as acts_module
134 except ImportError:
Jack Hee4787832017-01-24 22:31:18 -0800135 self.announce(
136 'Acts is not installed, nothing to uninstall.',
137 level=log.ERROR)
Benny Peake914ce732016-09-26 12:53:03 -0700138 return
139
140 while acts_module:
141 self.uninstall_acts_module(acts_module)
142 try:
143 del sys.modules['acts']
144 import acts as acts_module
145 except ImportError:
146 acts_module = None
147
148 self.announce('Finished uninstalling acts.')
149
150
Benny Peakee7fd9292016-09-28 14:26:36 -0700151def main():
Jack Hee4787832017-01-24 22:31:18 -0800152 setuptools.setup(
153 name='acts',
154 version='0.9',
155 description='Android Comms Test Suite',
156 license='Apache2.0',
157 packages=setuptools.find_packages(),
158 include_package_data=False,
159 tests_require=['pytest'],
160 install_requires=install_requires,
161 scripts=['acts/bin/act.py', 'acts/bin/monsoon.py'],
162 cmdclass={
163 'test': PyTest,
164 'install_deps': ActsInstallDependencies,
165 'uninstall': ActsUninstall
166 },
167 url="http://www.android.com/")
Benny Peakee7fd9292016-09-28 14:26:36 -0700168
169
170if __name__ == '__main__':
171 main()