Beispiel #1
0
    def test_setup_requires_overrides_version_conflict(self):
        """
        Regression test for issue #323.

        Ensures that a distribution's setup_requires requirements can still be
        installed and used locally even if a conflicting version of that
        requirement is already on the path.
        """

        pr_state = pkg_resources.__getstate__()
        fake_dist = PRDistribution('does-not-matter',
                                   project_name='foobar',
                                   version='0.0')
        working_set.add(fake_dist)

        try:
            with contexts.tempdir() as temp_dir:
                test_pkg = create_setup_requires_package(temp_dir)
                test_setup_py = os.path.join(test_pkg, 'setup.py')
                with contexts.quiet() as (stdout, stderr):
                    # Don't even need to install the package, just
                    # running the setup.py at all is sufficient
                    run_setup(test_setup_py, ['--name'])

                lines = stdout.readlines()
                assert len(lines) > 0
                assert lines[-1].strip(), 'test_pkg'
        finally:
            pkg_resources.__setstate__(pr_state)
Beispiel #2
0
    def test_setup_requires_overrides_version_conflict(self, use_setup_cfg):
        """
        Regression test for distribution issue 323:
        https://bitbucket.org/tarek/distribute/issues/323

        Ensures that a distribution's setup_requires requirements can still be
        installed and used locally even if a conflicting version of that
        requirement is already on the path.
        """

        fake_dist = PRDistribution('does-not-matter',
                                   project_name='foobar',
                                   version='0.0')
        working_set.add(fake_dist)

        with contexts.save_pkg_resources_state():
            with contexts.tempdir() as temp_dir:
                test_pkg = create_setup_requires_package(
                    temp_dir, use_setup_cfg=use_setup_cfg)
                test_setup_py = os.path.join(test_pkg, 'setup.py')
                with contexts.quiet() as (stdout, stderr):
                    # Don't even need to install the package, just
                    # running the setup.py at all is sufficient
                    run_setup(test_setup_py, [str('--name')])

                lines = stdout.readlines()
                assert len(lines) > 0
                assert lines[-1].strip() == 'test_pkg'
Beispiel #3
0
    def test_setup_requires_overrides_version_conflict(self):
        """
        Regression test for issue #323.

        Ensures that a distribution's setup_requires requirements can still be
        installed and used locally even if a conflicting version of that
        requirement is already on the path.
        """

        pr_state = pkg_resources.__getstate__()
        fake_dist = PRDistribution('does-not-matter',
                                   project_name='foobar',
                                   version='0.0')
        working_set.add(fake_dist)

        def setup_and_run(temp_dir):
            test_pkg = create_setup_requires_package(temp_dir)
            test_setup_py = os.path.join(test_pkg, 'setup.py')
            try:
                stdout, stderr = quiet_context(lambda: reset_setup_stop_context(
                    # Don't even need to install the package, just running
                    # the setup.py at all is sufficient
                    lambda: run_setup(test_setup_py, ['--name'])))
            except VersionConflict:
                self.fail('Installing setup.py requirements caused '
                          'VersionConflict')

            lines = stdout.splitlines()
            self.assertGreater(len(lines), 0)
            self.assert_(lines[-1].strip(), 'test_pkg')

        try:
            tempdir_context(setup_and_run)
        finally:
            pkg_resources.__setstate__(pr_state)
Beispiel #4
0
 def test_add_from_cwd_site_sets_dirty(self):
     '''a pth file manager should set dirty
     if a distribution is in site but also the cwd
     '''
     pth = PthDistributions('does-not_exist', [os.getcwd()])
     assert not pth.dirty
     pth.add(PRDistribution(os.getcwd()))
     assert pth.dirty
 def test_add_from_site_is_ignored(self):
     location = '/test/location/does-not-have-to-exist'
     # PthDistributions expects all locations to be normalized
     location = pkg_resources.normalize_path(location)
     pth = PthDistributions('does-not_exist', [location, ])
     assert not pth.dirty
     pth.add(PRDistribution(location))
     assert not pth.dirty
    def test_setup_requires_override_nspkg(self, use_setup_cfg):
        """
        Like ``test_setup_requires_overrides_version_conflict`` but where the
        ``setup_requires`` package is part of a namespace package that has
        *already* been imported.
        """

        with contexts.save_pkg_resources_state():
            with contexts.tempdir() as temp_dir:
                foobar_1_archive = os.path.join(temp_dir, 'foo.bar-0.1.tar.gz')
                make_nspkg_sdist(foobar_1_archive, 'foo.bar', '0.1')
                # Now actually go ahead an extract to the temp dir and add the
                # extracted path to sys.path so foo.bar v0.1 is importable
                foobar_1_dir = os.path.join(temp_dir, 'foo.bar-0.1')
                os.mkdir(foobar_1_dir)
                with tarfile.open(foobar_1_archive) as tf:
                    tf.extractall(foobar_1_dir)
                sys.path.insert(1, foobar_1_dir)

                dist = PRDistribution(foobar_1_dir, project_name='foo.bar',
                                      version='0.1')
                working_set.add(dist)

                template = DALS("""\
                    import foo  # Even with foo imported first the
                                # setup_requires package should override
                    import setuptools
                    setuptools.setup(**%r)

                    if not (hasattr(foo, '__path__') and
                            len(foo.__path__) == 2):
                        print('FAIL')

                    if 'foo.bar-0.2' not in foo.__path__[0]:
                        print('FAIL')
                """)

                test_pkg = create_setup_requires_package(
                    temp_dir, 'foo.bar', '0.2', make_nspkg_sdist, template,
                    use_setup_cfg=use_setup_cfg)

                test_setup_py = os.path.join(test_pkg, 'setup.py')

                with contexts.quiet() as (stdout, stderr):
                    try:
                        # Don't even need to install the package, just
                        # running the setup.py at all is sufficient
                        run_setup(test_setup_py, [str('--name')])
                    except pkg_resources.VersionConflict:
                        self.fail(
                            'Installing setup.py requirements '
                            'caused a VersionConflict')

                assert 'FAIL' not in stdout.getvalue()
                lines = stdout.readlines()
                assert len(lines) > 0
                assert lines[-1].strip() == 'test_pkg'
 def test_add_from_site_is_ignored(self):
     if os.name != 'nt':
         location = '/test/location/does-not-have-to-exist'
     else:
         location = 'c:\\does_not_exist'
     pth = PthDistributions('does-not_exist', [location, ])
     self.assert_(not pth.dirty)
     pth.add(PRDistribution(location))
     self.assert_(not pth.dirty)
Beispiel #8
0
 def test_add_from_site_is_ignored(self):
     pth = PthDistributions('does-not_exist',
                            ['/test/location/does-not-have-to-exist'])
     self.assert_(not pth.dirty)
     pth.add(PRDistribution('/test/location/does-not-have-to-exist'))
     self.assert_(not pth.dirty)