def __init__(self, load_configuration_files=True, load_environment_variables=True, **options): """ Initialize a Python to Debian package converter. :param load_configuration_files: When :data:`True` (the default) :func:`load_default_configuration_files()` is called automatically. :param load_environment_variables: When :data:`True` (the default) :func:`load_environment_variables()` is called automatically. :param options: Any keyword arguments are passed on to the initializer of the :class:`~property_manager.PropertyManager` class. """ # Initialize our superclass. super(PackageConverter, self).__init__(**options) # Initialize our internal state. self.pip_accel = PipAccelerator(PipAccelConfig()) if load_configuration_files: self.load_default_configuration_files() if load_environment_variables: self.load_environment_variables()
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 __init__(self, load_configuration_files=True, load_environment_variables=True): """ Initialize a Python to Debian package converter. :param load_configuration_files: When ``True`` (the default) :func:`load_default_configuration_files()` is called automatically. :param load_environment_variables: When ``True`` (the default) :func:`load_environment_variables()` is called automatically. """ self.alternatives = set() self.install_prefix = '/usr' self.lintian_enabled = True self.name_mapping = {} self.system_packages = {} self.name_prefix = 'python' self.pip_accel = PipAccelerator(PipAccelConfig()) self.python_callback = None self.repository = PackageRepository(tempfile.gettempdir()) self.scripts = {} if load_configuration_files: self.load_default_configuration_files() if load_environment_variables: self.load_environment_variables()
def initialize_pip_accel(self, load_environment_variables=False, **overrides): """ Construct an isolated pip accelerator instance. The pip-accel instance will not load configuration files but it may load environment variables because that's how FakeS3 is enabled on Travis CI (and in my local tests). :param load_environment_variables: If ``True`` the pip-accel instance will load environment variables (not the default). :param overrides: Any keyword arguments are set as properties on the :py:class:`~.Config` instance (overrides for configuration defaults). """ config = Config(load_configuration_files=False, load_environment_variables=load_environment_variables) for name, value in overrides.items(): setattr(config, name, value) accelerator = PipAccelerator(config) return accelerator
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'))