• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
17from distutils import cmd
18from distutils import log
19import os
20import shutil
21import setuptools
22from setuptools.command import test
23import sys
24
25
26install_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]
34if 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
40class 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
56class 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
85class 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        for acts_install_dir in acts_module.__path__:
110            self.announce('Deleting acts from: %s' % acts_install_dir, log.INFO)
111            shutil.rmtree(acts_install_dir)
112
113    def run(self):
114        """Entry point for the uninstaller."""
115        # Remove the working directory from the python path. This ensures that
116        # Source code is not accidently tarageted.
117        our_dir = os.path.abspath(os.path.dirname(__file__))
118        if our_dir in sys.path:
119            sys.path.remove(our_dir)
120
121        if os.getcwd() in sys.path:
122            sys.path.remove(os.getcwd())
123
124        try:
125            import acts as acts_module
126        except ImportError:
127            self.announce('Acts is not installed, nothing to uninstall.',
128                          level=log.ERROR)
129            return
130
131        while acts_module:
132            self.uninstall_acts_module(acts_module)
133            try:
134                del sys.modules['acts']
135                import acts as acts_module
136            except ImportError:
137                acts_module = None
138
139        self.announce('Finished uninstalling acts.')
140
141
142def main():
143    setuptools.setup(name='acts',
144                     version='0.9',
145                     description='Android Comms Test Suite',
146                     license='Apache2.0',
147                     packages=setuptools.find_packages(),
148                     include_package_data=False,
149                     tests_require=['pytest'],
150                     install_requires=install_requires,
151                     scripts=['acts/bin/act.py', 'acts/bin/monsoon.py'],
152                     cmdclass={'test': PyTest,
153                               'install_deps': ActsInstallDependencies,
154                               'uninstall': ActsUninstall},
155                     url="http://www.android.com/")
156
157
158if __name__ == '__main__':
159    main()
160