Merge "Clean imports in code"
This commit is contained in:
		@@ -41,8 +41,8 @@
 | 
				
			|||||||
import os
 | 
					import os
 | 
				
			||||||
import textwrap
 | 
					import textwrap
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from testtools.content import text_content
 | 
					from testtools import content
 | 
				
			||||||
from testtools.matchers import Contains, EndsWith
 | 
					from testtools import matchers
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from pbr.tests import base
 | 
					from pbr.tests import base
 | 
				
			||||||
from pbr.tests import util
 | 
					from pbr.tests import util
 | 
				
			||||||
@@ -85,16 +85,16 @@ class TestHooks(base.BaseTestCase):
 | 
				
			|||||||
        assert return_code == 0
 | 
					        assert return_code == 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        stdout, stderr, return_code = self.run_setup('build_ext')
 | 
					        stdout, stderr, return_code = self.run_setup('build_ext')
 | 
				
			||||||
        self.addDetailUniqueName('stderr', text_content(stderr))
 | 
					        self.addDetailUniqueName('stderr', content.text_content(stderr))
 | 
				
			||||||
        assert textwrap.dedent("""
 | 
					        assert textwrap.dedent("""
 | 
				
			||||||
            running build_ext
 | 
					            running build_ext
 | 
				
			||||||
            running pre_hook pbr_testpackage._setup_hooks.test_pre_hook for command build_ext
 | 
					            running pre_hook pbr_testpackage._setup_hooks.test_pre_hook for command build_ext
 | 
				
			||||||
            build_ext pre-hook
 | 
					            build_ext pre-hook
 | 
				
			||||||
        """) in stdout  # flake8: noqa
 | 
					        """) in stdout  # flake8: noqa
 | 
				
			||||||
        self.expectThat(stdout, EndsWith('build_ext post-hook'))
 | 
					        self.expectThat(stdout, matchers.EndsWith('build_ext post-hook'))
 | 
				
			||||||
        assert return_code == 0
 | 
					        assert return_code == 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_custom_commands_known(self):
 | 
					    def test_custom_commands_known(self):
 | 
				
			||||||
        stdout, _, return_code = self.run_setup('--help-commands')
 | 
					        stdout, _, return_code = self.run_setup('--help-commands')
 | 
				
			||||||
        self.assertFalse(return_code)
 | 
					        self.assertFalse(return_code)
 | 
				
			||||||
        self.assertThat(stdout, Contains(" testr "))
 | 
					        self.assertThat(stdout, matchers.Contains(" testr "))
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,8 +20,7 @@ import testtools
 | 
				
			|||||||
import textwrap
 | 
					import textwrap
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from pbr.tests import base
 | 
					from pbr.tests import base
 | 
				
			||||||
from pbr.tests.test_packaging import CreatePackages
 | 
					from pbr.tests import test_packaging
 | 
				
			||||||
from pbr.tests.test_packaging import Venv
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
PIPFLAGS = shlex.split(os.environ.get('PIPFLAGS', ''))
 | 
					PIPFLAGS = shlex.split(os.environ.get('PIPFLAGS', ''))
 | 
				
			||||||
PIPVERSION = os.environ.get('PIPVERSION', 'pip')
 | 
					PIPVERSION = os.environ.get('PIPVERSION', 'pip')
 | 
				
			||||||
