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 | # |
| 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 Peake | 914ce73 | 2016-09-26 12:53:03 -0700 | [diff] [blame] | 17 | from distutils import cmd |
| 18 | from distutils import log |
| 19 | import os |
Benny Peake | e7fd929 | 2016-09-28 14:26:36 -0700 | [diff] [blame] | 20 | import pip |
Benny Peake | 914ce73 | 2016-09-26 12:53:03 -0700 | [diff] [blame] | 21 | import shutil |
| 22 | import setuptools |
| 23 | from setuptools.command import test |
Alexander Dorokhine | 5eb366e | 2016-03-14 12:04:40 -0700 | [diff] [blame] | 24 | import sys |
| 25 | |
Alexander Dorokhine | 5eb366e | 2016-03-14 12:04:40 -0700 | [diff] [blame] | 26 | install_requires = [ |
markdr | 81044bc | 2017-04-26 12:12:39 -0700 | [diff] [blame] | 27 | # Future needs to have a newer version that contains urllib. |
| 28 | 'future>=0.16.0', |
Alexander Dorokhine | 5eb366e | 2016-03-14 12:04:40 -0700 | [diff] [blame] | 29 | # 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 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', |
Alexander Dorokhine | 5eb366e | 2016-03-14 12:04:40 -0700 | [diff] [blame] | 35 | ] |
Ang Li | eb5e505 | 2016-06-24 18:07:11 -0700 | [diff] [blame] | 36 | |
| 37 | if sys.version_info < (3, ): |
Alexander Dorokhine | 5eb366e | 2016-03-14 12:04:40 -0700 | [diff] [blame] | 38 | install_requires.append('enum34') |
Etan Cohen | 1020096 | 2016-10-06 10:56:52 -0700 | [diff] [blame] | 39 | install_requires.append('statistics') |
Ang Li | a7a3069 | 2016-09-21 13:25:53 -0700 | [diff] [blame] | 40 | # "futures" is needed for py2 compatibility and it only works in 2.7 |
| 41 | install_requires.append('futures') |
Benny Peake | a5deae4 | 2016-10-07 19:40:12 -0700 | [diff] [blame] | 42 | install_requires.append('py2-ipaddress') |
Christopher Wiley | fe38276 | 2016-11-07 09:58:32 -0800 | [diff] [blame] | 43 | install_requires.append('subprocess32') |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 44 | |
Ang Li | eb5e505 | 2016-06-24 18:07:11 -0700 | [diff] [blame] | 45 | |
Benny Peake | 914ce73 | 2016-09-26 12:53:03 -0700 | [diff] [blame] | 46 | class PyTest(test.test): |
Ang Li | eb5e505 | 2016-06-24 18:07:11 -0700 | [diff] [blame] | 47 | """Class used to execute unit tests using PyTest. This allows us to execute |
| 48 | unit tests without having to install the package. |
| 49 | """ |
Benny Peake | 914ce73 | 2016-09-26 12:53:03 -0700 | [diff] [blame] | 50 | |
Ang Li | eb5e505 | 2016-06-24 18:07:11 -0700 | [diff] [blame] | 51 | def finalize_options(self): |
Benny Peake | 914ce73 | 2016-09-26 12:53:03 -0700 | [diff] [blame] | 52 | test.test.finalize_options(self) |
Ang Li | eb5e505 | 2016-06-24 18:07:11 -0700 | [diff] [blame] | 53 | 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 Peake | e7fd929 | 2016-09-28 14:26:36 -0700 | [diff] [blame] | 62 | class 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 Rambish | 4bc048b | 2017-05-31 14:14:24 -0700 | [diff] [blame^] | 80 | import pip |
| 81 | pip.main(['install', '--upgrade', 'pip']) |
Benny Peake | e7fd929 | 2016-09-28 14:26:36 -0700 | [diff] [blame] | 82 | 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 Peake | 914ce73 | 2016-09-26 12:53:03 -0700 | [diff] [blame] | 91 | class 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 Peake | c973e29 | 2016-11-09 13:43:39 -0800 | [diff] [blame] | 115 | for acts_install_dir in acts_module.__path__: |
Jack He | e478783 | 2017-01-24 22:31:18 -0800 | [diff] [blame] | 116 | self.announce('Deleting acts from: %s' % acts_install_dir, |
| 117 | log.INFO) |
Benny Peake | c973e29 | 2016-11-09 13:43:39 -0800 | [diff] [blame] | 118 | shutil.rmtree(acts_install_dir) |
Benny Peake | 914ce73 | 2016-09-26 12:53:03 -0700 | [diff] [blame] | 119 | |
| 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 Peake | fe6113c | 2016-10-13 19:47:16 -0700 | [diff] [blame] | 124 | our_dir = os.path.abspath(os.path.dirname(__file__)) |
| 125 | if our_dir in sys.path: |
| 126 | sys.path.remove(our_dir) |
| 127 | |
Benny Peake | 914ce73 | 2016-09-26 12:53:03 -0700 | [diff] [blame] | 128 | 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 He | e478783 | 2017-01-24 22:31:18 -0800 | [diff] [blame] | 134 | self.announce( |
| 135 | 'Acts is not installed, nothing to uninstall.', |
| 136 | level=log.ERROR) |
Benny Peake | 914ce73 | 2016-09-26 12:53:03 -0700 | [diff] [blame] | 137 | 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 Peake | e7fd929 | 2016-09-28 14:26:36 -0700 | [diff] [blame] | 150 | def main(): |
Jack He | e478783 | 2017-01-24 22:31:18 -0800 | [diff] [blame] | 151 | 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 Peake | e7fd929 | 2016-09-28 14:26:36 -0700 | [diff] [blame] | 167 | |
| 168 | |
| 169 | if __name__ == '__main__': |
| 170 | main() |