Home | History | Annotate | Download | only in lab
      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 from distutils import cmd
     17 from distutils import log
     18 import pip
     19 import setuptools
     20 import sys
     21 import subprocess
     22 import os
     23 
     24 README_FILE = os.path.join(os.path.dirname(__file__), 'README.md')
     25 
     26 install_requires = [
     27     # Future needs to have a newer version that contains urllib.
     28     'future>=0.16.0',
     29     'psutil',
     30     'shellescape',
     31     'IPy',
     32 ]
     33 
     34 if sys.version_info < (3, ):
     35     # "futures" is needed for py2 compatibility and it only works in 2.7
     36     install_requires.append('futures')
     37     install_requires.append('subprocess32')
     38 
     39 try:
     40     # Need to install python-dev to work with Python2.7 installing.
     41     subprocess.check_call(['apt-get', 'install', '-y', 'python-dev'])
     42 except subprocess.CalledProcessError as cpe:
     43     print('Could not install python-dev: %s' % cpe.output)
     44 
     45 
     46 class LabHealthInstallDependencies(cmd.Command):
     47     """Installs only required packages
     48 
     49     Installs all required packages for acts to work. Rather than using the
     50     normal install system which creates links with the python egg, pip is
     51     used to install the packages.
     52     """
     53 
     54     description = 'Install dependencies needed for lab health.'
     55     user_options = []
     56 
     57     def initialize_options(self):
     58         pass
     59 
     60     def finalize_options(self):
     61         pass
     62 
     63     def run(self):
     64         pip.main(['install', '--upgrade', 'pip'])
     65 
     66         required_packages = self.distribution.install_requires
     67         for package in required_packages:
     68             self.announce('Installing %s...' % package, log.INFO)
     69             pip.main(['install', package])
     70 
     71         self.announce('Dependencies installed.')
     72 
     73 
     74 def main():
     75     setuptools.setup(
     76         name='LabHealth',
     77         version='0.1',
     78         description='Android Test Lab Health',
     79         license='Apache2.0',
     80         cmdclass={
     81             'install_deps': LabHealthInstallDependencies,
     82         },
     83         packages=setuptools.find_packages(),
     84         include_package_data=False,
     85         install_requires=install_requires,
     86         url="http://www.android.com/",
     87         long_description=open(README_FILE).read())
     88 
     89 
     90 if __name__ == '__main__':
     91     main()
     92