@@ -91,13 +90,15 @@ class TestIntegration(base.BaseTestCase):
 | 
				
			|||||||
        self.useFixture(base.CapturedSubprocess(
 | 
					        self.useFixture(base.CapturedSubprocess(
 | 
				
			||||||
            'clone',
 | 
					            'clone',
 | 
				
			||||||
            ['git', 'clone', os.path.join(REPODIR, self.short_name), path]))
 | 
					            ['git', 'clone', os.path.join(REPODIR, self.short_name), path]))
 | 
				
			||||||
        venv = self.useFixture(Venv('sdist',
 | 
					        venv = self.useFixture(
 | 
				
			||||||
 | 
					            test_packaging.Venv('sdist',
 | 
				
			||||||
                                modules=['pip', 'wheel', PBRVERSION],
 | 
					                                modules=['pip', 'wheel', PBRVERSION],
 | 
				
			||||||
                                pip_cmd=PIP_CMD))
 | 
					                                pip_cmd=PIP_CMD))
 | 
				
			||||||
        python = venv.python
 | 
					        python = venv.python
 | 
				
			||||||
        self.useFixture(base.CapturedSubprocess(
 | 
					        self.useFixture(base.CapturedSubprocess(
 | 
				
			||||||
            'sdist', [python, 'setup.py', 'sdist'], cwd=path))
 | 
					            'sdist', [python, 'setup.py', 'sdist'], cwd=path))
 | 
				
			||||||
        venv = self.useFixture(Venv('tarball',
 | 
					        venv = self.useFixture(
 | 
				
			||||||
 | 
					            test_packaging.Venv('tarball',
 | 
				
			||||||
                                modules=['pip', 'wheel', PBRVERSION],
 | 
					                                modules=['pip', 'wheel', PBRVERSION],
 | 
				
			||||||
                                pip_cmd=PIP_CMD))
 | 
					                                pip_cmd=PIP_CMD))
 | 
				
			||||||
        python = venv.python
 | 
					        python = venv.python
 | 
				
			||||||
@@ -105,7 +106,8 @@ class TestIntegration(base.BaseTestCase):
 | 
				
			|||||||
            path, 'dist', os.listdir(os.path.join(path, 'dist'))[0])
 | 
					            path, 'dist', os.listdir(os.path.join(path, 'dist'))[0])
 | 
				
			||||||
        self.useFixture(base.CapturedSubprocess(
 | 
					        self.useFixture(base.CapturedSubprocess(
 | 
				
			||||||
            'tarball', [python] + PIP_CMD + [filename]))
 | 
					            'tarball', [python] + PIP_CMD + [filename]))
 | 
				
			||||||
        venv = self.useFixture(Venv('install-git',
 | 
					        venv = self.useFixture(
 | 
				
			||||||
 | 
					            test_packaging.Venv('install-git',
 | 
				
			||||||
                                modules=['pip', 'wheel', PBRVERSION],
 | 
					                                modules=['pip', 'wheel', PBRVERSION],
 | 
				
			||||||
                                pip_cmd=PIP_CMD))
 | 
					                                pip_cmd=PIP_CMD))
 | 
				
			||||||
        root = venv.path
 | 
					        root = venv.path
 | 
				
			||||||
@@ -118,7 +120,8 @@ class TestIntegration(base.BaseTestCase):
 | 
				
			|||||||
                if 'migrate.cfg' in filenames:
 | 
					                if 'migrate.cfg' in filenames:
 | 
				
			||||||
                    found = True
 | 
					                    found = True
 | 
				
			||||||
            self.assertTrue(found)
 | 
					            self.assertTrue(found)
 | 
				
			||||||
        venv = self.useFixture(Venv('install-e',
 | 
					        venv = self.useFixture(
 | 
				
			||||||
 | 
					            test_packaging.Venv('install-e',
 | 
				
			||||||
                                modules=['pip', 'wheel', PBRVERSION],
 | 
					                                modules=['pip', 'wheel', PBRVERSION],
 | 
				
			||||||
                                pip_cmd=PIP_CMD))
 | 
					                                pip_cmd=PIP_CMD))
 | 
				
			||||||
        root = venv.path
 | 
					        root = venv.path
 | 
				
			||||||
