Esempio n. 1
0
def test_cli(*arguments):
    """
    Test the pip-accel command line interface.

    Runs pip-accel's command line interface inside the current Python process
    by temporarily changing :py:data:`sys.argv`, invoking the
    :py:func:`pip_accel.cli.main()` function and catching
    :py:exc:`~exceptions.SystemExit`.

    :param arguments: The value that :py:data:`sys.argv` should be set to (a
                      list of strings).
    :returns: The exit code of ``pip-accel``.
    """
    original_argv = sys.argv
    try:
        sys.argv = list(arguments)
        main()
        return 0
    except SystemExit as e:
        return e.code
    finally:
        sys.argv = original_argv
Esempio n. 2
0
 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'))
Esempio n. 3
0
# Accelerator for pip, the Python package manager.
#
# Author: Peter Odding <*****@*****.**>
# Last Change: March 14, 2016
# URL: https://github.com/paylogic/pip-accel

"""
Enable running `pip-accel` as ``python -m pip_accel ...``.

This module provides a uniform (platform independent) syntax for invoking
`pip-accel`, that is to say the command line ``python -m pip_accel ...`` works
the same on Windows, Linux and Mac OS X.

This requires Python 2.7 or higher (it specifically doesn't work on Python
2.6). The way ``__main__`` modules work is documented under the documentation
of the `python -m`_ construct.

.. _python -m: https://docs.python.org/2/using/cmdline.html#cmdoption-m
"""

from pip_accel.cli import main

if __name__ == '__main__':
    main()
Esempio n. 4
0
 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'))