def main(): """The command line interface for the ``pip-accel`` program.""" arguments = sys.argv[1:] # If no arguments are given, the help text of pip-accel is printed. if not arguments: usage() sys.exit(0) # If no install subcommand is given we pass the command line straight # to pip without any changes and exit immediately afterwards. if 'install' not in arguments: # This will not return. os.execvp('pip', ['pip'] + arguments) else: arguments = [arg for arg in arguments if arg != 'install'] # Initialize logging output. coloredlogs.install() # Adjust verbosity based on -v, -q, --verbose, --quiet options. for argument in list(arguments): if match_option(argument, '-v', '--verbose'): coloredlogs.increase_verbosity() elif match_option(argument, '-q', '--quiet'): coloredlogs.decrease_verbosity() # Perform the requested action(s). try: accelerator = PipAccelerator(Config()) accelerator.install_from_arguments(arguments) except NothingToDoError as e: # Don't print a traceback for this (it's not very user friendly). logger.error("%s", e) sys.exit(1) except Exception: logger.exception("Caught unhandled exception!") sys.exit(1)
def main(): """The command line interface for the ``pip-accel`` program.""" arguments = sys.argv[1:] # If no arguments are given, the help text of pip-accel is printed. if not arguments: usage() sys.exit(0) # If no install subcommand is given we pass the command line straight # to pip without any changes and exit immediately afterwards. if 'install' not in arguments: # This will not return. os.execvp('pip', ['pip'] + arguments) else: arguments = [arg for arg in arguments if arg != 'install'] # Initialize logging output. coloredlogs.install() # Adjust verbosity based on -v, -q, --verbose, --quiet options. for argument in list(arguments): if match_option(argument, '-v', '--verbose'): coloredlogs.increase_verbosity() elif match_option(argument, '-q', '--quiet'): coloredlogs.decrease_verbosity() # Perform the requested action(s). try: accelerator = PipAccelerator(Config()) accelerator.install_from_arguments(arguments) except NothingToDoError as e: # Don't print a traceback for this (it's not very user friendly) and # exit with status zero to stay compatible with pip. For more details # please refer to https://github.com/paylogic/pip-accel/issues/47. logger.warning("%s", e) sys.exit(0) except Exception: logger.exception("Caught unhandled exception!") sys.exit(1)
def main(): """The command line interface for the ``pip-accel`` program.""" arguments = sys.argv[1:] # If no arguments are given, the help text of pip-accel is printed. if not arguments: usage() sys.exit(0) # If no install subcommand is given we pass the command line straight # to pip without any changes and exit immediately afterwards. if 'install' not in arguments: # This will not return. os.execvp('pip', ['pip'] + arguments) else: arguments = [arg for arg in arguments if arg != 'install'] # Initialize logging output. coloredlogs.install() # Adjust verbosity based on -v, -q, --verbose, --quiet options. for argument in list(arguments): if match_option(argument, '-v', '--verbose'): coloredlogs.increase_verbosity() elif match_option(argument, '-q', '--quiet'): coloredlogs.decrease_verbosity() # Perform the requested action(s). try: accelerator = PipAccelerator(Config()) accelerator.install_from_arguments(arguments) except Exception: logger.exception("Caught unhandled exception!") sys.exit(1)
def runTest(self): """ A very basic test of the functions that make up the pip-accel command using the `virtualenv` package as a test case. """ accelerator = PipAccelerator(Config(), validate=False) # We will test the downloading, conversion to binary distribution and # installation of the virtualenv package (we simply need a package we # know is available from PyPI). arguments = ['--ignore-installed', 'virtualenv==1.8.4'] # First we do a simple sanity check that unpack_source_dists() does NOT # connect to PyPI when it's missing source distributions (it should # raise a DistributionNotFound exception instead). try: accelerator.unpack_source_dists(arguments) # This line should never be reached. self.assertTrue(False) except Exception as e: # We expect a `DistributionNotFound' exception. self.assertTrue(isinstance(e, DistributionNotFound)) # Download the source distribution from PyPI. requirements = accelerator.download_source_dists(arguments) self.assertTrue(isinstance(requirements, list)) self.assertEqual(len(requirements), 1) self.assertEqual(requirements[0].name, 'virtualenv') self.assertEqual(requirements[0].version, '1.8.4') self.assertTrue(os.path.isdir(requirements[0].source_directory)) # Make sure install_requirements() (really install_binary_dist()) # validates its arguments. self.assertRaises(ValueError, accelerator.install_requirements, requirements=requirements, prefix=self.virtual_environment, python='/usr/bin/python') # Test the build and installation of the binary package. We have to # pass `prefix' explicitly here because the Python process running this # test is not inside the virtual environment created to run the # tests... accelerator.install_requirements(requirements, prefix=self.virtual_environment, python=os.path.join(self.virtual_environment, 'bin', 'python')) # Validate that the `virtualenv' package was properly installed. logger.debug("Checking that `virtualenv' executable was installed ..") self.assertTrue(os.path.isfile(os.path.join(self.virtual_environment, 'bin', 'virtualenv'))) logger.debug("Checking that `virtualenv' command works ..") command = '%s --help' % pipes.quote(os.path.join(self.virtual_environment, 'bin', 'virtualenv')) self.assertEqual(os.system(command), 0) # We now have a non-empty download cache and source index so this # should not raise an exception (it should use the source index). accelerator.unpack_source_dists(arguments) # Verify that pip-accel properly deals with broken symbolic links # pointing from the source index to the download cache. os.unlink(os.path.join(self.download_cache, os.listdir(self.download_cache)[0])) accelerator = PipAccelerator(Config(), validate=False) accelerator.install_from_arguments(arguments) # I'm not yet sure how to effectively test the command line interface, # because this test suite abuses validate=False which the command line # interface does not expose. That's why the following will report an # error message. For now at least we're running the code and making # sure there are no syntax errors / incompatibilities. try: sys.argv = ['pip-accel', 'install', 'virtualenv==1.8.4'] main() # This should not be reached. self.assertTrue(False) except BaseException as e: # For now the main() function is expected to fail and exit with a # nonzero status code (explained above). self.assertTrue(isinstance(e, SystemExit)) # Test system package dependency handling. if coerce_boolean(os.environ.get('PIP_ACCEL_TEST_AUTO_INSTALL')): # Force the removal of a system package required by `lxml' without # removing any (reverse) dependencies (we don't actually want to # break the system, thank you very much :-). Disclaimer: you opt in # to this with $PIP_ACCEL_TEST_AUTO_INSTALL... os.system('sudo dpkg --remove --force-depends libxslt1-dev') os.environ['PIP_ACCEL_AUTO_INSTALL'] = 'true' accelerator = PipAccelerator(Config(), validate=False) accelerator.install_from_arguments(arguments=['--ignore-installed', 'lxml==3.2.1'], prefix=self.virtual_environment, python=os.path.join(self.virtual_environment, 'bin', 'python'))
def runTest(self): """ A very basic test of the functions that make up the pip-accel command using the `virtualenv` package as a test case. """ accelerator = PipAccelerator(Config(), validate=False) # We will test the downloading, conversion to binary distribution and # installation of the virtualenv package (we simply need a package we # know is available from PyPI). arguments = ['--ignore-installed', 'virtualenv==1.8.4'] # First we do a simple sanity check that unpack_source_dists() does NOT # connect to PyPI when it's missing source distributions (it should # raise a DistributionNotFound exception instead). try: accelerator.unpack_source_dists(arguments) # This line should never be reached. self.assertTrue(False) except Exception as e: # We expect a `DistributionNotFound' exception. self.assertTrue(isinstance(e, DistributionNotFound)) # Download the source distribution from PyPI. requirements = accelerator.download_source_dists(arguments) self.assertTrue(isinstance(requirements, list)) self.assertEqual(len(requirements), 1) self.assertEqual(requirements[0].name, 'virtualenv') self.assertEqual(requirements[0].version, '1.8.4') self.assertTrue(os.path.isdir(requirements[0].source_directory)) # Test the build and installation of the binary package. We have to # pass `prefix' explicitly here because the Python process running this # test is not inside the virtual environment created to run the # tests... accelerator.install_requirements(requirements, prefix=self.virtual_environment, python=os.path.join( self.virtual_environment, 'bin', 'python')) # Validate that the `virtualenv' package was properly installed. logger.debug("Checking that `virtualenv' executable was installed ..") self.assertTrue( os.path.isfile( os.path.join(self.virtual_environment, 'bin', 'virtualenv'))) logger.debug("Checking that `virtualenv' command works ..") command = '%s --help' % pipes.quote( os.path.join(self.virtual_environment, 'bin', 'virtualenv')) self.assertEqual(os.system(command), 0) # We now have a non-empty download cache and source index so this # should not raise an exception (it should use the source index). accelerator.unpack_source_dists(arguments) # Verify that pip-accel properly deals with broken symbolic links # pointing from the source index to the download cache. os.unlink( os.path.join(self.download_cache, os.listdir(self.download_cache)[0])) accelerator = PipAccelerator(Config(), validate=False) accelerator.install_from_arguments(arguments) # Verify that pip-accel properly handles setup.py scripts that break # the `bdist_dumb' action but support the `bdist' action as a fall # back. accelerator = PipAccelerator(Config(), validate=False) accelerator.install_from_arguments(['paver==1.2.3']) # I'm not yet sure how to effectively test the command line interface, # because this test suite abuses validate=False which the command line # interface does not expose. That's why the following will report an # error message. For now at least we're running the code and making # sure there are no syntax errors / incompatibilities. try: sys.argv = ['pip-accel', 'install', 'virtualenv==1.8.4'] main() # This should not be reached. self.assertTrue(False) except BaseException as e: # For now the main() function is expected to fail and exit with a # nonzero status code (explained above). self.assertTrue(isinstance(e, SystemExit)) # Test system package dependency handling. if coerce_boolean(os.environ.get('PIP_ACCEL_TEST_AUTO_INSTALL')): # Force the removal of a system package required by `lxml' without # removing any (reverse) dependencies (we don't actually want to # break the system, thank you very much :-). Disclaimer: you opt in # to this with $PIP_ACCEL_TEST_AUTO_INSTALL... os.system('sudo dpkg --remove --force-depends libxslt1-dev') os.environ['PIP_ACCEL_AUTO_INSTALL'] = 'true' accelerator = PipAccelerator(Config(), validate=False) accelerator.install_from_arguments( arguments=['--ignore-installed', 'lxml==3.2.1'], prefix=self.virtual_environment, python=os.path.join(self.virtual_environment, 'bin', 'python'))