blob: 48c71bbafa9e1d5acd29dbbcd5a1b450552fb740 [file] [log] [blame]
tturney1bdf77d2015-12-28 17:46:13 -08001#!/usr/bin/env python3.4
Ang Lieb5e5052016-06-24 18:07:11 -07002#
Daniel Barrosfefd8c32017-08-04 15:36:40 -07003# Copyright 2017 - The Android Open Source Project
Ang Lieb5e5052016-06-24 18:07:11 -07004#
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',
Daniel Barrosfefd8c32017-08-04 15:36:40 -070035 'roman',
36 'scapy-python3',
Alexander Dorokhine5eb366e2016-03-14 12:04:40 -070037]
Ang Lieb5e5052016-06-24 18:07:11 -070038
39if sys.version_info < (3, ):
Alexander Dorokhine5eb366e2016-03-14 12:04:40 -070040 install_requires.append('enum34')
Etan Cohen10200962016-10-06 10:56:52 -070041 install_requires.append('statistics')
Ang Lia7a30692016-09-21 13:25:53 -070042 # "futures" is needed for py2 compatibility and it only works in 2.7
43 install_requires.append('futures')
Benny Peakea5deae42016-10-07 19:40:12 -070044 install_requires.append('py2-ipaddress')
Christopher Wileyfe382762016-11-07 09:58:32 -080045 install_requires.append('subprocess32')
Ang Li73697b32015-12-03 00:41:53 +000046
Ang Lieb5e5052016-06-24 18:07:11 -070047
Benny Peake914ce732016-09-26 12:53:03 -070048class PyTest(test.test):
Ang Lieb5e5052016-06-24 18:07:11 -070049 """Class used to execute unit tests using PyTest. This allows us to execute
50 unit tests without having to install the package.
51 """
Benny Peake914ce732016-09-26 12:53:03 -070052
Ang Lieb5e5052016-06-24 18:07:11 -070053 def finalize_options(self):
Benny Peake914ce732016-09-26 12:53:03 -070054 test.test.finalize_options(self)
Ang Lieb5e5052016-06-24 18:07:11 -070055 self.test_args = ['-x', "tests"]
56 self.test_suite = True
57
58 def run_tests(self):
59 import pytest
60 errno = pytest.main(self.test_args)
61 sys.exit(errno)
62
63
Benny Peakee7fd9292016-09-28 14:26:36 -070064class ActsInstallDependencies(cmd.Command):
65 """Installs only required packages
66
67 Installs all required packages for acts to work. Rather than using the
68 normal install system which creates links with the python egg, pip is
69 used to install the packages.
70 """
71
72 description = 'Install dependencies needed for acts to run on this machine.'
73 user_options = []
74
75 def initialize_options(self):
76 pass
77
78 def finalize_options(self):
79 pass
80
81 def run(self):
Kris Rambish4bc048b2017-05-31 14:14:24 -070082 import pip
83 pip.main(['install', '--upgrade', 'pip'])
Benny Peakee7fd9292016-09-28 14:26:36 -070084 required_packages = self.distribution.install_requires
85
86 for package in required_packages:
87 self.announce('Installing %s...' % package, log.INFO)
88 pip.main(['install', package])
89
90 self.announce('Dependencies installed.')
91
92
Benny Peake914ce732016-09-26 12:53:03 -070093class ActsUninstall(cmd.Command):
94 """Acts uninstaller.
95
96 Uninstalls acts from the current version of python. This will attempt to
97 import acts from any of the python egg locations. If it finds an import
98 it will use the modules file location to delete it. This is repeated until
99 acts can no longer be imported and thus is uninstalled.
100 """
101
102 description = 'Uninstall acts from the local machine.'
103 user_options = []
104
105 def initialize_options(self):
106 pass
107
108 def finalize_options(self):
109 pass
110
111 def uninstall_acts_module(self, acts_module):
112 """Uninstalls acts from a module.
113
114 Args:
115 acts_module: The acts module to uninstall.
116 """
Benny Peakec973e292016-11-09 13:43:39 -0800117 for acts_install_dir in acts_module.__path__:
Jack Hee4787832017-01-24 22:31:18 -0800118 self.announce('Deleting acts from: %s' % acts_install_dir,
119 log.INFO)
Benny Peakec973e292016-11-09 13:43:39 -0800120 shutil.rmtree(acts_install_dir)
Benny Peake914ce732016-09-26 12:53:03 -0700121
122 def run(self):
123 """Entry point for the uninstaller."""
124 # Remove the working directory from the python path. This ensures that
125 # Source code is not accidently tarageted.
Benny Peakefe6113c2016-10-13 19:47:16 -0700126 our_dir = os.path.abspath(os.path.dirname(__file__))
127 if our_dir in sys.path:
128 sys.path.remove(our_dir)
129
Benny Peake914ce732016-09-26 12:53:03 -0700130 if os.getcwd() in sys.path:
131 sys.path.remove(os.getcwd())
132
133 try:
134 import acts as acts_module
135 except ImportError:
Jack Hee4787832017-01-24 22:31:18 -0800136 self.announce(
137 'Acts is not installed, nothing to uninstall.',
138 level=log.ERROR)
Benny Peake914ce732016-09-26 12:53:03 -0700139 return
140
141 while acts_module:
142 self.uninstall_acts_module(acts_module)
143 try:
144 del sys.modules['acts']
145 import acts as acts_module
146 except ImportError:
147 acts_module = None
148
149 self.announce('Finished uninstalling acts.')
150
151
Benny Peakee7fd9292016-09-28 14:26:36 -0700152def main():
Jack Hee4787832017-01-24 22:31:18 -0800153 setuptools.setup(
154 name='acts',
155 version='0.9',
156 description='Android Comms Test Suite',
157 license='Apache2.0',
158 packages=setuptools.find_packages(),
159 include_package_data=False,
160 tests_require=['pytest'],
161 install_requires=install_requires,
162 scripts=['acts/bin/act.py', 'acts/bin/monsoon.py'],
163 cmdclass={
164 'test': PyTest,
165 'install_deps': ActsInstallDependencies,
166 'uninstall': ActsUninstall
167 },
168 url="http://www.android.com/")
Benny Peakee7fd9292016-09-28 14:26:36 -0700169
170
171if __name__ == '__main__':
172 main()