diff --git a/docs/pip_sphinxext.py b/docs/pip_sphinxext.py index a0e69c6e4c2..3336bd50993 100644 --- a/docs/pip_sphinxext.py +++ b/docs/pip_sphinxext.py @@ -42,15 +42,16 @@ def run(self): class PipOptions(rst.Directive): def _format_option(self, option, cmd_name=None): - if cmd_name: - bookmark_line = ".. _`%s_%s`:" % (cmd_name, option._long_opts[0]) - else: - bookmark_line = ".. _`%s`:" % option._long_opts[0] + bookmark_line = ( + ".. _`{cmd_name}_{option.long_opts[0]}`:" + if cmd_name else + ".. _`{option.long_opts[0]}`:" + ).format(**locals()) line = ".. option:: " if option._short_opts: line += option._short_opts[0] if option._short_opts and option._long_opts: - line += ", %s" % option._long_opts[0] + line += ", " + option._long_opts[0] elif option._long_opts: line += option._long_opts[0] if option.takes_value(): @@ -60,7 +61,7 @@ def _format_option(self, option, cmd_name=None): opt_help = option.help.replace('%default', str(option.default)) # fix paths with sys.prefix opt_help = opt_help.replace(sys.prefix, "") - return [bookmark_line, "", line, "", " %s" % opt_help, ""] + return [bookmark_line, "", line, "", " " + opt_help, ""] def _format_options(self, options, cmd_name=None): for option in options: diff --git a/src/pip/_internal/cli/main_parser.py b/src/pip/_internal/cli/main_parser.py index 4871956c9de..08c82c1f711 100644 --- a/src/pip/_internal/cli/main_parser.py +++ b/src/pip/_internal/cli/main_parser.py @@ -48,7 +48,7 @@ def create_main_parser(): # create command listing for description description = [''] + [ - '%-27s %s' % (name, command_info.summary) + '{name:27} {command_info.summary}'.format(**locals()) for name, command_info in commands_dict.items() ] parser.description = '\n'.join(description) diff --git a/src/pip/_internal/cli/parser.py b/src/pip/_internal/cli/parser.py index e799215bef1..04e00b72132 100644 --- a/src/pip/_internal/cli/parser.py +++ b/src/pip/_internal/cli/parser.py @@ -31,14 +31,14 @@ def __init__(self, *args, **kwargs): optparse.IndentedHelpFormatter.__init__(self, *args, **kwargs) def format_option_strings(self, option): - return self._format_option_strings(option, ' <%s>', ', ') + return self._format_option_strings(option) def _format_option_strings(self, option, mvarfmt=' <{}>', optsep=', '): """ Return a comma-separated list of option strings and metavars. :param option: tuple of (short opt, long opt), e.g: ('-f', '--format') - :param mvarfmt: metavar format string - evaluated as mvarfmt % metavar + :param mvarfmt: metavar format string :param optsep: separator """ opts = [] diff --git a/src/pip/_internal/cli/progress_bars.py b/src/pip/_internal/cli/progress_bars.py index 7ed224790cf..94e753bd666 100644 --- a/src/pip/_internal/cli/progress_bars.py +++ b/src/pip/_internal/cli/progress_bars.py @@ -124,7 +124,7 @@ def update(self): class BlueEmojiBar(IncrementalBar): - suffix = "%(percent)d%%" + suffix = "{percent}%" bar_prefix = " " bar_suffix = " " phases = (u"\U0001F539", u"\U0001F537", u"\U0001F535") # type: Any @@ -203,8 +203,8 @@ class BaseDownloadProgressBar(WindowsMixin, InterruptibleMixin, DownloadProgressMixin): file = sys.stdout - message = "%(percent)d%%" - suffix = "%(downloaded)s %(download_speed)s %(pretty_eta)s" + message = "{percent}%" + suffix = "{downloaded} {download_speed} {pretty_eta}" # NOTE: The "type: ignore" comments on the following classes are there to # work around https://github.com/python/typing/issues/241 @@ -238,7 +238,7 @@ class DownloadProgressSpinner(WindowsMixin, InterruptibleMixin, DownloadProgressMixin, Spinner): file = sys.stdout - suffix = "%(downloaded)s %(download_speed)s" + suffix = "{downloaded} {download_speed}" def next_phase(self): # type: ignore if not hasattr(self, "_phaser"): @@ -247,17 +247,10 @@ def next_phase(self): # type: ignore def update(self): # type: () -> None - message = self.message % self + message = self.message.format(vars(self)) phase = self.next_phase() - suffix = self.suffix % self - line = ''.join([ - message, - " " if message else "", - phase, - " " if suffix else "", - suffix, - ]) - + suffix = self.suffix.format(vars(self)) + line = " ".join(filter(None, (message, phase, suffix))) self.writeln(line) diff --git a/src/pip/_internal/cli/req_command.py b/src/pip/_internal/cli/req_command.py index 21770df62e2..db7b3138a58 100644 --- a/src/pip/_internal/cli/req_command.py +++ b/src/pip/_internal/cli/req_command.py @@ -342,13 +342,13 @@ def get_requirements( opts = {'name': self.name} if options.find_links: raise CommandError( - 'You must give at least one requirement to %(name)s ' - '(maybe you meant "pip %(name)s %(links)s"?)' % - dict(opts, links=' '.join(options.find_links))) + 'You must give at least one requirement to {name} ' + '(maybe you meant "pip {name} {links}"?)'.format( + **dict(opts, links=' '.join(options.find_links)))) else: raise CommandError( - 'You must give at least one requirement to %(name)s ' - '(see "pip help %(name)s")' % opts) + 'You must give at least one requirement to {name} ' + '(see "pip help {name}")'.format(**opts)) return requirements diff --git a/src/pip/_internal/cli/spinners.py b/src/pip/_internal/cli/spinners.py index 3d152a80742..8e8e44eeb5c 100644 --- a/src/pip/_internal/cli/spinners.py +++ b/src/pip/_internal/cli/spinners.py @@ -106,7 +106,7 @@ def finish(self, final_status): # type: (str) -> None if self._finished: return - self._update("finished with status '%s'" % (final_status,)) + self._update("finished with status '{final_status}'".format(**locals())) self._finished = True diff --git a/src/pip/_internal/commands/completion.py b/src/pip/_internal/commands/completion.py index e0b743e542f..d3469131090 100644 --- a/src/pip/_internal/commands/completion.py +++ b/src/pip/_internal/commands/completion.py @@ -10,7 +10,7 @@ from pip._internal.utils.misc import get_prog BASE_COMPLETION = """ -# pip %(shell)s completion start%(script)s# pip %(shell)s completion end +# pip {shell} completion start{script}# pip {shell} completion end """ COMPLETION_SCRIPTS = { @@ -21,7 +21,7 @@ COMP_CWORD=$COMP_CWORD \\ PIP_AUTO_COMPLETE=1 $1 2>/dev/null ) ) } - complete -o default -F _pip_completion %(prog)s + complete -o default -F _pip_completion {prog} """, 'zsh': """ function _pip_completion { @@ -32,7 +32,7 @@ COMP_CWORD=$(( cword-1 )) \\ PIP_AUTO_COMPLETE=1 $words[1] 2>/dev/null )) } - compctl -K _pip_completion %(prog)s + compctl -K _pip_completion {prog} """, 'fish': """ function __fish_complete_pip @@ -43,7 +43,7 @@ set -lx PIP_AUTO_COMPLETE 1 string split \\ -- (eval $COMP_WORDS[1]) end - complete -fa "(__fish_complete_pip)" -c %(prog)s + complete -fa "(__fish_complete_pip)" -c {prog} """, } @@ -85,11 +85,9 @@ def run(self, options, args): shell_options = ['--' + shell for shell in sorted(shells)] if options.shell in shells: script = textwrap.dedent( - COMPLETION_SCRIPTS.get(options.shell, '') % { - 'prog': get_prog(), - } + COMPLETION_SCRIPTS.get(options.shell, '').format(prog=get_prog()) ) - print(BASE_COMPLETION % {'script': script, 'shell': options.shell}) + print(BASE_COMPLETION.format(script=script, shell=options.shell)) else: sys.stderr.write( 'ERROR: You must pass {}\n' .format(' or '.join(shell_options)) diff --git a/src/pip/_internal/commands/search.py b/src/pip/_internal/commands/search.py index 2e880eec224..276379ca640 100644 --- a/src/pip/_internal/commands/search.py +++ b/src/pip/_internal/commands/search.py @@ -121,8 +121,9 @@ def print_results(hits, name_column_width=None, terminal_width=None): summary = textwrap.wrap(summary, target_width) summary = ('\n' + ' ' * (name_column_width + 3)).join(summary) - line = '%-*s - %s' % (name_column_width, - '%s (%s)' % (name, latest), summary) + line = '{name_latest:{name_column_width}} - {summary}'.format( + name_latest='{name} ({latest})'.format(**locals()), + **locals) try: write_output(line) if name in installed_packages: diff --git a/src/pip/_internal/commands/uninstall.py b/src/pip/_internal/commands/uninstall.py index e93ad74e29e..5db4fb46721 100644 --- a/src/pip/_internal/commands/uninstall.py +++ b/src/pip/_internal/commands/uninstall.py @@ -73,8 +73,8 @@ def run(self, options, args): reqs_to_uninstall[canonicalize_name(req.name)] = req if not reqs_to_uninstall: raise InstallationError( - 'You must give at least one requirement to %(name)s (see ' - '"pip help %(name)s")' % dict(name=self.name) + 'You must give at least one requirement to {self.name} (see ' + '"pip help {self.name}")'.format(**locals()) ) protect_pip_from_modification_on_windows( diff --git a/src/pip/_internal/models/link.py b/src/pip/_internal/models/link.py index 0b30ab2511a..ed057de196b 100644 --- a/src/pip/_internal/models/link.py +++ b/src/pip/_internal/models/link.py @@ -96,7 +96,7 @@ def filename(self): return netloc name = urllib_parse.unquote(name) - assert name, ('URL %r produced no filename' % self._url) + assert name, ('URL {self._url!r} produced no filename'.format(**locals())) return name @property diff --git a/src/pip/_internal/operations/install/wheel.py b/src/pip/_internal/operations/install/wheel.py index b1a76a24ce2..6184499bdd2 100644 --- a/src/pip/_internal/operations/install/wheel.py +++ b/src/pip/_internal/operations/install/wheel.py @@ -534,13 +534,9 @@ def is_entrypoint_wrapper(name): del console[k] # Generate the console and GUI entry points specified in the wheel - scripts_to_generate.extend( - '%s = %s' % kv for kv in console.items() - ) + scripts_to_generate.extend(map('{} = {}'.format, console.items())) - gui_scripts_to_generate = [ - '%s = %s' % kv for kv in gui.items() - ] + gui_scripts_to_generate = list(map('{} = {}'.format, gui.items())) generated_console_scripts = [] # type: List[str] diff --git a/src/pip/_internal/req/constructors.py b/src/pip/_internal/req/constructors.py index 395157c4be6..195b0d0be78 100644 --- a/src/pip/_internal/req/constructors.py +++ b/src/pip/_internal/req/constructors.py @@ -281,8 +281,8 @@ def _get_url_from_path(path, name): if is_installable_dir(path): return path_to_url(path) raise InstallationError( - "Directory %r is not installable. Neither 'setup.py' " - "nor 'pyproject.toml' found." % name + "Directory {name!r} is not installable. Neither 'setup.py' " + "nor 'pyproject.toml' found.".format(**locals()) ) if not is_archive_file(path): return None @@ -339,7 +339,7 @@ def parse_req_from_line(name, line_source): # wheel file if link.is_wheel: wheel = Wheel(link.filename) # can raise InvalidWheelFilename - req_as_string = "%s==%s" % (wheel.name, wheel.version) + req_as_string = "{wheel.name}=={wheel.version}".format(**locals()) else: # set the req to the egg fragment. when it's not there, this # will become an 'unnamed' requirement diff --git a/src/pip/_internal/req/req_install.py b/src/pip/_internal/req/req_install.py index 5926a17de89..ce0309932cb 100644 --- a/src/pip/_internal/req/req_install.py +++ b/src/pip/_internal/req/req_install.py @@ -639,7 +639,7 @@ def update_editable(self, obtain=True): if self.link.scheme == 'file': # Static paths don't get updated return - assert '+' in self.link.url, "bad url: %r" % self.link.url + assert '+' in self.link.url, "bad url: {self.link.url!r}".format(**locals()) vc_type, url = self.link.url.split('+', 1) vcs_backend = vcs.get_backend(vc_type) if vcs_backend: @@ -701,7 +701,8 @@ def _get_archive_name(self, path, parentdir, rootdir): def _clean_zip_name(name, prefix): # type: (str, str) -> str assert name.startswith(prefix + os.path.sep), ( - "name %r doesn't start with prefix %r" % (name, prefix) + "name {name!r} doesn't start with prefix {prefix!r}" + .format(**locals()) ) name = name[len(prefix) + 1:] name = name.replace(os.path.sep, '/') diff --git a/src/pip/_internal/req/req_set.py b/src/pip/_internal/req/req_set.py index dc76cce9b30..bc8e32264a3 100644 --- a/src/pip/_internal/req/req_set.py +++ b/src/pip/_internal/req/req_set.py @@ -194,7 +194,7 @@ def get_requirement(self, name): if project_name in self.requirements: return self.requirements[project_name] - raise KeyError("No project with the name %r" % name) + raise KeyError("No project with the name {name!r}".format(**locals())) @property def all_requirements(self): diff --git a/src/pip/_internal/utils/compat.py b/src/pip/_internal/utils/compat.py index 08c292d189d..d939e21fe2a 100644 --- a/src/pip/_internal/utils/compat.py +++ b/src/pip/_internal/utils/compat.py @@ -64,7 +64,7 @@ def backslashreplace_decode_fn(err): raw_bytes = (err.object[i] for i in range(err.start, err.end)) # Python 2 gave us characters - convert to numeric bytes raw_bytes = (ord(b) for b in raw_bytes) - return u"".join(u"\\x%x" % c for c in raw_bytes), err.end + return u"".join(map(u"\\x{:x}".format, raw_bytes)), err.end codecs.register_error( "backslashreplace_decode", backslashreplace_decode_fn, diff --git a/src/pip/_internal/utils/filesystem.py b/src/pip/_internal/utils/filesystem.py index 6f1537e4032..a0866779719 100644 --- a/src/pip/_internal/utils/filesystem.py +++ b/src/pip/_internal/utils/filesystem.py @@ -73,7 +73,7 @@ def copy2_fixed(src, dest): pass else: if is_socket_file: - raise shutil.SpecialFileError("`%s` is a socket" % f) + raise shutil.SpecialFileError("`{f}` is a socket".format(**locals())) raise diff --git a/src/pip/_internal/utils/logging.py b/src/pip/_internal/utils/logging.py index 7767111a6ba..54ff956a38f 100644 --- a/src/pip/_internal/utils/logging.py +++ b/src/pip/_internal/utils/logging.py @@ -156,7 +156,7 @@ def format(self, record): if self.add_timestamp: # TODO: Use Formatter.default_time_format after dropping PY2. t = self.formatTime(record, "%Y-%m-%dT%H:%M:%S") - prefix = '%s,%03d ' % (t, record.msecs) + prefix = '{t},{record.msecs:03} '.format(**locals()) prefix += " " * get_indentation() formatted = "".join([ prefix + line diff --git a/src/pip/_internal/utils/misc.py b/src/pip/_internal/utils/misc.py index 5ad0544be79..ae3561fa8cc 100644 --- a/src/pip/_internal/utils/misc.py +++ b/src/pip/_internal/utils/misc.py @@ -266,13 +266,13 @@ def ask_password(message): def format_size(bytes): # type: (float) -> str if bytes > 1000 * 1000: - return '%.1f MB' % (bytes / 1000.0 / 1000) + return '{:.1} MB'.format(bytes / 1000.0 / 1000) elif bytes > 10 * 1000: - return '%i kB' % (bytes / 1000) + return '{} kB'.format(int(bytes / 1000)) elif bytes > 1000: - return '%.1f kB' % (bytes / 1000.0) + return '{:.1} kB'.format(bytes / 1000.0) else: - return '%i bytes' % bytes + return '{} bytes'.format(int(bytes)) def is_installable_dir(path): diff --git a/src/pip/_internal/utils/urls.py b/src/pip/_internal/utils/urls.py index 9ad40feb345..a3dcc83b527 100644 --- a/src/pip/_internal/utils/urls.py +++ b/src/pip/_internal/utils/urls.py @@ -34,7 +34,7 @@ def url_to_path(url): Convert a file: URL to a path. """ assert url.startswith('file:'), ( - "You can only turn file: urls into filenames (not %r)" % url) + "You can only turn file: urls into filenames (not {url!r})".format(**locals())) _, netloc, path, _, _ = urllib_parse.urlsplit(url) @@ -46,8 +46,8 @@ def url_to_path(url): netloc = '\\\\' + netloc else: raise ValueError( - 'non-local file URIs are not supported on this platform: %r' - % url + 'non-local file URIs are not supported on this platform: {url!r}' + .format(**locals()) ) path = urllib_request.url2pathname(netloc + path) diff --git a/src/pip/_internal/vcs/subversion.py b/src/pip/_internal/vcs/subversion.py index 6c76d1ad435..064fb77e50e 100644 --- a/src/pip/_internal/vcs/subversion.py +++ b/src/pip/_internal/vcs/subversion.py @@ -151,7 +151,7 @@ def _get_svn_url_rev(cls, location): elif data.startswith('=40.8.0.' % path_to_url(project_dir)) in result.stderr + 'setuptools>=40.8.0.'.format(url=path_to_url(project_dir))) in result.stderr ), str(result) @@ -198,12 +198,12 @@ def test_pip_second_command_line_interface_works( if pyversion_tuple < (2, 7, 9): kwargs['expect_stderr'] = True - args = ['pip%s' % pyversion] + args = ['pip{version}'.format(**locals())] args.extend(['install', 'INITools==0.2']) args.extend(['-f', data.packages]) result = script.run(*args, **kwargs) egg_info_folder = ( - script.site_packages / 'INITools-0.2-py%s.egg-info' % pyversion + script.site_packages / 'INITools-0.2-py{pyversion}.egg-info'.format(**locals()) ) initools_folder = script.site_packages / 'initools' assert egg_info_folder in result.files_created, str(result) @@ -234,7 +234,7 @@ def test_basic_install_from_pypi(script): """ result = script.pip('install', 'INITools==0.2') egg_info_folder = ( - script.site_packages / 'INITools-0.2-py%s.egg-info' % pyversion + script.site_packages / 'INITools-0.2-py{pyversion}.egg-info'.format(**locals()) ) initools_folder = script.site_packages / 'initools' assert egg_info_folder in result.files_created, str(result) @@ -281,7 +281,7 @@ def test_basic_install_editable_from_svn(script): def _test_install_editable_from_git(script, tmpdir): """Test cloning from Git.""" pkg_path = _create_test_package(script, name='testpackage', vcs='git') - args = ['install', '-e', 'git+%s#egg=testpackage' % path_to_url(pkg_path)] + args = ['install', '-e', 'git+{url}#egg=testpackage'.format(url=path_to_url(pkg_path))] result = script.pip(*args) result.assert_installed('testpackage', with_files=['.git']) @@ -310,10 +310,10 @@ def test_install_editable_uninstalls_existing(data, script, tmpdir): result = script.pip( 'install', '-e', - '%s#egg=pip-test-package' % - local_checkout( + '{dir}#egg=pip-test-package'.format( + dir=local_checkout( 'git+https://github.com/pypa/pip-test-package.git', tmpdir, - ), + )), ) result.assert_installed('pip-test-package', with_files=['.git']) assert 'Found existing installation: pip-test-package 0.1' in result.stdout @@ -362,7 +362,7 @@ def test_vcs_url_final_slash_normalization(script, tmpdir): Test that presence or absence of final slash in VCS URL is normalized. """ pkg_path = _create_test_package(script, name='testpackage', vcs='hg') - args = ['install', '-e', 'hg+%s/#egg=testpackage' % path_to_url(pkg_path)] + args = ['install', '-e', 'hg+{url}/#egg=testpackage'.format(url=path_to_url(pkg_path))] result = script.pip(*args) result.assert_installed('testpackage', with_files=['.hg']) @@ -371,7 +371,7 @@ def test_vcs_url_final_slash_normalization(script, tmpdir): def test_install_editable_from_bazaar(script, tmpdir): """Test checking out from Bazaar.""" pkg_path = _create_test_package(script, name='testpackage', vcs='bazaar') - args = ['install', '-e', 'bzr+%s/#egg=testpackage' % path_to_url(pkg_path)] + args = ['install', '-e', 'bzr+{url}/#egg=testpackage'.format(url=path_to_url(pkg_path))] result = script.pip(*args) result.assert_installed('testpackage', with_files=['.bzr']) @@ -384,12 +384,12 @@ def test_vcs_url_urlquote_normalization(script, tmpdir): """ script.pip( 'install', '-e', - '%s/#egg=django-wikiapp' % - local_checkout( - 'bzr+http://bazaar.launchpad.net/%7Edjango-wikiapp/django-wikiapp' - '/release-0.1', - tmpdir, - ), + '{url}/#egg=django-wikiapp'.format( + url=local_checkout( + 'bzr+http://bazaar.launchpad.net/%7Edjango-wikiapp/django-wikiapp' + '/release-0.1', + tmpdir, + )), ) @@ -401,7 +401,8 @@ def test_basic_install_from_local_directory(script, data): result = script.pip('install', to_install) fspkg_folder = script.site_packages / 'fspkg' egg_info_folder = ( - script.site_packages / 'FSPkg-0.1.dev0-py%s.egg-info' % pyversion + script.site_packages / + 'FSPkg-0.1.dev0-py{pyversion}.egg-info'.format(**locals()) ) assert fspkg_folder in result.files_created, str(result.stdout) assert egg_info_folder in result.files_created, str(result) @@ -420,7 +421,7 @@ def test_basic_install_relative_directory(script, data, test_type, editable): Test installing a requirement using a relative path. """ egg_info_file = ( - script.site_packages / 'FSPkg-0.1.dev0-py%s.egg-info' % pyversion + script.site_packages / 'FSPkg-0.1.dev0-py{pyversion}.egg-info'.format(**locals()) ) egg_link_file = ( script.site_packages / 'FSPkg.egg-link' @@ -550,7 +551,8 @@ def test_install_from_local_directory_with_symlinks_to_directories( result = script.pip('install', to_install) pkg_folder = script.site_packages / 'symlinks' egg_info_folder = ( - script.site_packages / 'symlinks-0.1.dev0-py%s.egg-info' % pyversion + script.site_packages / + 'symlinks-0.1.dev0-py{pyversion}.egg-info'.format(**locals()) ) assert pkg_folder in result.files_created, str(result.stdout) assert egg_info_folder in result.files_created, str(result) @@ -562,7 +564,8 @@ def test_install_from_local_directory_with_socket_file(script, data, tmpdir): Test installing from a local directory containing a socket file. """ egg_info_file = ( - script.site_packages / "FSPkg-0.1.dev0-py%s.egg-info" % pyversion + script.site_packages / + "FSPkg-0.1.dev0-py{pyversion}.egg-info".format(**locals()) ) package_folder = script.site_packages / "fspkg" to_copy = data.packages.joinpath("FSPkg") @@ -663,7 +666,7 @@ def test_install_curdir(script, data): result = script.pip('install', curdir, cwd=run_from) fspkg_folder = script.site_packages / 'fspkg' egg_info_folder = ( - script.site_packages / 'FSPkg-0.1.dev0-py%s.egg-info' % pyversion + script.site_packages / 'FSPkg-0.1.dev0-py{pyversion}.egg-info'.format(**locals()) ) assert fspkg_folder in result.files_created, str(result.stdout) assert egg_info_folder in result.files_created, str(result) @@ -677,7 +680,7 @@ def test_install_pardir(script, data): result = script.pip('install', pardir, cwd=run_from) fspkg_folder = script.site_packages / 'fspkg' egg_info_folder = ( - script.site_packages / 'FSPkg-0.1.dev0-py%s.egg-info' % pyversion + script.site_packages / 'FSPkg-0.1.dev0-py{pyversion}.egg-info'.format(**locals()) ) assert fspkg_folder in result.files_created, str(result.stdout) assert egg_info_folder in result.files_created, str(result) @@ -714,9 +717,9 @@ def test_install_using_install_option_and_editable(script, tmpdir): script.scratch_path.joinpath(folder).mkdir() url = 'git+git://github.com/pypa/pip-test-package' result = script.pip( - 'install', '-e', '%s#egg=pip-test-package' % - local_checkout(url, tmpdir), - '--install-option=--script-dir=%s' % folder, + 'install', '-e', '{url}#egg=pip-test-package' + .format(url=local_checkout(url, tmpdir)), + '--install-option=--script-dir={footer}'.format(**locals()), expect_stderr=True) script_file = ( script.venv / 'src' / 'pip-test-package' / @@ -735,7 +738,7 @@ def test_install_global_option_using_editable(script, tmpdir): url = 'hg+http://bitbucket.org/runeh/anyjson' result = script.pip( 'install', '--global-option=--version', '-e', - '%s@0.2.5#egg=anyjson' % local_checkout(url, tmpdir), + '{url}@0.2.5#egg=anyjson'.format(url=local_checkout(url, tmpdir)), expect_stderr=True) assert 'Successfully installed anyjson' in result.stdout @@ -747,7 +750,7 @@ def test_install_package_with_same_name_in_curdir(script): """ script.scratch_path.joinpath("mock==0.6").mkdir() result = script.pip('install', 'mock==0.6') - egg_folder = script.site_packages / 'mock-0.6.0-py%s.egg-info' % pyversion + egg_folder = script.site_packages / 'mock-0.6.0-py{pyversion}.egg-info'.format(**locals()) assert egg_folder in result.files_created, str(result) @@ -765,7 +768,7 @@ def test_install_folder_using_dot_slash(script): pkg_path = script.scratch_path / 'mock' pkg_path.joinpath("setup.py").write_text(mock100_setup_py) result = script.pip('install', './mock') - egg_folder = script.site_packages / 'mock-100.1-py%s.egg-info' % pyversion + egg_folder = script.site_packages / 'mock-100.1-py{pyversion}.egg-info'.format(**locals()) assert egg_folder in result.files_created, str(result) @@ -777,7 +780,7 @@ def test_install_folder_using_slash_in_the_end(script): pkg_path = script.scratch_path / 'mock' pkg_path.joinpath("setup.py").write_text(mock100_setup_py) result = script.pip('install', 'mock' + os.path.sep) - egg_folder = script.site_packages / 'mock-100.1-py%s.egg-info' % pyversion + egg_folder = script.site_packages / 'mock-100.1-py{pyversion}.egg-info'.format(**locals()) assert egg_folder in result.files_created, str(result) @@ -790,7 +793,7 @@ def test_install_folder_using_relative_path(script): pkg_path = script.scratch_path / 'initools' / 'mock' pkg_path.joinpath("setup.py").write_text(mock100_setup_py) result = script.pip('install', Path('initools') / 'mock') - egg_folder = script.site_packages / 'mock-100.1-py%s.egg-info' % pyversion + egg_folder = script.site_packages / 'mock-100.1-py{pyversion}.egg-info'.format(**locals()) assert egg_folder in result.files_created, str(result) @@ -802,8 +805,8 @@ def test_install_package_which_contains_dev_in_name(script): result = script.pip('install', 'django-devserver==0.0.4') devserver_folder = script.site_packages / 'devserver' egg_info_folder = ( - script.site_packages / 'django_devserver-0.0.4-py%s.egg-info' % - pyversion + script.site_packages / + 'django_devserver-0.0.4-py{pyversion}.egg-info'.format(**locals) ) assert devserver_folder in result.files_created, str(result.stdout) assert egg_info_folder in result.files_created, str(result) @@ -832,7 +835,7 @@ def test_install_package_with_target(script): str(result) ) egg_folder = ( - Path('scratch') / 'target' / 'simple-2.0-py%s.egg-info' % pyversion) + Path('scratch') / 'target' / 'simple-2.0-py{pyversion}.egg-info'.format(**locals())) assert egg_folder in result.files_created, ( str(result) ) @@ -966,8 +969,8 @@ def test_install_package_with_root(script, data): 'simple==1.0', ) normal_install_path = ( - script.base_path / script.site_packages / 'simple-1.0-py%s.egg-info' % - pyversion + script.base_path / script.site_packages / + 'simple-1.0-py{pyversion}.egg-info'.format(**locals()) ) # use distutils to change the root exactly how the --root option does it from distutils.util import change_root @@ -1090,9 +1093,9 @@ def test_url_req_case_mismatch_no_index(script, data): ) # only Upper-1.0.tar.gz should get installed. - egg_folder = script.site_packages / 'Upper-1.0-py%s.egg-info' % pyversion + egg_folder = script.site_packages / 'Upper-1.0-py{pyversion}.egg-info'.format(**locals()) assert egg_folder in result.files_created, str(result) - egg_folder = script.site_packages / 'Upper-2.0-py%s.egg-info' % pyversion + egg_folder = script.site_packages / 'Upper-2.0-py{pyversion}.egg-info'.format(**locals()) assert egg_folder not in result.files_created, str(result) @@ -1117,9 +1120,9 @@ def test_url_req_case_mismatch_file_index(script, data): ) # only Upper-1.0.tar.gz should get installed. - egg_folder = script.site_packages / 'Dinner-1.0-py%s.egg-info' % pyversion + egg_folder = script.site_packages / 'Dinner-1.0-py{pyversion}.egg-info'.format(**locals()) assert egg_folder in result.files_created, str(result) - egg_folder = script.site_packages / 'Dinner-2.0-py%s.egg-info' % pyversion + egg_folder = script.site_packages / 'Dinner-2.0-py{pyversion}.egg-info'.format(**locals()) assert egg_folder not in result.files_created, str(result) @@ -1134,9 +1137,9 @@ def test_url_incorrect_case_no_index(script, data): ) # only Upper-2.0.tar.gz should get installed. - egg_folder = script.site_packages / 'Upper-1.0-py%s.egg-info' % pyversion + egg_folder = script.site_packages / 'Upper-1.0-py{pyversion}.egg-info'.format(**locals()) assert egg_folder not in result.files_created, str(result) - egg_folder = script.site_packages / 'Upper-2.0-py%s.egg-info' % pyversion + egg_folder = script.site_packages / 'Upper-2.0-py{pyversion}.egg-info'.format(**locals()) assert egg_folder in result.files_created, str(result) @@ -1152,9 +1155,9 @@ def test_url_incorrect_case_file_index(script, data): ) # only Upper-2.0.tar.gz should get installed. - egg_folder = script.site_packages / 'Dinner-1.0-py%s.egg-info' % pyversion + egg_folder = script.site_packages / 'Dinner-1.0-py{pyversion}.egg-info'.format(**locals()) assert egg_folder not in result.files_created, str(result) - egg_folder = script.site_packages / 'Dinner-2.0-py%s.egg-info' % pyversion + egg_folder = script.site_packages / 'Dinner-2.0-py{pyversion}.egg-info'.format(**locals()) assert egg_folder in result.files_created, str(result) # Should show index-url location in output @@ -1258,7 +1261,7 @@ def test_install_subprocess_output_handling(script, data): def test_install_log(script, data, tmpdir): # test that verbose logs go to "--log" file f = tmpdir.joinpath("log.txt") - args = ['--log=%s' % f, + args = ['--log={f}'.format(**locals()), 'install', data.src.joinpath('chattymodule')] result = script.pip(*args) assert 0 == result.stdout.count("HELLO FROM CHATTYMODULE") @@ -1411,7 +1414,7 @@ def test_install_editable_with_wrong_egg_name(script): version='0.1') """)) result = script.pip( - 'install', '--editable', 'file://%s#egg=pkgb' % pkga_path + 'install', '--editable', 'file://{pkga_path}#egg=pkgb'.format(**locals()) ) assert ("Generating metadata for package pkgb produced metadata " "for project name pkga. Fix your #egg=pkgb " @@ -1485,7 +1488,7 @@ def test_install_incompatible_python_requires_editable(script): version='0.1') """)) result = script.pip( - 'install', '--editable=%s' % pkga_path, expect_error=True) + 'install', '--editable={pkga_path}'.format(**locals()), expect_error=True) assert _get_expected_error_text() in result.stderr, str(result) @@ -1599,7 +1602,7 @@ def test_installed_files_recorded_in_deterministic_order(script, data): to_install = data.packages.joinpath("FSPkg") result = script.pip('install', to_install) fspkg_folder = script.site_packages / 'fspkg' - egg_info = 'FSPkg-0.1.dev0-py%s.egg-info' % pyversion + egg_info = 'FSPkg-0.1.dev0-py{pyversion}.egg-info'.format(**locals()) installed_files_path = ( script.site_packages / egg_info / 'installed-files.txt' ) @@ -1664,8 +1667,8 @@ def test_target_install_ignores_distutils_config_install_prefix(script): distutils_config.write_text(textwrap.dedent( ''' [install] - prefix=%s - ''' % str(prefix))) + prefix={prefix} + '''.format(**locals()))) target = script.scratch_path / 'target' result = script.pip_install_local('simplewheel', '-t', target) diff --git a/tests/functional/test_install_cleanup.py b/tests/functional/test_install_cleanup.py index b07c809079b..7f91be3a4b8 100644 --- a/tests/functional/test_install_cleanup.py +++ b/tests/functional/test_install_cleanup.py @@ -85,7 +85,7 @@ def test_cleanup_req_satisfied_no_name(script, data): script.pip('install', dist) build = script.venv_path / 'build' - assert not exists(build), "unexpected build/ dir exists: %s" % build + assert not exists(build), "unexpected build/ dir exists: {build}".format(**locals()) script.assert_no_temp() @@ -99,7 +99,7 @@ def test_cleanup_after_install_exception(script, data): expect_error=True, ) build = script.venv_path / 'build' - assert not exists(build), "build/ dir still exists: %s" % result.stdout + assert not exists(build), "build/ dir still exists: {result.stdout}".format(**locals()) script.assert_no_temp() @@ -113,7 +113,7 @@ def test_cleanup_after_egg_info_exception(script, data): expect_error=True, ) build = script.venv_path / 'build' - assert not exists(build), "build/ dir still exists: %s" % result.stdout + assert not exists(build), "build/ dir still exists: {result.stdout}".format(**locals()) script.assert_no_temp() diff --git a/tests/functional/test_install_compat.py b/tests/functional/test_install_compat.py index b957934ef48..bd6baa496cc 100644 --- a/tests/functional/test_install_compat.py +++ b/tests/functional/test_install_compat.py @@ -24,17 +24,18 @@ def test_debian_egg_name_workaround(script): result = script.pip('install', 'INITools==0.2') egg_info = os.path.join( - script.site_packages, "INITools-0.2-py%s.egg-info" % pyversion) + script.site_packages, + "INITools-0.2-py{pyversion}.egg-info".format(**locals())) # Debian only removes pyversion for global installs, not inside a venv # so even if this test runs on a Debian/Ubuntu system with broken # setuptools, since our test runs inside a venv we'll still have the normal # .egg-info - assert egg_info in result.files_created, "Couldn't find %s" % egg_info + assert egg_info in result.files_created, "Couldn't find {egg_info}".format(**locals()) # The Debian no-pyversion version of the .egg-info mangled = os.path.join(script.site_packages, "INITools-0.2.egg-info") - assert mangled not in result.files_created, "Found unexpected %s" % mangled + assert mangled not in result.files_created, "Found unexpected {mangled}".format(**locals()) # Simulate a Debian install by copying the .egg-info to their name for it full_egg_info = os.path.join(script.base_path, egg_info) diff --git a/tests/functional/test_install_config.py b/tests/functional/test_install_config.py index 2b76e81cd25..088016a9f1b 100644 --- a/tests/functional/test_install_config.py +++ b/tests/functional/test_install_config.py @@ -107,7 +107,7 @@ def test_command_line_appends_correctly(script, data): """ script.environ['PIP_FIND_LINKS'] = ( - 'https://test.pypi.org %s' % data.find_links + 'https://test.pypi.org {data.find_links}'.format(**locals()) ) result = script.pip( 'install', '-vvv', 'INITools', '--trusted-host', diff --git a/tests/functional/test_install_extras.py b/tests/functional/test_install_extras.py index acfd58dff17..bce95cb196d 100644 --- a/tests/functional/test_install_extras.py +++ b/tests/functional/test_install_extras.py @@ -121,7 +121,7 @@ def test_install_special_extra(script): """)) result = script.pip( - 'install', '--no-index', '%s[Hop_hOp-hoP]' % pkga_path, + 'install', '--no-index', '{pkga_path}[Hop_hOp-hoP]'.format(**locals()), expect_error=True) assert ( "Could not find a version that satisfies the requirement missing_pkg" diff --git a/tests/functional/test_install_reqs.py b/tests/functional/test_install_reqs.py index 2422bdb500e..2d83f5a6994 100644 --- a/tests/functional/test_install_reqs.py +++ b/tests/functional/test_install_reqs.py @@ -24,14 +24,14 @@ def test_requirements_file(script): script.scratch_path.joinpath("initools-req.txt").write_text(textwrap.dedent("""\ INITools==0.2 # and something else to test out: - %s<=%s - """ % (other_lib_name, other_lib_version))) + {other_lib_name}<={other_lib_version} + """.format(**locals()))) result = script.pip( 'install', '-r', script.scratch_path / 'initools-req.txt' ) assert ( script.site_packages / 'INITools-0.2-py{}.egg-info'.format( - pyversion in result.files_created) + pyversion) in result.files_created ) assert script.site_packages / 'initools' in result.files_created assert result.files_created[script.site_packages / other_lib_name].dir @@ -46,7 +46,7 @@ def test_schema_check_in_requirements_file(script): """ script.scratch_path.joinpath("file-egg-req.txt").write_text( - "\n%s\n" % ( + "\n{}\n".format( "git://github.com/alex/django-fixture-generator.git" "#egg=fixture_generator" ) @@ -73,7 +73,7 @@ def test_relative_requirements_file(script, data, test_type, editable): """ egg_info_file = ( - script.site_packages / 'FSPkg-0.1.dev0-py%s.egg-info' % pyversion + script.site_packages / 'FSPkg-0.1.dev0-py{pyversion}.egg-info'.format(**locals()) ) egg_link_file = ( script.site_packages / 'FSPkg.egg-link' @@ -120,22 +120,22 @@ def test_multiple_requirements_files(script, tmpdir): other_lib_name, other_lib_version = 'anyjson', '0.3' script.scratch_path.joinpath("initools-req.txt").write_text( textwrap.dedent(""" - -e %s@10#egg=INITools - -r %s-req.txt - """) % + -e {}@10#egg=INITools + -r {}-req.txt + """).format ( local_checkout('svn+http://svn.colorstudy.com/INITools', tmpdir), other_lib_name ), ) - script.scratch_path.joinpath("%s-req.txt" % other_lib_name).write_text( - "%s<=%s" % (other_lib_name, other_lib_version) + script.scratch_path.joinpath("{other_lib_name}-req.txt".format(**locals())).write_text( + "{other_lib_name}<={other_lib_version}".format(**locals()) ) result = script.pip( 'install', '-r', script.scratch_path / 'initools-req.txt' ) assert result.files_created[script.site_packages / other_lib_name].dir - fn = '%s-%s-py%s.egg-info' % (other_lib_name, other_lib_version, pyversion) + fn = '{other_lib_name}-{other_lib_version}-py{pyversion}.egg-info'.format(**locals()) assert result.files_created[script.site_packages / fn].dir assert script.venv / 'src' / 'initools' in result.files_created @@ -176,13 +176,13 @@ def test_respect_order_in_requirements_file(script, data): if 'Processing' in line] assert 'parent' in downloaded[0], ( - 'First download should be "parent" but was "%s"' % downloaded[0] + 'First download should be "parent" but was "{}"'.format(downloaded[0]) ) assert 'child' in downloaded[1], ( - 'Second download should be "child" but was "%s"' % downloaded[1] + 'Second download should be "child" but was "{}"'.format(downloaded[1]) ) assert 'simple' in downloaded[2], ( - 'Third download should be "simple" but was "%s"' % downloaded[2] + 'Third download should be "simple" but was "{}"'.format(downloaded[2]) ) @@ -215,8 +215,9 @@ def test_install_local_editable_with_subdirectory(script): 'version_subdir') result = script.pip( 'install', '-e', - '%s#egg=version_subpkg&subdirectory=version_subdir' % - ('git+%s' % path_to_url(version_pkg_path),) + '{uri}#egg=version_subpkg&subdirectory=version_subdir'.format( + uri='git+' + path_to_url(version_pkg_path), + ), ) result.assert_installed('version-subpkg', sub_dir='version_subdir') @@ -228,8 +229,9 @@ def test_install_local_with_subdirectory(script): 'version_subdir') result = script.pip( 'install', - '%s#egg=version_subpkg&subdirectory=version_subdir' % - ('git+' + path_to_url(version_pkg_path),) + '{uri}#egg=version_subpkg&subdirectory=version_subdir'.format( + uri='git+' + path_to_url(version_pkg_path), + ), ) result.assert_installed('version_subpkg.py', editable=False) @@ -247,7 +249,7 @@ def test_wheel_user_with_prefix_in_pydistutils_cfg( with open(user_cfg, "w") as cfg: cfg.write(textwrap.dedent(""" [install] - prefix=%s""" % script.scratch_path)) + prefix={script.scratch_path}""".format(**locals()))) result = script.pip( 'install', '--user', '--no-index', @@ -268,13 +270,14 @@ def test_install_option_in_requirements_file(script, data, virtualenv): script.scratch_path.joinpath("reqs.txt").write_text( textwrap.dedent( - """simple --install-option='--home=%s'""" - % script.scratch_path.joinpath("home1"))) + """simple --install-option='--home={home}'""".format( + home=script.scratch_path.joinpath("home1")))) result = script.pip( 'install', '--no-index', '-f', data.find_links, '-r', script.scratch_path / 'reqs.txt', - '--install-option=--home=%s' % script.scratch_path.joinpath("home2"), + '--install-option=--home={home}'.format( + home=script.scratch_path.joinpath("home2")), expect_stderr=True) package_dir = script.scratch / 'home1' / 'lib' / 'python' / 'simple' @@ -333,7 +336,7 @@ def test_constraints_local_install_causes_error(script, data): def test_constraints_constrain_to_local_editable(script, data): to_install = data.src.joinpath("singlemodule") script.scratch_path.joinpath("constraints.txt").write_text( - "-e %s#egg=singlemodule" % path_to_url(to_install) + "-e {url}#egg=singlemodule".format(url=path_to_url(to_install)) ) result = script.pip( 'install', '--no-index', '-f', data.find_links, '-c', @@ -344,7 +347,7 @@ def test_constraints_constrain_to_local_editable(script, data): def test_constraints_constrain_to_local(script, data): to_install = data.src.joinpath("singlemodule") script.scratch_path.joinpath("constraints.txt").write_text( - "%s#egg=singlemodule" % path_to_url(to_install) + "{url}#egg=singlemodule".format(url=path_to_url(to_install)) ) result = script.pip( 'install', '--no-index', '-f', data.find_links, '-c', @@ -400,7 +403,7 @@ def test_double_install_spurious_hash_mismatch( def test_install_with_extras_from_constraints(script, data): to_install = data.packages.joinpath("LocalExtras") script.scratch_path.joinpath("constraints.txt").write_text( - "%s#egg=LocalExtras[bar]" % path_to_url(to_install) + "{url}#egg=LocalExtras[bar]".format(url=path_to_url(to_install)) ) result = script.pip_install_local( '-c', script.scratch_path / 'constraints.txt', 'LocalExtras') @@ -410,7 +413,7 @@ def test_install_with_extras_from_constraints(script, data): def test_install_with_extras_from_install(script, data): to_install = data.packages.joinpath("LocalExtras") script.scratch_path.joinpath("constraints.txt").write_text( - "%s#egg=LocalExtras" % path_to_url(to_install) + "{url}#egg=LocalExtras".format(url=path_to_url(to_install)) ) result = script.pip_install_local( '-c', script.scratch_path / 'constraints.txt', 'LocalExtras[baz]') @@ -420,7 +423,7 @@ def test_install_with_extras_from_install(script, data): def test_install_with_extras_joined(script, data): to_install = data.packages.joinpath("LocalExtras") script.scratch_path.joinpath("constraints.txt").write_text( - "%s#egg=LocalExtras[bar]" % path_to_url(to_install) + "{url}#egg=LocalExtras[bar]".format(url=path_to_url(to_install)) ) result = script.pip_install_local( '-c', script.scratch_path / 'constraints.txt', 'LocalExtras[baz]' @@ -432,7 +435,7 @@ def test_install_with_extras_joined(script, data): def test_install_with_extras_editable_joined(script, data): to_install = data.packages.joinpath("LocalExtras") script.scratch_path.joinpath("constraints.txt").write_text( - "-e %s#egg=LocalExtras[bar]" % path_to_url(to_install) + "-e {url}#egg=LocalExtras[bar]".format(url=path_to_url(to_install)) ) result = script.pip_install_local( '-c', script.scratch_path / 'constraints.txt', 'LocalExtras[baz]') @@ -454,13 +457,15 @@ def test_install_distribution_duplicate_extras(script, data): package_name = to_install + "[bar]" with pytest.raises(AssertionError): result = script.pip_install_local(package_name, package_name) - assert 'Double requirement given: %s' % package_name in result.stderr + expected = ( + 'Double requirement given: {package_name}'.format(**locals())) + assert expected in result.stderr def test_install_distribution_union_with_constraints(script, data): to_install = data.packages.joinpath("LocalExtras") script.scratch_path.joinpath("constraints.txt").write_text( - "%s[bar]" % to_install) + "{to_install}[bar]".format(**locals())) result = script.pip_install_local( '-c', script.scratch_path / 'constraints.txt', to_install + '[baz]') assert 'Running setup.py install for LocalExtras' in result.stdout @@ -492,11 +497,10 @@ def test_install_distribution_union_conflicting_extras(script, data): def test_install_unsupported_wheel_link_with_marker(script): script.scratch_path.joinpath("with-marker.txt").write_text( textwrap.dedent("""\ - %s; %s - """) % - ( - 'https://github.com/a/b/c/asdf-1.5.2-cp27-none-xyz.whl', - 'sys_platform == "xyz"' + {url}; {req} + """).format( + url='https://github.com/a/b/c/asdf-1.5.2-cp27-none-xyz.whl', + req='sys_platform == "xyz"', ) ) result = script.pip( @@ -511,9 +515,10 @@ def test_install_unsupported_wheel_link_with_marker(script): def test_install_unsupported_wheel_file(script, data): # Trying to install a local wheel with an incompatible version/type # should fail. + path = data.packages.joinpath("simple.dist-0.1-py1-none-invalid.whl") script.scratch_path.joinpath("wheel-file.txt").write_text(textwrap.dedent("""\ - %s - """ % data.packages.joinpath("simple.dist-0.1-py1-none-invalid.whl"))) + {path} + """.format(**locals()))) result = script.pip( 'install', '-r', script.scratch_path / 'wheel-file.txt', expect_error=True, @@ -538,9 +543,9 @@ def test_install_options_local_to_package(script, data): reqs_file = script.scratch_path.joinpath("reqs.txt") reqs_file.write_text( textwrap.dedent(""" - simple --install-option='--home=%s' + simple --install-option='--home={home_simple}' INITools - """ % home_simple)) + """.format(**locals()))) result = script.pip( 'install', '--no-index', '-f', data.find_links, diff --git a/tests/functional/test_install_upgrade.py b/tests/functional/test_install_upgrade.py index 0024de4d438..87ccd893afc 100644 --- a/tests/functional/test_install_upgrade.py +++ b/tests/functional/test_install_upgrade.py @@ -46,11 +46,13 @@ def test_only_if_needed_does_not_upgrade_deps_when_satisfied(script): ) assert ( - (script.site_packages / 'require_simple-1.0-py%s.egg-info' % pyversion) + (script.site_packages / 'require_simple-1.0-py{pyversion}.egg-info' + .format(**globals())) not in result.files_deleted ), "should have installed require_simple==1.0" assert ( - (script.site_packages / 'simple-2.0-py%s.egg-info' % pyversion) + (script.site_packages / 'simple-2.0-py{pyversion}.egg-info' + .format(**globals())) not in result.files_deleted ), "should not have uninstalled simple==2.0" assert ( @@ -70,16 +72,23 @@ def test_only_if_needed_does_upgrade_deps_when_no_longer_satisfied(script): ) assert ( - (script.site_packages / 'require_simple-1.0-py%s.egg-info' % pyversion) + (script.site_packages / 'require_simple-1.0-py{pyversion}.egg-info' + .format(**globals())) not in result.files_deleted ), "should have installed require_simple==1.0" + expected = ( + script.site_packages / + 'simple-3.0-py{pyversion}.egg-info'.format(**globals()) + ) assert ( - script.site_packages / 'simple-3.0-py%s.egg-info' % - pyversion in result.files_created + expected in result.files_created ), "should have installed simple==3.0" + expected = ( + script.site_packages / + 'simple-1.0-py{pyversion}.egg-info'.format(**globals()) + ) assert ( - script.site_packages / 'simple-1.0-py%s.egg-info' % - pyversion in result.files_deleted + expected in result.files_deleted ), "should have uninstalled simple==1.0" @@ -94,11 +103,13 @@ def test_eager_does_upgrade_dependecies_when_currently_satisfied(script): ) assert ( - (script.site_packages / 'require_simple-1.0-py%s.egg-info' % pyversion) + (script.site_packages / + 'require_simple-1.0-py{pyversion}.egg-info'.format(**globals())) not in result.files_deleted ), "should have installed require_simple==1.0" assert ( - (script.site_packages / 'simple-2.0-py%s.egg-info' % pyversion) + (script.site_packages / + 'simple-2.0-py{pyversion}.egg-info'.format(**globals())) in result.files_deleted ), "should have uninstalled simple==2.0" @@ -114,16 +125,19 @@ def test_eager_does_upgrade_dependecies_when_no_longer_satisfied(script): ) assert ( - (script.site_packages / 'require_simple-1.0-py%s.egg-info' % pyversion) + (script.site_packages / + 'require_simple-1.0-py{pyversion}.egg-info'.format(**globals())) not in result.files_deleted ), "should have installed require_simple==1.0" assert ( - script.site_packages / 'simple-3.0-py%s.egg-info' % - pyversion in result.files_created + script.site_packages / + 'simple-3.0-py{pyversion}.egg-info'.format(**globals()) + in result.files_created ), "should have installed simple==3.0" assert ( - script.site_packages / 'simple-1.0-py%s.egg-info' % - pyversion in result.files_deleted + script.site_packages / + 'simple-1.0-py{pyversion}.egg-info'.format(**globals()) + in result.files_deleted ), "should have uninstalled simple==1.0" @@ -139,12 +153,14 @@ def test_upgrade_to_specific_version(script): 'pip install with specific version did not upgrade' ) assert ( - script.site_packages / 'INITools-0.1-py%s.egg-info' % - pyversion in result.files_deleted + script.site_packages / 'INITools-0.1-py{pyversion}.egg-info' + .format(**globals()) + in result.files_deleted ) assert ( - script.site_packages / 'INITools-0.2-py%s.egg-info' % - pyversion in result.files_created + script.site_packages / 'INITools-0.2-py{pyversion}.egg-info' + .format(**globals()) + in result.files_created ) @@ -158,8 +174,9 @@ def test_upgrade_if_requested(script): result = script.pip('install', '--upgrade', 'INITools') assert result.files_created, 'pip install --upgrade did not upgrade' assert ( - script.site_packages / 'INITools-0.1-py%s.egg-info' % - pyversion not in result.files_created + script.site_packages / + 'INITools-0.1-py{pyversion}.egg-info'.format(**globals()) + not in result.files_created ) @@ -322,12 +339,14 @@ def test_should_not_install_always_from_cache(script): script.pip('uninstall', '-y', 'INITools') result = script.pip('install', 'INITools==0.1') assert ( - script.site_packages / 'INITools-0.2-py%s.egg-info' % - pyversion not in result.files_created + script.site_packages / + 'INITools-0.2-py{pyversion}.egg-info'.format(**globals()) + not in result.files_created ) assert ( - script.site_packages / 'INITools-0.1-py%s.egg-info' % - pyversion in result.files_created + script.site_packages / + 'INITools-0.1-py{pyversion}.egg-info'.format(**globals()) + in result.files_created ) @@ -341,18 +360,22 @@ def test_install_with_ignoreinstalled_requested(script): assert result.files_created, 'pip install -I did not install' # both the old and new metadata should be present. assert os.path.exists( - script.site_packages_path / 'INITools-0.1-py%s.egg-info' % pyversion + script.site_packages_path / + 'INITools-0.1-py{pyversion}.egg-info'.format(**globals()) ) assert os.path.exists( - script.site_packages_path / 'INITools-0.3-py%s.egg-info' % pyversion + script.site_packages_path / + 'INITools-0.3-py{pyversion}.egg-info'.format(**globals()) ) @pytest.mark.network def test_upgrade_vcs_req_with_no_dists_found(script, tmpdir): """It can upgrade a VCS requirement that has no distributions otherwise.""" - req = "%s#egg=pip-test-package" % local_checkout( - "git+https://github.com/pypa/pip-test-package.git", tmpdir, + req = "{checkout}#egg=pip-test-package".format( + checkout=local_checkout( + "git+https://github.com/pypa/pip-test-package.git", tmpdir, + ) ) script.pip("install", req) result = script.pip("install", "-U", req) @@ -365,10 +388,11 @@ def test_upgrade_vcs_req_with_dist_found(script): # TODO(pnasrat) Using local_checkout fails on windows - oddness with the # test path urls/git. req = ( - "%s#egg=pretend" % - ( - "git+git://github.com/alex/pretend@e7f26ad7dbcb4a02a4995aade4" - "743aad47656b27" + "{url}#egg=pretend".format( + url=( + "git+git://github.com/alex/pretend@e7f26ad7dbcb4a02a4995aade4" + "743aad47656b27" + ), ) ) script.pip("install", req, expect_stderr=True) @@ -401,7 +425,8 @@ class TestUpgradeDistributeToSetuptools(object): def prep_ve(self, script, version, pip_src, distribute=False): self.script = script - self.script.pip_install_local('virtualenv==%s' % version) + self.script.pip_install_local( + 'virtualenv=={version}'.format(**locals())) args = ['virtualenv', self.script.scratch_path / 'VE'] if distribute: args.insert(1, '--distribute') diff --git a/tests/functional/test_install_user.py b/tests/functional/test_install_user.py index 2cc91f56c75..8432dbc0bd6 100644 --- a/tests/functional/test_install_user.py +++ b/tests/functional/test_install_user.py @@ -52,8 +52,10 @@ def test_install_subversion_usersite_editable_with_distribute( """ result = script.pip( 'install', '--user', '-e', - '%s#egg=initools' % - local_checkout('svn+http://svn.colorstudy.com/INITools', tmpdir) + '{checkout}#egg=initools'.format( + checkout=local_checkout( + 'svn+http://svn.colorstudy.com/INITools', tmpdir) + ) ) result.assert_installed('INITools', use_user_site=True) @@ -110,7 +112,7 @@ def test_install_user_conflict_in_usersite(self, script): # usersite has 0.1 egg_info_folder = ( - script.user_site / 'INITools-0.1-py%s.egg-info' % pyversion + script.user_site / 'INITools-0.1-py{pyversion}.egg-info'.format(**globals()) ) initools_v3_file = ( # file only in 0.3 @@ -136,7 +138,7 @@ def test_install_user_conflict_in_globalsite(self, virtualenv, script): # usersite has 0.1 egg_info_folder = ( - script.user_site / 'INITools-0.1-py%s.egg-info' % pyversion + script.user_site / 'INITools-0.1-py{pyversion}.egg-info'.format(**globals()) ) initools_folder = script.user_site / 'initools' assert egg_info_folder in result2.files_created, str(result2) @@ -145,7 +147,7 @@ def test_install_user_conflict_in_globalsite(self, virtualenv, script): # site still has 0.2 (can't look in result1; have to check) egg_info_folder = ( script.base_path / script.site_packages / - 'INITools-0.2-py%s.egg-info' % pyversion + 'INITools-0.2-py{pyversion}.egg-info'.format(**globals()) ) initools_folder = script.base_path / script.site_packages / 'initools' assert isdir(egg_info_folder) @@ -166,7 +168,7 @@ def test_upgrade_user_conflict_in_globalsite(self, virtualenv, script): # usersite has 0.3.1 egg_info_folder = ( - script.user_site / 'INITools-0.3.1-py%s.egg-info' % pyversion + script.user_site / 'INITools-0.3.1-py{pyversion}.egg-info'.format(**globals()) ) initools_folder = script.user_site / 'initools' assert egg_info_folder in result2.files_created, str(result2) @@ -175,7 +177,7 @@ def test_upgrade_user_conflict_in_globalsite(self, virtualenv, script): # site still has 0.2 (can't look in result1; have to check) egg_info_folder = ( script.base_path / script.site_packages / - 'INITools-0.2-py%s.egg-info' % pyversion + 'INITools-0.2-py{pyversion}.egg-info'.format(**globals()) ) initools_folder = script.base_path / script.site_packages / 'initools' assert isdir(egg_info_folder), result2.stdout @@ -199,7 +201,7 @@ def test_install_user_conflict_in_globalsite_and_usersite( # usersite has 0.1 egg_info_folder = ( - script.user_site / 'INITools-0.1-py%s.egg-info' % pyversion + script.user_site / 'INITools-0.1-py{pyversion}.egg-info'.format(**globals()) ) initools_v3_file = ( # file only in 0.3 @@ -212,7 +214,7 @@ def test_install_user_conflict_in_globalsite_and_usersite( # site still has 0.2 (can't just look in result1; have to check) egg_info_folder = ( script.base_path / script.site_packages / - 'INITools-0.2-py%s.egg-info' % pyversion + 'INITools-0.2-py{pyversion}.egg-info'.format(**globals()) ) initools_folder = script.base_path / script.site_packages / 'initools' assert isdir(egg_info_folder) @@ -241,6 +243,9 @@ def test_install_user_in_global_virtualenv_with_conflict_fails( dist_location = resultp.stdout.strip() assert ( "Will not install to the user site because it will lack sys.path " - "precedence to %s in %s" % - ('INITools', dist_location) in result2.stderr + "precedence to {name} in {location}".format( + name='INITools', + location=dist_location, + ) + in result2.stderr ) diff --git a/tests/functional/test_install_vcs_git.py b/tests/functional/test_install_vcs_git.py index 01fec7a8bd4..3cb4d1490b2 100644 --- a/tests/functional/test_install_vcs_git.py +++ b/tests/functional/test_install_vcs_git.py @@ -171,7 +171,7 @@ def test_install_noneditable_git(script, tmpdir): ) egg_info_folder = ( script.site_packages / - 'pip_test_package-0.1.1-py%s.egg-info' % pyversion + 'pip_test_package-0.1.1-py{pyversion}.egg-info'.format(**globals()) ) result.assert_installed('piptestpackage', without_egg_link=True, diff --git a/tests/functional/test_pep517.py b/tests/functional/test_pep517.py index d932f2ef83b..0286fe1f034 100644 --- a/tests/functional/test_pep517.py +++ b/tests/functional/test_pep517.py @@ -134,11 +134,13 @@ def test_conflicting_pep517_backend_requirements(script, tmpdir, data): project_dir, expect_error=True ) + msg = ( + 'Some build dependencies for {url} conflict with the backend ' + 'dependencies: simplewheel==1.0 is incompatible with ' + 'simplewheel==2.0.'.format(url=path_to_url(project_dir))) assert ( result.returncode != 0 and - ('Some build dependencies for %s conflict with the backend ' - 'dependencies: simplewheel==1.0 is incompatible with ' - 'simplewheel==2.0.' % path_to_url(project_dir)) in result.stderr + msg in result.stderr ), str(result) diff --git a/tests/functional/test_uninstall.py b/tests/functional/test_uninstall.py index e06ff024630..04d8550f32a 100644 --- a/tests/functional/test_uninstall.py +++ b/tests/functional/test_uninstall.py @@ -328,8 +328,9 @@ def test_uninstall_editable_from_svn(script, tmpdir): """ result = script.pip( 'install', '-e', - '%s#egg=initools' % ( - local_checkout('svn+http://svn.colorstudy.com/INITools', tmpdir) + '{checkout}#egg=initools'.format( + checkout=local_checkout( + 'svn+http://svn.colorstudy.com/INITools', tmpdir) ), ) result.assert_installed('INITools') @@ -396,10 +397,10 @@ def test_uninstall_from_reqs_file(script, tmpdir): ) script.scratch_path.joinpath("test-req.txt").write_text( textwrap.dedent(""" - -e %s#egg=initools + -e {url}#egg=initools # and something else to test out: PyLogo<0.4 - """) % local_svn_url + """).format(url=local_svn_url) ) result = script.pip('install', '-r', 'test-req.txt') script.scratch_path.joinpath("test-req.txt").write_text( @@ -409,10 +410,10 @@ def test_uninstall_from_reqs_file(script, tmpdir): -i http://www.example.com --extra-index-url http://www.example.com - -e %s#egg=initools + -e {url}#egg=initools # and something else to test out: PyLogo<0.4 - """) % local_svn_url + """).format(url=local_svn_url) ) result2 = script.pip('uninstall', '-r', 'test-req.txt', '-y') assert_all_changes( diff --git a/tests/functional/test_uninstall_user.py b/tests/functional/test_uninstall_user.py index ed277739a1f..1b19294b78d 100644 --- a/tests/functional/test_uninstall_user.py +++ b/tests/functional/test_uninstall_user.py @@ -44,7 +44,7 @@ def test_uninstall_from_usersite_with_dist_in_global_site( # site still has 0.2 (can't look in result1; have to check) egg_info_folder = ( script.base_path / script.site_packages / - 'pip_test_package-0.1-py%s.egg-info' % pyversion + 'pip_test_package-0.1-py{pyversion}.egg-info'.format(**globals()) ) assert isdir(egg_info_folder) diff --git a/tests/functional/test_wheel.py b/tests/functional/test_wheel.py index 181ca05845b..a5c156019e6 100644 --- a/tests/functional/test_wheel.py +++ b/tests/functional/test_wheel.py @@ -48,12 +48,12 @@ def test_pip_wheel_success(script, data): 'wheel', '--no-index', '-f', data.find_links, 'simple==3.0', ) - wheel_file_name = 'simple-3.0-py%s-none-any.whl' % pyversion[0] + wheel_file_name = 'simple-3.0-py{pyversion[0]}-none-any.whl'.format(**globals()) wheel_file_path = script.scratch / wheel_file_name assert re.search( r"Created wheel for simple: " - r"filename=%s size=\d+ sha256=[A-Fa-f0-9]{64}" - % re.escape(wheel_file_name), result.stdout) + r"filename={filename} size=\d+ sha256=[A-Fa-f0-9]{64}" + .format(filename=re.escape(wheel_file_name)), result.stdout) assert re.search( r"^\s+Stored in directory: ", result.stdout, re.M) assert wheel_file_path in result.files_created, result.stdout @@ -68,7 +68,7 @@ def test_pip_wheel_build_cache(script, data): 'wheel', '--no-index', '-f', data.find_links, 'simple==3.0', ) - wheel_file_name = 'simple-3.0-py%s-none-any.whl' % pyversion[0] + wheel_file_name = 'simple-3.0-py{pyversion[0]}-none-any.whl'.format(**globals()) wheel_file_path = script.scratch / wheel_file_name assert wheel_file_path in result.files_created, result.stdout assert "Successfully built simple" in result.stdout, result.stdout @@ -145,7 +145,7 @@ def test_pip_wheel_builds_editable_deps(script, data): 'wheel', '--no-index', '-f', data.find_links, '-e', editable_path ) - wheel_file_name = 'simple-1.0-py%s-none-any.whl' % pyversion[0] + wheel_file_name = 'simple-1.0-py{pyversion[0]}-none-any.whl'.format(**globals()) wheel_file_path = script.scratch / wheel_file_name assert wheel_file_path in result.files_created, result.stdout @@ -159,7 +159,7 @@ def test_pip_wheel_builds_editable(script, data): 'wheel', '--no-index', '-f', data.find_links, '-e', editable_path ) - wheel_file_name = 'simplewheel-1.0-py%s-none-any.whl' % pyversion[0] + wheel_file_name = 'simplewheel-1.0-py{pyversion[0]}-none-any.whl'.format(**globals()) wheel_file_path = script.scratch / wheel_file_name assert wheel_file_path in result.files_created, result.stdout @@ -173,7 +173,7 @@ def test_pip_wheel_fail(script, data): 'wheelbroken==0.1', expect_error=True, ) - wheel_file_name = 'wheelbroken-0.1-py%s-none-any.whl' % pyversion[0] + wheel_file_name = 'wheelbroken-0.1-py{pyversion[0]}-none-any.whl'.format(**globals()) wheel_file_path = script.scratch / wheel_file_name assert wheel_file_path not in result.files_created, ( wheel_file_path, @@ -191,12 +191,12 @@ def test_no_clean_option_blocks_cleaning_after_wheel(script, data): build = script.venv_path / 'build' result = script.pip( 'wheel', '--no-clean', '--no-index', '--build', build, - '--find-links=%s' % data.find_links, + '--find-links={data.find_links}'.format(**locals()), 'simple', expect_temp=True, ) build = build / 'simple' - assert exists(build), "build/simple should still exist %s" % str(result) + assert exists(build), "build/simple should still exist {result}".format(**locals()) def test_pip_wheel_source_deps(script, data): @@ -209,7 +209,7 @@ def test_pip_wheel_source_deps(script, data): 'wheel', '--no-index', '-f', data.find_links, 'requires_source', ) - wheel_file_name = 'source-1.0-py%s-none-any.whl' % pyversion[0] + wheel_file_name = 'source-1.0-py{pyversion[0]}-none-any.whl'.format(**globals()) wheel_file_path = script.scratch / wheel_file_name assert wheel_file_path in result.files_created, result.stdout assert "Successfully built source" in result.stdout, result.stdout @@ -228,7 +228,7 @@ def test_pip_wheel_fail_cause_of_previous_build_dir(script, data): # When I call pip trying to install things again result = script.pip( - 'wheel', '--no-index', '--find-links=%s' % data.find_links, + 'wheel', '--no-index', '--find-links={data.find_links}'.format(**locals()), '--build', script.venv_path / 'build', 'simple==3.0', expect_error=True, expect_temp=True, ) @@ -248,7 +248,7 @@ def test_wheel_package_with_latin1_setup(script, data): def test_pip_wheel_with_pep518_build_reqs(script, data, common_wheels): result = script.pip('wheel', '--no-index', '-f', data.find_links, '-f', common_wheels, 'pep518==3.0',) - wheel_file_name = 'pep518-3.0-py%s-none-any.whl' % pyversion[0] + wheel_file_name = 'pep518-3.0-py{pyversion[0]}-none-any.whl'.format(**globals()) wheel_file_path = script.scratch / wheel_file_name assert wheel_file_path in result.files_created, result.stdout assert "Successfully built pep518" in result.stdout, result.stdout @@ -261,7 +261,7 @@ def test_pip_wheel_with_pep518_build_reqs_no_isolation(script, data): 'wheel', '--no-index', '-f', data.find_links, '--no-build-isolation', 'pep518==3.0', ) - wheel_file_name = 'pep518-3.0-py%s-none-any.whl' % pyversion[0] + wheel_file_name = 'pep518-3.0-py{pyversion[0]}-none-any.whl'.format(**globals()) wheel_file_path = script.scratch / wheel_file_name assert wheel_file_path in result.files_created, result.stdout assert "Successfully built pep518" in result.stdout, result.stdout @@ -289,7 +289,7 @@ def test_pep517_wheels_are_not_confused_with_other_files(script, tmpdir, data): result = script.pip('wheel', pkg_to_wheel, '-w', script.scratch_path) assert "Installing build dependencies" in result.stdout, result.stdout - wheel_file_name = 'withpyproject-0.0.1-py%s-none-any.whl' % pyversion[0] + wheel_file_name = 'withpyproject-0.0.1-py{pyversion[0]}-none-any.whl'.format(**globals()) wheel_file_path = script.scratch / wheel_file_name assert wheel_file_path in result.files_created, result.stdout @@ -303,6 +303,6 @@ def test_legacy_wheels_are_not_confused_with_other_files(script, tmpdir, data): result = script.pip('wheel', pkg_to_wheel, '-w', script.scratch_path) assert "Installing build dependencies" not in result.stdout, result.stdout - wheel_file_name = 'simplewheel-1.0-py%s-none-any.whl' % pyversion[0] + wheel_file_name = 'simplewheel-1.0-py{pyversion[0]}-none-any.whl'.format(**globals()) wheel_file_path = script.scratch / wheel_file_name assert wheel_file_path in result.files_created, result.stdout diff --git a/tests/lib/__init__.py b/tests/lib/__init__.py index c0baa0a1cfb..7bece427099 100644 --- a/tests/lib/__init__.py +++ b/tests/lib/__init__.py @@ -285,14 +285,16 @@ def assert_installed(self, pkg_name, editable=True, with_files=[], if without_egg_link: if egg_link_path in self.files_created: raise TestFailure( - 'unexpected egg link file created: %r\n%s' % - (egg_link_path, self) + 'unexpected egg link file created: ' + '{egg_link_path!r}\n{self}' + .format(**locals()) ) else: if egg_link_path not in self.files_created: raise TestFailure( - 'expected egg link file missing: %r\n%s' % - (egg_link_path, self) + 'expected egg link file missing: ' + '{egg_link_path!r}\n{self}' + .format(**locals()) ) egg_link_file = self.files_created[egg_link_path] @@ -301,15 +303,15 @@ def assert_installed(self, pkg_name, editable=True, with_files=[], # FIXME: I don't understand why there's a trailing . here if not (egg_link_contents.endswith('\n.') and egg_link_contents[:-2].endswith(pkg_dir)): - raise TestFailure(textwrap.dedent(u'''\ - Incorrect egg_link file %r - Expected ending: %r + raise TestFailure(textwrap.dedent( + u'''\ + Incorrect egg_link file {egg_link_file!r} + Expected ending: {expected_ending!r} ------- Actual contents ------- - %s - -------------------------------''' % ( - egg_link_file, - pkg_dir + '\n.', - repr(egg_link_contents)) + {egg_link_contents!r} + -------------------------------'''.format( + expected_ending=pkg_dir + '\n.', + **locals()) )) if use_user_site: @@ -318,8 +320,10 @@ def assert_installed(self, pkg_name, editable=True, with_files=[], pth_file = e.site_packages / 'easy-install.pth' if (pth_file in self.files_updated) == without_egg_link: - raise TestFailure('%r unexpectedly %supdated by install' % ( - pth_file, (not without_egg_link and 'not ' or ''))) + raise TestFailure( + '{pth_file} unexpectedly {maybe}updated by install'.format( + maybe=not without_egg_link and 'not ' or '', + **locals())) if (pkg_dir in self.files_created) == (curdir in without_files): raise TestFailure(textwrap.dedent('''\