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 |
| 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 = [ |
Alexander Dorokhine | 5eb366e | 2016-03-14 12:04:40 -0700 | [diff] [blame] | 26 | 'future', |
| 27 | # mock-1.0.1 is the last version compatible with setuptools <17.1, |
| 28 | # which is what comes with Ubuntu 14.04 LTS. |
| 29 | 'mock<=1.0.1', |
| 30 | 'pyserial', |
Christopher Wiley | fe38276 | 2016-11-07 09:58:32 -0800 | [diff] [blame^] | 31 | 'shellescape', |
Alexander Dorokhine | 5eb366e | 2016-03-14 12:04:40 -0700 | [diff] [blame] | 32 | ] |
Ang Li | eb5e505 | 2016-06-24 18:07:11 -0700 | [diff] [blame] | 33 | |
| 34 | if sys.version_info < (3, ): |
Alexander Dorokhine | 5eb366e | 2016-03-14 12:04:40 -0700 | [diff] [blame] | 35 | install_requires.append('enum34') |
Etan Cohen | 1020096 | 2016-10-06 10:56:52 -0700 | [diff] [blame] | 36 | install_requires.append('statistics') |
Ang Li | a7a3069 | 2016-09-21 13:25:53 -0700 | [diff] [blame] | 37 | # "futures" is needed for py2 compatibility and it only works in 2.7 |
| 38 | install_requires.append('futures') |
Benny Peake | a5deae4 | 2016-10-07 19:40:12 -0700 | [diff] [blame] | 39 | install_requires.append('py2-ipaddress') |
Christopher Wiley | fe38276 | 2016-11-07 09:58:32 -0800 | [diff] [blame^] | 40 | install_requires.append('subprocess32') |
Ang Li | 73697b3 | 2015-12-03 00:41:53 +0000 | [diff] [blame] | 41 | |
Ang Li | eb5e505 | 2016-06-24 18:07:11 -0700 | [diff] [blame] | 42 | |
Benny Peake | 914ce73 | 2016-09-26 12:53:03 -0700 | [diff] [blame] | 43 | class PyTest(test.test): |
Ang Li | eb5e505 | 2016-06-24 18:07:11 -0700 | [diff] [blame] | 44 | """Class used to execute unit tests using PyTest. This allows us to execute |
| 45 | unit tests without having to install the package. |
| 46 | """ |
Benny Peake | 914ce73 | 2016-09-26 12:53:03 -0700 | [diff] [blame] | 47 | |
Ang Li | eb5e505 | 2016-06-24 18:07:11 -0700 | [diff] [blame] | 48 | def finalize_options(self): |
Benny Peake | 914ce73 | 2016-09-26 12:53:03 -0700 | [diff] [blame] | 49 | test.test.finalize_options(self) |
Ang Li | eb5e505 | 2016-06-24 18:07:11 -0700 | [diff] [blame] | 50 | self.test_args = ['-x', "tests"] |
| 51 | self.test_suite = True |
| 52 | |
| 53 | def run_tests(self): |
| 54 | import pytest |
| 55 | errno = pytest.main(self.test_args) |
| 56 | sys.exit(errno) |
| 57 | |
| 58 | |
Benny Peake | e7fd929 | 2016-09-28 14:26:36 -0700 | [diff] [blame] | 59 | class ActsInstallDependencies(cmd.Command): |
| 60 | """Installs only required packages |
| 61 | |
| 62 | Installs all required packages for acts to work. Rather than using the |
| 63 | normal install system which creates links with the python egg, pip is |
| 64 | used to install the packages. |
| 65 | """ |
| 66 | |
| 67 | description = 'Install dependencies needed for acts to run on this machine.' |
| 68 | user_options = [] |
| 69 | |
| 70 | def initialize_options(self): |
| 71 | pass |
| 72 | |
| 73 | def finalize_options(self): |
| 74 | pass |
| 75 | |
| 76 | def run(self): |
Benny Peake | b7fa202 | 2016-10-13 11:24:58 -0700 | [diff] [blame] | 77 | import pip |
| 78 | |
Benny Peake | e7fd929 | 2016-09-28 14:26:36 -0700 | [diff] [blame] | 79 | required_packages = self.distribution.install_requires |
| 80 | |
| 81 | for package in required_packages: |
| 82 | self.announce('Installing %s...' % package, log.INFO) |
| 83 | pip.main(['install', package]) |
| 84 | |
| 85 | self.announce('Dependencies installed.') |
| 86 | |
| 87 | |
Benny Peake | 914ce73 | 2016-09-26 12:53:03 -0700 | [diff] [blame] | 88 | class ActsUninstall(cmd.Command): |
| 89 | """Acts uninstaller. |
| 90 | |
| 91 | Uninstalls acts from the current version of python. This will attempt to |
| 92 | import acts from any of the python egg locations. If it finds an import |
| 93 | it will use the modules file location to delete it. This is repeated until |
| 94 | acts can no longer be imported and thus is uninstalled. |
| 95 | """ |
| 96 | |
| 97 | description = 'Uninstall acts from the local machine.' |
| 98 | user_options = [] |
| 99 | |
| 100 | def initialize_options(self): |
| 101 | pass |
| 102 | |
| 103 | def finalize_options(self): |
| 104 | pass |
| 105 | |
| 106 | def uninstall_acts_module(self, acts_module): |
| 107 | """Uninstalls acts from a module. |
| 108 | |
| 109 | Args: |
| 110 | acts_module: The acts module to uninstall. |
| 111 | """ |
| 112 | acts_install_dir = os.path.dirname(acts_module.__file__) |
| 113 | |
| 114 | self.announce('Deleting acts from: %s' % acts_install_dir, log.INFO) |
| 115 | shutil.rmtree(acts_install_dir) |
| 116 | |
| 117 | def run(self): |
| 118 | """Entry point for the uninstaller.""" |
| 119 | # Remove the working directory from the python path. This ensures that |
| 120 | # Source code is not accidently tarageted. |
Benny Peake | b4cd895 | 2016-10-13 19:47:16 -0700 | [diff] [blame] | 121 | our_dir = os.path.abspath(os.path.dirname(__file__)) |
| 122 | if our_dir in sys.path: |
| 123 | sys.path.remove(our_dir) |
| 124 | |
Benny Peake | 914ce73 | 2016-09-26 12:53:03 -0700 | [diff] [blame] | 125 | if os.getcwd() in sys.path: |
| 126 | sys.path.remove(os.getcwd()) |
| 127 | |
| 128 | try: |
| 129 | import acts as acts_module |
| 130 | except ImportError: |
| 131 | self.announce('Acts is not installed, nothing to uninstall.', |
| 132 | level=log.ERROR) |
| 133 | return |
| 134 | |
| 135 | while acts_module: |
| 136 | self.uninstall_acts_module(acts_module) |
| 137 | try: |
| 138 | del sys.modules['acts'] |
| 139 | import acts as acts_module |
| 140 | except ImportError: |
| 141 | acts_module = None |
| 142 | |
| 143 | self.announce('Finished uninstalling acts.') |
| 144 | |
| 145 | |
Benny Peake | e7fd929 | 2016-09-28 14:26:36 -0700 | [diff] [blame] | 146 | def main(): |
| 147 | setuptools.setup(name='acts', |
| 148 | version='0.9', |
| 149 | description='Android Comms Test Suite', |
| 150 | license='Apache2.0', |
| 151 | packages=setuptools.find_packages(), |
| 152 | include_package_data=False, |
| 153 | tests_require=['pytest'], |
| 154 | install_requires=install_requires, |
| 155 | scripts=['acts/bin/act.py', 'acts/bin/monsoon.py'], |
| 156 | cmdclass={'test': PyTest, |
| 157 | 'install_deps': ActsInstallDependencies, |
| 158 | 'uninstall': ActsUninstall}, |
| 159 | url="http://www.android.com/") |
| 160 | |
| 161 | |
| 162 | if __name__ == '__main__': |
| 163 | main() |