blob: 179d2af32afe540a3c96f5f1b2158d6176635dd4 [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
Benny Peakee7fd9292016-09-28 14:26:36 -070020import pip
Benny Peake914ce732016-09-26 12:53:03 -070021import shutil
22import setuptools
23from setuptools.command import test
Alexander Dorokhine5eb366e2016-03-14 12:04:40 -070024import sys
25
Alexander Dorokhine5eb366e2016-03-14 12:04:40 -070026install_requires = [
Alexander Dorokhine5eb366e2016-03-14 12:04:40 -070027 'future',
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',
31 'pyserial',
32]
Ang Lieb5e5052016-06-24 18:07:11 -070033
34if sys.version_info < (3, ):
Alexander Dorokhine5eb366e2016-03-14 12:04:40 -070035 install_requires.append('enum34')
Etan Cohen10200962016-10-06 10:56:52 -070036 install_requires.append('statistics')
Ang Lia7a30692016-09-21 13:25:53 -070037 # "futures" is needed for py2 compatibility and it only works in 2.7
38 install_requires.append('futures')
Benny Peakea5deae42016-10-07 19:40:12 -070039 install_requires.append('py2-ipaddress')
Ang Li73697b32015-12-03 00:41:53 +000040
Ang Lieb5e5052016-06-24 18:07:11 -070041
Benny Peake914ce732016-09-26 12:53:03 -070042class PyTest(test.test):
Ang Lieb5e5052016-06-24 18:07:11 -070043 """Class used to execute unit tests using PyTest. This allows us to execute
44 unit tests without having to install the package.
45 """
Benny Peake914ce732016-09-26 12:53:03 -070046
Ang Lieb5e5052016-06-24 18:07:11 -070047 def finalize_options(self):
Benny Peake914ce732016-09-26 12:53:03 -070048 test.test.finalize_options(self)
Ang Lieb5e5052016-06-24 18:07:11 -070049 self.test_args = ['-x', "tests"]
50 self.test_suite = True
51
52 def run_tests(self):
53 import pytest
54 errno = pytest.main(self.test_args)
55 sys.exit(errno)
56
57
Benny Peakee7fd9292016-09-28 14:26:36 -070058class ActsInstallDependencies(cmd.Command):
59 """Installs only required packages
60
61 Installs all required packages for acts to work. Rather than using the
62 normal install system which creates links with the python egg, pip is
63 used to install the packages.
64 """
65
66 description = 'Install dependencies needed for acts to run on this machine.'
67 user_options = []
68
69 def initialize_options(self):
70 pass
71
72 def finalize_options(self):
73 pass
74
75 def run(self):
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
Benny Peake914ce732016-09-26 12:53:03 -070085class 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 if os.getcwd() in sys.path:
119 sys.path.remove(os.getcwd())
120
121 try:
122 import acts as acts_module
123 except ImportError:
124 self.announce('Acts is not installed, nothing to uninstall.',
125 level=log.ERROR)
126 return
127
128 while acts_module:
129 self.uninstall_acts_module(acts_module)
130 try:
131 del sys.modules['acts']
132 import acts as acts_module
133 except ImportError:
134 acts_module = None
135
136 self.announce('Finished uninstalling acts.')
137
138
Benny Peakee7fd9292016-09-28 14:26:36 -0700139def main():
140 setuptools.setup(name='acts',
141 version='0.9',
142 description='Android Comms Test Suite',
143 license='Apache2.0',
144 packages=setuptools.find_packages(),
145 include_package_data=False,
146 tests_require=['pytest'],
147 install_requires=install_requires,
148 scripts=['acts/bin/act.py', 'acts/bin/monsoon.py'],
149 cmdclass={'test': PyTest,
150 'install_deps': ActsInstallDependencies,
151 'uninstall': ActsUninstall},
152 url="http://www.android.com/")
153
154
155if __name__ == '__main__':
156 main()