@@ -167,14 +170,15 @@ class TestInstallWithoutPbr(base.BaseTestCase):
 | 
				
			|||||||
                    print("FakeTest loaded and ran")
 | 
					                    print("FakeTest loaded and ran")
 | 
				
			||||||
                """)},
 | 
					                """)},
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        pkg_dirs = self.useFixture(CreatePackages(pkgs)).package_dirs
 | 
					        pkg_dirs = self.useFixture(
 | 
				
			||||||
 | 
					            test_packaging.CreatePackages(pkgs)).package_dirs
 | 
				
			||||||
        test_pkg_dir = pkg_dirs['pkgTest']
 | 
					        test_pkg_dir = pkg_dirs['pkgTest']
 | 
				
			||||||
        req_pkg_dir = pkg_dirs['pkgReq']
 | 
					        req_pkg_dir = pkg_dirs['pkgReq']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self._run_cmd(sys.executable, ('setup.py', 'sdist', '-d', dist_dir),
 | 
					        self._run_cmd(sys.executable, ('setup.py', 'sdist', '-d', dist_dir),
 | 
				
			||||||
                      allow_fail=False, cwd=req_pkg_dir)
 | 
					                      allow_fail=False, cwd=req_pkg_dir)
 | 
				
			||||||
        # A venv to test within
 | 
					        # A venv to test within
 | 
				
			||||||
        venv = self.useFixture(Venv('nopbr', ['pip', 'wheel']))
 | 
					        venv = self.useFixture(test_packaging.Venv('nopbr', ['pip', 'wheel']))
 | 
				
			||||||
        python = venv.python
 | 
					        python = venv.python
 | 
				
			||||||
        # Run the depending script
 | 
					        # Run the depending script
 | 
				
			||||||
        self.useFixture(base.CapturedSubprocess(
 | 
					        self.useFixture(base.CapturedSubprocess(
 | 
				
			||||||
@@ -205,10 +209,11 @@ class TestMarkersPip(base.BaseTestCase):
 | 
				
			|||||||
            'pkg_a': {},
 | 
					            'pkg_a': {},
 | 
				
			||||||
            'pkg_b': {},
 | 
					            'pkg_b': {},
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        pkg_dirs = self.useFixture(CreatePackages(pkgs)).package_dirs
 | 
					        pkg_dirs = self.useFixture(
 | 
				
			||||||
 | 
					            test_packaging.CreatePackages(pkgs)).package_dirs
 | 
				
			||||||
        temp_dir = self.useFixture(fixtures.TempDir()).path
 | 
					        temp_dir = self.useFixture(fixtures.TempDir()).path
 | 
				
			||||||
        repo_dir = os.path.join(temp_dir, 'repo')
 | 
					        repo_dir = os.path.join(temp_dir, 'repo')
 | 
				
			||||||
        venv = self.useFixture(Venv('markers'))
 | 
					        venv = self.useFixture(test_packaging.Venv('markers'))
 | 
				
			||||||
        bin_python = venv.python
 | 
					        bin_python = venv.python
 | 
				
			||||||
        os.mkdir(repo_dir)
 | 
					        os.mkdir(repo_dir)
 | 
				
			||||||
        for module in self.modules:
 | 
					        for module in self.modules:
 | 
				
			||||||
@@ -254,7 +259,8 @@ class TestLTSSupport(base.BaseTestCase):
 | 
				
			|||||||
        if (sys.version_info[0] == 3 and not self.py3support):
 | 
					        if (sys.version_info[0] == 3 and not self.py3support):
 | 
				
			||||||
            self.skipTest('This combination will not install with py3, '
 | 
					            self.skipTest('This combination will not install with py3, '
 | 
				
			||||||
                          'skipping test')
 | 
					                          'skipping test')
 | 
				
			||||||
        venv = self.useFixture(Venv('setuptools', modules=self.modules))
 | 
					        venv = self.useFixture(
 | 
				
			||||||
 | 
					            test_packaging.Venv('setuptools', modules=self.modules))
 | 
				
			||||||
        bin_python = venv.python
 | 
					        bin_python = venv.python
 | 
				
			||||||
        pbr = 'file://%s#egg=pbr' % PBR_ROOT
 | 
					        pbr = 'file://%s#egg=pbr' % PBR_ROOT
 | 
				
			||||||
        # Installing PBR is a reasonable indication that we are not broken on
 | 
					        # Installing PBR is a reasonable indication that we are not broken on
 | 
				
			||||||
@@ -281,7 +287,7 @@ class TestSphinxWarnErrors(base.BaseTestCase):
 | 
				
			|||||||
        os.environ.get('PBR_INTEGRATION', None) == '1',
 | 
					        os.environ.get('PBR_INTEGRATION', None) == '1',
 | 
				
			||||||
        'integration tests not enabled')
 | 
					        'integration tests not enabled')
 | 
				
			||||||
    def test_sphinx_runs(self):
 | 
					    def test_sphinx_runs(self):
 | 
				
			||||||
        venv = self.useFixture(Venv('sphinx'))
 | 
					        venv = self.useFixture(test_packaging.Venv('sphinx'))
 | 
				
			||||||
        bin_python = venv.python
 | 
					        bin_python = venv.python
 | 
				
			||||||
        self._run_cmd(bin_python, ['-m', 'pip', 'install', self.module],
 | 
					        self._run_cmd(bin_python, ['-m', 'pip', 'install', self.module],
 | 
				
			||||||
                      cwd=venv.path, allow_fail=False)
 | 
					                      cwd=venv.path, allow_fail=False)
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										21
									
								
								pbr/util.py
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								pbr/util.py
									
									
									
									
									
								
							@@ -72,11 +72,10 @@ import distutils.ccompiler
 | 
				
			|||||||
import pkg_resources
 | 
					import pkg_resources
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from distutils import log
 | 
					from distutils import log
 | 
				
			||||||
from distutils.errors import (DistutilsOptionError, DistutilsModuleError,
 | 
					from distutils import errors
 | 
				
			||||||
                              DistutilsFileError)
 | 
					 | 
				
			||||||
from setuptools.command.egg_info import manifest_maker
 | 
					from setuptools.command.egg_info import manifest_maker
 | 
				
			||||||
from setuptools.dist import Distribution
 | 
					from setuptools import dist as st_dist
 | 
				
			||||||
from setuptools.extension import Extension
 | 
					from setuptools import extension
 | 
				
			||||||
 | 
					
 | 
				
			||||||
try:
 | 
					try:
 | 
				
			||||||
    import ConfigParser as configparser
 | 
					    import ConfigParser as configparser
 | 
				
			||||||
@@ -208,7 +207,7 @@ def cfg_to_args(path='setup.cfg', script_args=()):
 | 
				
			|||||||
    else:
 | 
					    else:
 | 
				
			||||||
            parser = configparser.SafeConfigParser()
 | 
					            parser = configparser.SafeConfigParser()
 | 
				
			||||||
    if not os.path.exists(path):
 | 
					    if not os.path.exists(path):
 | 
				
			||||||
        raise DistutilsFileError("file '%s' does not exist" %
 | 
					        raise errors.DistutilsFileError("file '%s' does not exist" %
 | 
				
			||||||
                                        os.path.abspath(path))
 | 
					                                        os.path.abspath(path))
 | 
				
			||||||
    parser.read(path)
 | 
					    parser.read(path)
 | 
				
			||||||
    config = {}
 | 
					    config = {}
 | 
				
			||||||
@@ -367,7 +366,7 @@ def setup_cfg_to_setup_kwargs(config, script_args=()):
 | 
				
			|||||||
                        else:
 | 
					                        else:
 | 
				
			||||||
                            prev = data_files[key.strip()] = value.split()
 | 
					                            prev = data_files[key.strip()] = value.split()
 | 
				
			||||||
                    elif firstline:
 | 
					                    elif firstline:
 | 
				
			||||||
                        raise DistutilsOptionError(
 | 
					                        raise errors.DistutilsOptionError(
 | 
				
			||||||
                            'malformed package_data first line %r (misses '
 | 
					                            'malformed package_data first line %r (misses '
 | 
				
			||||||
                            '"=")' % line)
 | 
					                            '"=")' % line)
 | 
				
			||||||
                    else:
 | 
					                    else:
 | 
				
			||||||
@@ -380,7 +379,7 @@ def setup_cfg_to_setup_kwargs(config, script_args=()):
 | 
				
			|||||||
                in_cfg_value = data_files
 | 
					                in_cfg_value = data_files
 | 
				
			||||||
            elif arg == 'cmdclass':
 | 
					            elif arg == 'cmdclass':
 | 
				
			||||||
                cmdclass = {}
 | 
					                cmdclass = {}
 | 
				
			||||||
                dist = Distribution()
 | 
					                dist = st_dist.Distribution()
 | 
				
			||||||
                for cls_name in in_cfg_value:
 | 
					                for cls_name in in_cfg_value:
 | 
				
			||||||
                    cls = resolve_name(cls_name)
 | 
					                    cls = resolve_name(cls_name)
 | 
				
			||||||
                    cmd = cls(dist)
 | 
					                    cmd = cls(dist)
 | 
				
			||||||
@@ -534,7 +533,7 @@ def get_extension_modules(config):
 | 
				
			|||||||
            if ext_args:
 | 
					            if ext_args:
 | 
				
			||||||
                if 'name' not in ext_args:
 | 
					                if 'name' not in ext_args:
 | 
				
			||||||
                    ext_args['name'] = labels[1]
 | 
					                    ext_args['name'] = labels[1]
 | 
				
			||||||
                ext_modules.append(Extension(ext_args.pop('name'),
 | 
					                ext_modules.append(extension.Extension(ext_args.pop('name'),
 | 
				
			||||||
                                                       **ext_args))
 | 
					                                                       **ext_args))
 | 
				
			||||||
    return ext_modules
 | 
					    return ext_modules
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -554,7 +553,7 @@ def get_entry_points(config):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def wrap_commands(kwargs):
 | 
					def wrap_commands(kwargs):
 | 
				
			||||||
    dist = Distribution()
 | 
					    dist = st_dist.Distribution()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # This should suffice to get the same config values and command classes
 | 
					    # This should suffice to get the same config values and command classes
 | 
				
			||||||
    # that the actual Distribution will see (not counting cmdclass, which is
 | 
					    # that the actual Distribution will see (not counting cmdclass, which is
 | 
				
			||||||
@@ -630,13 +629,13 @@ def run_command_hooks(cmd_obj, hook_kind):
 | 
				
			|||||||
                hook_obj = resolve_name(hook)
 | 
					                hook_obj = resolve_name(hook)
 | 
				
			||||||
            except ImportError:
 | 
					            except ImportError:
 | 
				
			||||||
                err = sys.exc_info()[1] # For py3k
 | 
					                err = sys.exc_info()[1] # For py3k
 | 
				
			||||||
                raise DistutilsModuleError('cannot find hook %s: %s' %
 | 
					                raise errors.DistutilsModuleError('cannot find hook %s: %s' %
 | 
				
			||||||
                                                  (hook,err))
 | 
					                                                  (hook,err))
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            hook_obj = hook
 | 
					            hook_obj = hook
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if not hasattr(hook_obj, '__call__'):
 | 
					        if not hasattr(hook_obj, '__call__'):
 | 
				
			||||||
            raise DistutilsOptionError('hook %r is not callable' % hook)
 | 
					            raise errors.DistutilsOptionError('hook %r is not callable' % hook)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        log.info('running %s %s for command %s',
 | 
					        log.info('running %s %s for command %s',
 | 
				
			||||||
                 hook_kind, hook, cmd_obj.get_command_name())
 | 
					                 hook_kind, hook, cmd_obj.get_command_name())
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user