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