diff --git a/setuptools/tests/test_easy_install.py b/setuptools/tests/test_easy_install.py index bca86066ad..b3bf64dc9c 100644 --- a/setuptools/tests/test_easy_install.py +++ b/setuptools/tests/test_easy_install.py @@ -28,7 +28,9 @@ from setuptools.sandbox import run_setup import setuptools.command.easy_install as ei from setuptools.command.easy_install import ( - EasyInstallDeprecationWarning, ScriptWriter, PthDistributions, + EasyInstallDeprecationWarning, + ScriptWriter, + PthDistributions, WindowsScriptWriter, ) from setuptools.dist import Distribution @@ -62,11 +64,13 @@ def as_requirement(self): return 'spec' -SETUP_PY = DALS(""" +SETUP_PY = DALS( + """ from setuptools import setup setup() - """) + """ +) class TestEasyInstallTest: @@ -79,8 +83,7 @@ def test_get_script_args(self): assert "'spec'" in script assert "'console_scripts'" in script assert "'name'" in script - assert re.search( - '^# EASY-INSTALL-ENTRY-SCRIPT', script, flags=re.MULTILINE) + assert re.search('^# EASY-INSTALL-ENTRY-SCRIPT', script, flags=re.MULTILINE) def test_no_find_links(self): # new option '--no-find-links', that blocks find-links added at @@ -124,6 +127,7 @@ def test_all_site_dirs(self, monkeypatch): def mock_gsp(): return [path] + monkeypatch.setattr(site, 'getsitepackages', mock_gsp, raising=False) assert path in ei.get_site_dirs() @@ -136,7 +140,8 @@ def sdist_unicode(self, tmpdir): files = [ ( 'setup.py', - DALS(""" + DALS( + """ import setuptools setuptools.setup( name="setuptools-test-unicode", @@ -144,7 +149,8 @@ def sdist_unicode(self, tmpdir): packages=["mypkg"], include_package_data=True, ) - """), + """ + ), ), ( 'mypkg/__init__.py', @@ -166,8 +172,7 @@ def sdist_unicode(self, tmpdir): return str(sdist) @fail_on_ascii - def test_unicode_filename_in_sdist( - self, sdist_unicode, tmpdir, monkeypatch): + def test_unicode_filename_in_sdist(self, sdist_unicode, tmpdir, monkeypatch): """ The install command should execute correctly even if the package has unicode filenames. @@ -188,7 +193,8 @@ def sdist_unicode_in_script(self, tmpdir): files = [ ( "setup.py", - DALS(""" + DALS( + """ import setuptools setuptools.setup( name="setuptools-test-unicode", @@ -197,7 +203,8 @@ def sdist_unicode_in_script(self, tmpdir): include_package_data=True, scripts=['mypkg/unicode_in_script'], ) - """), + """ + ), ), ("mypkg/__init__.py", ""), ( @@ -209,7 +216,8 @@ def sdist_unicode_in_script(self, tmpdir): non_python_fn() { } - """), + """ + ), ), ] sdist_name = "setuptools-test-unicode-script-1.0.zip" @@ -224,7 +232,8 @@ def sdist_unicode_in_script(self, tmpdir): @fail_on_ascii def test_unicode_content_in_sdist( - self, sdist_unicode_in_script, tmpdir, monkeypatch): + self, sdist_unicode_in_script, tmpdir, monkeypatch + ): """ The install command should execute correctly even if the package has unicode in scripts. @@ -241,21 +250,25 @@ def sdist_script(self, tmpdir): files = [ ( 'setup.py', - DALS(""" + DALS( + """ import setuptools setuptools.setup( name="setuptools-test-script", version="1.0", scripts=["mypkg_script"], ) - """), + """ + ), ), ( 'mypkg_script', - DALS(""" + DALS( + """ #/usr/bin/python print('mypkg_script') - """), + """ + ), ), ] sdist_name = 'setuptools-test-script-1.0.zip' @@ -263,8 +276,9 @@ def sdist_script(self, tmpdir): make_sdist(sdist, files) return sdist - @pytest.mark.skipif(not sys.platform.startswith('linux'), - reason="Test can only be run on Linux") + @pytest.mark.skipif( + not sys.platform.startswith('linux'), reason="Test can only be run on Linux" + ) def test_script_install(self, sdist_script, tmpdir, monkeypatch): """ Check scripts are installed. @@ -313,7 +327,12 @@ 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, ]) + pth = PthDistributions( + 'does-not_exist', + [ + location, + ], + ) assert not pth.dirty pth.add(PRDistribution(location)) assert not pth.dirty @@ -330,7 +349,6 @@ def setup_context(tmpdir): @pytest.mark.usefixtures("user_override") @pytest.mark.usefixtures("setup_context") class TestUserInstallTest: - # prevent check that site-packages is writable. easy_install # shouldn't be writing to system site-packages during finalize # options, but while it does, bypass the behavior. @@ -408,6 +426,7 @@ def user_install_setup_context(self, *args, **kwargs): """ with self.orig_context(*args, **kwargs): import setuptools.command.easy_install as ei + ei.__file__ = site.USER_SITE yield @@ -464,15 +483,23 @@ def test_setup_install_includes_dependencies(self, tmp_path, mock_index): self.create_project(project_root) cmd = [ sys.executable, - '-c', '__import__("setuptools").setup()', + '-c', + '__import__("setuptools").setup()', 'install', - '--install-base', str(install_root), - '--install-lib', str(install_root), - '--install-headers', str(install_root), - '--install-scripts', str(install_root), - '--install-data', str(install_root), - '--install-purelib', str(install_root), - '--install-platlib', str(install_root), + '--install-base', + str(install_root), + '--install-lib', + str(install_root), + '--install-headers', + str(install_root), + '--install-scripts', + str(install_root), + '--install-data', + str(install_root), + '--install-purelib', + str(install_root), + '--install-platlib', + str(install_root), ] env = {**os.environ, "__EASYINSTALL_INDEX": mock_index.url} cp = subprocess.run( @@ -512,7 +539,6 @@ def create_project(self, root): class TestSetupRequires: - def test_setup_requires_honors_fetch_params(self, mock_index, monkeypatch): """ When easy_install installs a source distribution which specifies @@ -529,11 +555,14 @@ def test_setup_requires_honors_fetch_params(self, mock_index, monkeypatch): with contexts.environment(PYTHONPATH=temp_install_dir): cmd = [ sys.executable, - '-c', '__import__("setuptools").setup()', + '-c', + '__import__("setuptools").setup()', 'easy_install', - '--index-url', mock_index.url, + '--index-url', + mock_index.url, '--exclude-scripts', - '--install-dir', temp_install_dir, + '--install-dir', + temp_install_dir, dist_file, ] subprocess.Popen(cmd).wait() @@ -549,17 +578,25 @@ def create_sdist(): """ with contexts.tempdir() as dir: dist_path = os.path.join(dir, 'setuptools-test-fetcher-1.0.tar.gz') - make_sdist(dist_path, [ - ('setup.py', DALS(""" + make_sdist( + dist_path, + [ + ( + 'setup.py', + DALS( + """ import setuptools setuptools.setup( name="setuptools-test-fetcher", version="1.0", setup_requires = ['does-not-exist'], ) - """)), - ('setup.cfg', ''), - ]) + """ + ), + ), + ('setup.cfg', ''), + ], + ) yield dist_path use_setup_cfg = ( @@ -580,14 +617,16 @@ def test_setup_requires_overrides_version_conflict(self, use_setup_cfg): requirement is already on the path. """ - fake_dist = PRDistribution('does-not-matter', project_name='foobar', - version='0.0') + 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) + 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 @@ -618,11 +657,13 @@ def test_setup_requires_override_nspkg(self, use_setup_cfg): tf.extractall(foobar_1_dir) sys.path.insert(1, foobar_1_dir) - dist = PRDistribution(foobar_1_dir, project_name='foo.bar', - version='0.1') + dist = PRDistribution( + foobar_1_dir, project_name='foo.bar', version='0.1' + ) working_set.add(dist) - template = DALS("""\ + template = DALS( + """\ import foo # Even with foo imported first the # setup_requires package should override import setuptools @@ -634,11 +675,17 @@ def test_setup_requires_override_nspkg(self, use_setup_cfg): 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) + 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') @@ -650,7 +697,8 @@ def test_setup_requires_override_nspkg(self, use_setup_cfg): except pkg_resources.VersionConflict: self.fail( 'Installing setup.py requirements ' - 'caused a VersionConflict') + 'caused a VersionConflict' + ) assert 'FAIL' not in stdout.getvalue() lines = stdout.readlines() @@ -660,27 +708,38 @@ def test_setup_requires_override_nspkg(self, use_setup_cfg): @pytest.mark.parametrize('use_setup_cfg', use_setup_cfg) def test_setup_requires_with_attr_version(self, use_setup_cfg): def make_dependency_sdist(dist_path, distname, version): - files = [( - 'setup.py', - DALS(""" + files = [ + ( + 'setup.py', + DALS( + """ import setuptools setuptools.setup( name={name!r}, version={version!r}, py_modules=[{name!r}], ) - """.format(name=distname, version=version)), - ), ( - distname + '.py', - DALS(""" + """.format( + name=distname, version=version + ) + ), + ), + ( + distname + '.py', + DALS( + """ version = 42 - """), - )] + """ + ), + ), + ] make_sdist(dist_path, files) + with contexts.save_pkg_resources_state(): with contexts.tempdir() as temp_dir: test_pkg = create_setup_requires_package( - temp_dir, setup_attrs=dict(version='attr: foobar.version'), + temp_dir, + setup_attrs=dict(version='attr: foobar.version'), make_package=make_dependency_sdist, use_setup_cfg=use_setup_cfg + ('version',), ) @@ -699,15 +758,21 @@ def test_setup_requires_honors_pip_env(self, mock_index, monkeypatch): with contexts.save_pkg_resources_state(): with contexts.tempdir() as temp_dir: test_pkg = create_setup_requires_package( - temp_dir, 'python-xlib', '0.19', - setup_attrs=dict(dependency_links=[])) + temp_dir, + 'python-xlib', + '0.19', + setup_attrs=dict(dependency_links=[]), + ) test_setup_cfg = os.path.join(test_pkg, 'setup.cfg') with open(test_setup_cfg, 'w') as fp: - fp.write(DALS( - ''' + fp.write( + DALS( + ''' [easy_install] index_url = https://pypi.org/legacy/ - ''')) + ''' + ) + ) test_setup_py = os.path.join(test_pkg, 'setup.py') with pytest.raises(distutils.errors.DistutilsError): run_setup(test_setup_py, [str('--version')]) @@ -726,25 +791,30 @@ def test_setup_requires_with_pep508_url(self, mock_index, monkeypatch): test_pkg = create_setup_requires_package( temp_dir, # Ignored (overridden by setup_attrs) - 'python-xlib', '0.19', - setup_attrs=dict( - setup_requires='dependency @ %s' % dep_url)) + 'python-xlib', + '0.19', + setup_attrs=dict(setup_requires='dependency @ %s' % dep_url), + ) test_setup_py = os.path.join(test_pkg, 'setup.py') run_setup(test_setup_py, [str('--version')]) assert len(mock_index.requests) == 0 def test_setup_requires_with_allow_hosts(self, mock_index): - ''' The `allow-hosts` option in not supported anymore. ''' + '''The `allow-hosts` option in not supported anymore.''' files = { 'test_pkg': { - 'setup.py': DALS(''' + 'setup.py': DALS( + ''' from setuptools import setup setup(setup_requires='python-xlib') - '''), - 'setup.cfg': DALS(''' + ''' + ), + 'setup.cfg': DALS( + ''' [easy_install] allow_hosts = * - '''), + ''' + ), } } with contexts.save_pkg_resources_state(): @@ -756,7 +826,7 @@ def test_setup_requires_with_allow_hosts(self, mock_index): assert len(mock_index.requests) == 0 def test_setup_requires_with_python_requires(self, monkeypatch, tmpdir): - ''' Check `python_requires` is honored. ''' + '''Check `python_requires` is honored.''' monkeypatch.setenv(str('PIP_RETRIES'), str('0')) monkeypatch.setenv(str('PIP_TIMEOUT'), str('0')) monkeypatch.setenv(str('PIP_NO_INDEX'), str('1')) @@ -765,16 +835,18 @@ def test_setup_requires_with_python_requires(self, monkeypatch, tmpdir): dep_1_0_url = path_to_url(str(tmpdir / dep_1_0_sdist)) dep_1_0_python_requires = '>=2.7' make_python_requires_sdist( - str(tmpdir / dep_1_0_sdist), 'dep', '1.0', dep_1_0_python_requires) + str(tmpdir / dep_1_0_sdist), 'dep', '1.0', dep_1_0_python_requires + ) dep_2_0_sdist = 'dep-2.0.tar.gz' dep_2_0_url = path_to_url(str(tmpdir / dep_2_0_sdist)) - dep_2_0_python_requires = '!=' + '.'.join( - map(str, sys.version_info[:2])) + '.*' + dep_2_0_python_requires = '!=' + '.'.join(map(str, sys.version_info[:2])) + '.*' make_python_requires_sdist( - str(tmpdir / dep_2_0_sdist), 'dep', '2.0', dep_2_0_python_requires) + str(tmpdir / dep_2_0_sdist), 'dep', '2.0', dep_2_0_python_requires + ) index = tmpdir / 'index.html' - index.write_text(DALS( - ''' + index.write_text( + DALS( + '''