blob: 97487cf48281c291a25d261197a179a01a471f42 [file] [log] [blame]
tturney1bdf77d2015-12-28 17:46:13 -08001#!/usr/bin/env python3.4
Ang Lieb5e5052016-06-24 18:07:11 -07002#
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 Peake914ce732016-09-26 12:53:03 -070017from distutils import cmd
18from distutils import log
19import os
20import shutil
21import setuptools
22from setuptools.command import test
Alexander Dorokhine5eb366e2016-03-14 12:04:40 -070023import sys
24
Alexander Dorokhine5eb366e2016-03-14 12:04:40 -070025install_requires = [
Alexander Dorokhine5eb366e2016-03-14 12:04:40 -070026 '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 Wileyfe382762016-11-07 09:58:32 -080031 'shellescape',
Jack Hee4787832017-01-24 22:31:18 -080032 'protobuf',
Alexander Dorokhine5eb366e2016-03-14 12:04:40 -070033]
Ang Lieb5e5052016-06-24 18:07:11 -070034
35if sys.version_info < (3, ):
Alexander Dorokhine5eb366e2016-03-14 12:04:40 -070036 install_requires.append('enum34')
Etan Cohen10200962016-10-06 10:56:52 -070037 install_requires.append('statistics')
Ang Lia7a30692016-09-21 13:25:53 -070038 # "futures" is needed for py2 compatibility and it only works in 2.7
39 install_requires.append('futures')
Benny Peakea5deae42016-10-07 19:40:12 -070040 install_requires.append('py2-ipaddress')
Christopher Wileyfe382762016-11-07 09:58:32 -080041 install_requires.append('subprocess32')
Ang Li73697b32015-12-03 00:41:53 +000042
Ang Lieb5e5052016-06-24 18:07:11 -070043
Benny Peake914ce732016-09-26 12:53:03 -070044class PyTest(test.test):
Ang Lieb5e5052016-06-24 18:07:11 -070045 """Class used to execute unit tests using PyTest. This allows us to execute
46 unit tests without having to install the package.
47 """
Benny Peake914ce732016-09-26 12:53:03 -070048
Ang Lieb5e5052016-06-24 18:07:11 -070049 def finalize_options(self):
Benny Peake914ce732016-09-26 12:53:03 -070050 test.test.finalize_options(self)
Ang Lieb5e5052016-06-24 18:07:11 -070051 self.test_args = ['-x', "tests"]
52 self.test_suite = True
53
54 def run_tests(self):
55 import pytest
56 errno = pytest.main(self.test_args)
57 sys.exit(errno)
58
59
Benny Peakee7fd9292016-09-28 14:26:36 -070060class ActsInstallDependencies(cmd.Command):
61 """Installs only required packages
62
63 Installs all required packages for acts to work. Rather than using the
64 normal install system which creates links with the python egg, pip is
65 used to install the packages.
66 """
67
68 description = 'Install dependencies needed for acts to run on this machine.'
69 user_options = []
70
71 def initialize_options(self):
72 pass
73
74 def finalize_options(self):
75 pass
76
77 def run(self):
Benny Peakeb7fa2022016-10-13 11:24:58 -070078 import pip
79
Benny Peakee7fd9292016-09-28 14:26:36 -070080 required_packages = self.distribution.install_requires
81
82 for package in required_packages:
83 self.announce('Installing %s...' % package, log.INFO)
84 pip.main(['install', package])
85
86 self.announce('Dependencies installed.')
87
88
Benny Peake914ce732016-09-26 12:53:03 -070089class ActsUninstall(cmd.Command):
90 """Acts uninstaller.
91
92 Uninstalls acts from the current version of python. This will attempt to
93 import acts from any of the python egg locations. If it finds an import
94 it will use the modules file location to delete it. This is repeated until
95 acts can no longer be imported and thus is uninstalled.
96 """
97
98 description = 'Uninstall acts from the local machine.'
99 user_options = []
100
101 def initialize_options(self):
102 pass
103
104 def finalize_options(self):
105 pass
106
107 def uninstall_acts_module(self, acts_module):
108 """Uninstalls acts from a module.
109
110 Args:
111 acts_module: The acts module to uninstall.
112 """
Benny Peakec973e292016-11-09 13:43:39 -0800113 for acts_install_dir in acts_module.__path__:
Jack Hee4787832017-01-24 22:31:18 -0800114 self.announce('Deleting acts from: %s' % acts_install_dir,
115 log.INFO)
Benny Peakec973e292016-11-09 13:43:39 -0800116 shutil.rmtree(acts_install_dir)
Benny Peake914ce732016-09-26 12:53:03 -0700117
118 def run(self):
119 """Entry point for the uninstaller."""
120 # Remove the working directory from the python path. This ensures that
121 # Source code is not accidently tarageted.
Benny Peakeb4cd8952016-10-13 19:47:16 -0700122 our_dir = os.path.abspath(os.path.dirname(__file__))
123 if our_dir in sys.path:
124 sys.path.remove(our_dir)
125
Benny Peake914ce732016-09-26 12:53:03 -0700126 if os.getcwd() in sys.path:
127 sys.path.remove(os.getcwd())
128
129 try:
130 import acts as acts_module
131 except ImportError:
Jack Hee4787832017-01-24 22:31:18 -0800132 self.announce(
133 'Acts is not installed, nothing to uninstall.',
134 level=log.ERROR)
Benny Peake914ce732016-09-26 12:53:03 -0700135 return
136
137 while acts_module:
138 self.uninstall_acts_module(acts_module)
139 try:
140 del sys.modules['acts']
141 import acts as acts_module
142 except ImportError:
143 acts_module = None
144
145 self.announce('Finished uninstalling acts.')
146
147
Benny Peakee7fd9292016-09-28 14:26:36 -0700148def main():
Jack Hee4787832017-01-24 22:31:18 -0800149 setuptools.setup(
150 name='acts',
151 version='0.9',
152 description='Android Comms Test Suite',
153 license='Apache2.0',
154 packages=setuptools.find_packages(),
155 include_package_data=False,
156 tests_require=['pytest'],
157 install_requires=install_requires,
158 scripts=['acts/bin/act.py', 'acts/bin/monsoon.py'],
159 cmdclass={
160 'test': PyTest,
161 'install_deps': ActsInstallDependencies,
162 'uninstall': ActsUninstall
163 },
164 url="http://www.android.com/")
Benny Peakee7fd9292016-09-28 14:26:36 -0700165
166
167if __name__ == '__main__':
168 main()