tturney | 1bdf77d | 2015-12-28 17:46:13 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python3.4 |
Ang Li | eb5e505 | 2016-06-24 18:07:11 -0700 | [diff] [blame] | 2 | # |
Daniel Barros | 1cefafd | 2017-08-04 15:36:40 -0700 | [diff] [blame] | 3 | # Copyright 2017 - The Android Open Source Project |
Ang Li | eb5e505 | 2016-06-24 18:07:11 -0700 | [diff] [blame] | 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 Peake | 914ce73 | 2016-09-26 12:53:03 -0700 | [diff] [blame] | 17 | from distutils import cmd |
| 18 | from distutils import log |
| 19 | import os |
| 20 | import shutil |
| 21 | import setuptools |
| 22 | from setuptools.command import test |
Alexander Dorokhine | 5eb366e | 2016-03-14 12:04:40 -0700 | [diff] [blame] | 23 | import sys |
| 24 | |
Alexander Dorokhine | 5eb366e | 2016-03-14 12:04:40 -0700 | [diff] [blame] | 25 | install_requires = [ |
markdr | 81044bc | 2017-04-26 12:12:39 -0700 | [diff] [blame] | 26 | # Future needs to have a newer version that contains urllib. |
| 27 | 'future>=0.16.0', |
Alexander Dorokhine | 5eb366e | 2016-03-14 12:04:40 -0700 | [diff] [blame] | 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', |
tturney | 91191de | 2017-11-16 15:07:17 -0800 | [diff] [blame] | 31 | 'numpy', |
Alexander Dorokhine | 5eb366e | 2016-03-14 12:04:40 -0700 | [diff] [blame] | 32 | 'pyserial', |
Christopher Wiley | fe38276 | 2016-11-07 09:58:32 -0800 | [diff] [blame] | 33 | 'shellescape', |
Jack He | e478783 | 2017-01-24 22:31:18 -0800 | [diff] [blame] | 34 | 'protobuf', |
markdr | 78faf62 | 2017-09-12 11:37:16 -0700 | [diff] [blame] | 35 | 'roman', |
Daniel Barros | 1cefafd | 2017-08-04 15:36:40 -0700 | [diff] [blame] | 36 | 'scapy-python3', |
globaledge | e770675 | 2018-01-22 17:07:22 +0530 | [diff] [blame^] | 37 | 'pylibftdi', |
Alexander Dorokhine | 5eb366e | 2016-03-14 12:04:40 -0700 | [diff] [blame] | 38 | ] |
Ang Li | eb5e505 | 2016-06-24 18:07:11 -0700 | [diff] [blame] | 39 | |
| 40 | if sys.version_info < (3, ): |
Alexander Dorokhine | 5eb366e | 2016-03-14 12:04:40 -0700 | [diff] [blame] | 41 | install_requires.append('enum34') |
Etan Cohen | 1020096 | 2016-10-06 10:56:52 -0700 | [diff] [blame] | 42 | install_requires.append('statistics') |
Ang Li | a7a3069 | 2016-09-21 13:25:53 -0700 | [diff] [blame] | 43 | # "futures" is needed for py2 compatibility and it only works in 2.7 |
| 44 | install_requires.append('futures') |
Benny Peake | a5deae4 | 2016-10-07 19:40:12 -0700 | [diff] [blame] | 45 | install_requires.append('py2-ipaddress') |
Christopher Wiley | fe38276 | 2016-11-07 09:58:32 -0800 | [diff] [blame] | 46 | install_requires.append('subprocess32') |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 47 | |
Ang Li | eb5e505 | 2016-06-24 18:07:11 -0700 | [diff] [blame] | 48 | |
Benny Peake | 914ce73 | 2016-09-26 12:53:03 -0700 | [diff] [blame] | 49 | class PyTest(test.test): |
Ang Li | eb5e505 | 2016-06-24 18:07:11 -0700 | [diff] [blame] | 50 | """Class used to execute unit tests using PyTest. This allows us to execute |
| 51 | unit tests without having to install the package. |
| 52 | """ |
Benny Peake | 914ce73 | 2016-09-26 12:53:03 -0700 | [diff] [blame] | 53 | |
Ang Li | eb5e505 | 2016-06-24 18:07:11 -0700 | [diff] [blame] | 54 | def finalize_options(self): |
Benny Peake | 914ce73 | 2016-09-26 12:53:03 -0700 | [diff] [blame] | 55 | test.test.finalize_options(self) |
Ang Li | eb5e505 | 2016-06-24 18:07:11 -0700 | [diff] [blame] | 56 | self.test_args = ['-x', "tests"] |
| 57 | self.test_suite = True |
| 58 | |
| 59 | def run_tests(self): |
| 60 | import pytest |
| 61 | errno = pytest.main(self.test_args) |
| 62 | sys.exit(errno) |
| 63 | |
| 64 | |
Benny Peake | e7fd929 | 2016-09-28 14:26:36 -0700 | [diff] [blame] | 65 | class ActsInstallDependencies(cmd.Command): |
| 66 | """Installs only required packages |
| 67 | |
| 68 | Installs all required packages for acts to work. Rather than using the |
| 69 | normal install system which creates links with the python egg, pip is |
| 70 | used to install the packages. |
| 71 | """ |
| 72 | |
| 73 | description = 'Install dependencies needed for acts to run on this machine.' |
| 74 | user_options = [] |
| 75 | |
| 76 | def initialize_options(self): |
| 77 | pass |
| 78 | |
| 79 | def finalize_options(self): |
| 80 | pass |
| 81 | |
| 82 | def run(self): |
Kris Rambish | 4bc048b | 2017-05-31 14:14:24 -0700 | [diff] [blame] | 83 | import pip |
| 84 | pip.main(['install', '--upgrade', 'pip']) |
Benny Peake | e7fd929 | 2016-09-28 14:26:36 -0700 | [diff] [blame] | 85 | required_packages = self.distribution.install_requires |
| 86 | |
| 87 | for package in required_packages: |
| 88 | self.announce('Installing %s...' % package, log.INFO) |
| 89 | pip.main(['install', package]) |
| 90 | |
| 91 | self.announce('Dependencies installed.') |
| 92 | |
| 93 | |
Benny Peake | 914ce73 | 2016-09-26 12:53:03 -0700 | [diff] [blame] | 94 | class ActsUninstall(cmd.Command): |
| 95 | """Acts uninstaller. |
| 96 | |
| 97 | Uninstalls acts from the current version of python. This will attempt to |
| 98 | import acts from any of the python egg locations. If it finds an import |
| 99 | it will use the modules file location to delete it. This is repeated until |
| 100 | acts can no longer be imported and thus is uninstalled. |
| 101 | """ |
| 102 | |
| 103 | description = 'Uninstall acts from the local machine.' |
| 104 | user_options = [] |
| 105 | |
| 106 | def initialize_options(self): |
| 107 | pass |
| 108 | |
| 109 | def finalize_options(self): |
| 110 | pass |
| 111 | |
| 112 | def uninstall_acts_module(self, acts_module): |
| 113 | """Uninstalls acts from a module. |
| 114 | |
| 115 | Args: |
| 116 | acts_module: The acts module to uninstall. |
| 117 | """ |
Benny Peake | c973e29 | 2016-11-09 13:43:39 -0800 | [diff] [blame] | 118 | for acts_install_dir in acts_module.__path__: |
Jack He | e478783 | 2017-01-24 22:31:18 -0800 | [diff] [blame] | 119 | self.announce('Deleting acts from: %s' % acts_install_dir, |
| 120 | log.INFO) |
Benny Peake | c973e29 | 2016-11-09 13:43:39 -0800 | [diff] [blame] | 121 | shutil.rmtree(acts_install_dir) |
Benny Peake | 914ce73 | 2016-09-26 12:53:03 -0700 | [diff] [blame] | 122 | |
| 123 | def run(self): |
| 124 | """Entry point for the uninstaller.""" |
| 125 | # Remove the working directory from the python path. This ensures that |
markdr | b2e826a | 2017-08-04 21:42:08 -0700 | [diff] [blame] | 126 | # Source code is not accidentally targeted. |
Benny Peake | fe6113c | 2016-10-13 19:47:16 -0700 | [diff] [blame] | 127 | our_dir = os.path.abspath(os.path.dirname(__file__)) |
| 128 | if our_dir in sys.path: |
| 129 | sys.path.remove(our_dir) |
| 130 | |
Benny Peake | 914ce73 | 2016-09-26 12:53:03 -0700 | [diff] [blame] | 131 | if os.getcwd() in sys.path: |
| 132 | sys.path.remove(os.getcwd()) |
| 133 | |
| 134 | try: |
| 135 | import acts as acts_module |
| 136 | except ImportError: |
Jack He | e478783 | 2017-01-24 22:31:18 -0800 | [diff] [blame] | 137 | self.announce( |
| 138 | 'Acts is not installed, nothing to uninstall.', |
| 139 | level=log.ERROR) |
Benny Peake | 914ce73 | 2016-09-26 12:53:03 -0700 | [diff] [blame] | 140 | return |
| 141 | |
| 142 | while acts_module: |
| 143 | self.uninstall_acts_module(acts_module) |
| 144 | try: |
| 145 | del sys.modules['acts'] |
| 146 | import acts as acts_module |
| 147 | except ImportError: |
| 148 | acts_module = None |
| 149 | |
| 150 | self.announce('Finished uninstalling acts.') |
| 151 | |
| 152 | |
Benny Peake | e7fd929 | 2016-09-28 14:26:36 -0700 | [diff] [blame] | 153 | def main(): |
Jack He | e478783 | 2017-01-24 22:31:18 -0800 | [diff] [blame] | 154 | setuptools.setup( |
| 155 | name='acts', |
| 156 | version='0.9', |
| 157 | description='Android Comms Test Suite', |
| 158 | license='Apache2.0', |
| 159 | packages=setuptools.find_packages(), |
| 160 | include_package_data=False, |
| 161 | tests_require=['pytest'], |
| 162 | install_requires=install_requires, |
| 163 | scripts=['acts/bin/act.py', 'acts/bin/monsoon.py'], |
| 164 | cmdclass={ |
| 165 | 'test': PyTest, |
| 166 | 'install_deps': ActsInstallDependencies, |
| 167 | 'uninstall': ActsUninstall |
| 168 | }, |
| 169 | url="http://www.android.com/") |
Benny Peake | e7fd929 | 2016-09-28 14:26:36 -0700 | [diff] [blame] | 170 | |
markdr | 98ec2c6 | 2017-10-03 12:40:47 -0700 | [diff] [blame] | 171 | if {'-u', '--uninstall', 'uninstall'}.intersection(sys.argv): |
| 172 | act_path = '/usr/local/bin/act.py' |
| 173 | if os.path.islink(act_path): |
| 174 | os.unlink(act_path) |
| 175 | elif os.path.exists(act_path): |
| 176 | os.remove(act_path) |
| 177 | |
Benny Peake | e7fd929 | 2016-09-28 14:26:36 -0700 | [diff] [blame] | 178 | |
| 179 | if __name__ == '__main__': |
| 180 | main() |