From bf279c1595434fff91c5ab7564b15e6260d0182c Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Fri, 21 Jul 2023 22:38:36 -0400 Subject: [PATCH 01/10] Start fixing ruff-complaints --- pipenv/exceptions.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/pipenv/exceptions.py b/pipenv/exceptions.py index b5bd7af7ec..69ae741517 100644 --- a/pipenv/exceptions.py +++ b/pipenv/exceptions.py @@ -73,9 +73,7 @@ def show(self, file=None): if isinstance(self.extra, str): self.extra = [self.extra] for extra in self.extra: - extra = "[pipenv.exceptions.{!s}]: {}".format( - self.__class__.__name__, extra - ) + extra = f"[pipenv.exceptions.{self.__class__.__name__}]: {extra}" click.echo(extra, file=file) click.echo(f"{self.message}", file=file) @@ -164,10 +162,7 @@ def show(self, file=None): click.echo(extra, file=file) hint = "" if self.cmd is not None and self.cmd.get_help_option(self.ctx) is not None: - hint = 'Try "{} {}" for help.\n'.format( - self.ctx.command_path, - self.ctx.help_option_names[0], - ) + hint = f'Try "{self.ctx.command_path} {self.ctx.help_option_names[0]}" for help.\n' if self.ctx is not None: click.echo(self.ctx.get_usage() + "\n%s" % hint, file=file, color=color) click.echo(self.message, file=file) From 22bdaba9a7f38f68605ea5ab341df9a12314a43e Mon Sep 17 00:00:00 2001 From: Oz Tiram Date: Sun, 23 Jul 2023 07:56:59 +0200 Subject: [PATCH 02/10] Fix ruff warnings in tasks/vendoring/__init__.py --- tasks/vendoring/__init__.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/tasks/vendoring/__init__.py b/tasks/vendoring/__init__.py index 7b2d7c51ea..5282288de3 100644 --- a/tasks/vendoring/__init__.py +++ b/tasks/vendoring/__init__.py @@ -296,10 +296,7 @@ def install(ctx, vendor_dir, package=None): # are added to vendor.txt, this includes all dependencies recursively up # the chain. ctx.run( - "pip install -t {} --no-compile --no-deps --upgrade {}".format( - vendor_dir.as_posix(), - requirement, - ) + f"pip install -t {vendor_dir.as_posix()} --no-compile --no-deps --upgrade {requirement}" ) # read licenses from distinfo files if possible for path in vendor_dir.glob("*.dist-info"): @@ -627,9 +624,8 @@ def license_destination(vendor_dir, libname, filename): override = vendor_dir / LIBRARY_DIRNAMES[libname] if not override.exists() and override.parent.exists(): # for flattened subdeps, specifically backports/weakref.py - return (vendor_dir / override.parent) / "{}.{}".format( - override.name, filename - ) + return (vendor_dir / override.parent) / "{override.name}.{filename}" + license_path = Path(LIBRARY_DIRNAMES[libname]) / filename if license_path.as_posix() in LICENSE_RENAMES: return vendor_dir / LICENSE_RENAMES[license_path.as_posix()] From 0bf2109025f80628350472d8d6fa3928222f4ea0 Mon Sep 17 00:00:00 2001 From: Oz Tiram Date: Sun, 23 Jul 2023 08:02:42 +0200 Subject: [PATCH 03/10] Fix ruff warnning in pipenv/routines/install.py --- pipenv/routines/install.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pipenv/routines/install.py b/pipenv/routines/install.py index d0c5ffc09a..86921a4827 100644 --- a/pipenv/routines/install.py +++ b/pipenv/routines/install.py @@ -715,13 +715,12 @@ def do_init( if new_hash != old_hash: if deploy: click.secho( - "Your Pipfile.lock ({}) is out of date. Expected: ({}).".format( - old_hash[-6:], new_hash[-6:] - ), + "Your Pipfile.lock (old_hash[-6:]) is out of date." + " Expected: ({new_hash[-6:]}).", fg="red", ) raise exceptions.DeployException - elif (system or allow_global) and not (project.s.PIPENV_VIRTUALENV): + if (system or allow_global) and not (project.s.PIPENV_VIRTUALENV): click.secho( "Pipfile.lock ({}) out of date, but installation " "uses {} re-building lockfile must happen in " From fe9742b4dd7bdc7c0297e76774cea3bca0bdfe47 Mon Sep 17 00:00:00 2001 From: Oz Tiram Date: Sun, 23 Jul 2023 08:10:20 +0200 Subject: [PATCH 04/10] Fix ruff warnings in pipenv/routines/outdated.py --- pipenv/routines/outdated.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/pipenv/routines/outdated.py b/pipenv/routines/outdated.py index 95304decf9..5c2c478b74 100644 --- a/pipenv/routines/outdated.py +++ b/pipenv/routines/outdated.py @@ -64,16 +64,15 @@ def do_outdated(project, pypi_mirror=None, pre=False, clear=False): ) rdeps = reverse_deps.get(canonicalize_name(package)) if isinstance(rdeps, Mapping) and "required" in rdeps: - required = " {} required".format(rdeps["required"]) + required = " {rdeps['required']} required" if version: pipfile_version_text = f" ({version} set in Pipfile)" else: pipfile_version_text = " (Unpinned in Pipfile)" click.secho( - "Skipped Update of Package {!s}: {!s} installed,{!s}{!s}, " - "{!s} available.".format( - package, old_version, required, pipfile_version_text, new_version - ), + f"Skipped Update of Package {package!s}:" + f" {old_version!s} installed,{required!s}{pipfile_version_text!s}, " + f"{new_version!s} available.", fg="yellow", err=True, ) @@ -82,8 +81,6 @@ def do_outdated(project, pypi_mirror=None, pre=False, clear=False): sys.exit(0) for package, new_version, old_version in outdated: click.echo( - "Package {!r} out-of-date: {!r} installed, {!r} available.".format( - package, old_version, new_version - ) + f"Package {package!r} out-of-date: {old_version!r} installed, {new_version!r} available." ) sys.exit(bool(outdated)) From 0c72375e5cd0969104eebc9cf4adcab6eea00802 Mon Sep 17 00:00:00 2001 From: Oz Tiram Date: Sun, 23 Jul 2023 08:12:57 +0200 Subject: [PATCH 05/10] Fix ruff warnings pipenv/shells.py --- pipenv/shells.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pipenv/shells.py b/pipenv/shells.py index 24f53e62ce..9520008493 100644 --- a/pipenv/shells.py +++ b/pipenv/shells.py @@ -74,10 +74,7 @@ def __init__(self, cmd): self.args = [] def __repr__(self): - return "{type}(cmd={cmd!r})".format( - type=type(self).__name__, - cmd=self.cmd, - ) + return "{type(self).__name__}(cmd={self.cmd!r})" @contextlib.contextmanager def inject_path(self, venv): From d866aba3878f79513724f98e2dbcb4e1504f4850 Mon Sep 17 00:00:00 2001 From: Oz Tiram Date: Sun, 23 Jul 2023 08:14:21 +0200 Subject: [PATCH 06/10] Fix ruff warnings in pipenv/utils/resolver.py --- pipenv/utils/resolver.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pipenv/utils/resolver.py b/pipenv/utils/resolver.py index a4e975f8a5..4568b30f41 100644 --- a/pipenv/utils/resolver.py +++ b/pipenv/utils/resolver.py @@ -399,9 +399,7 @@ def get_deps_from_req( if req.specifiers: locked_deps[name]["version"] = req.specifiers elif parsed_line.setup_info and parsed_line.setup_info.version: - locked_deps[name]["version"] = "=={}".format( - parsed_line.setup_info.version - ) + locked_deps[name]["version"] = f"=={parsed_line.setup_info.version}" # if not req.is_vcs: locked_deps.update({name: entry}) else: From 0fbb9b30beda417bbe25a36bc16e5dc58a9845fe Mon Sep 17 00:00:00 2001 From: Oz Tiram Date: Sun, 23 Jul 2023 08:22:18 +0200 Subject: [PATCH 07/10] Fix ruff warnings in pipenv/routines/check.py --- pipenv/routines/check.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pipenv/routines/check.py b/pipenv/routines/check.py index 186ca6df50..b9735995c9 100644 --- a/pipenv/routines/check.py +++ b/pipenv/routines/check.py @@ -125,11 +125,11 @@ def do_check( "--exit-code" if exit_code else "--continue-on-error", ] - if output == "full-report": - options.append("--full-report") - elif output == "minimal": - options.append("--json") - elif output not in ["screen", "default"]: + formats = {"full-report": "--full-report", "minimal": "--json"} + if output in formats: + options.append(formats.get(output, "")) + + elif output in ["screen", "default"]: options.append(f"--output={output}") if save_json: From e74a282e091538d46b03b9f786f1d976ef256850 Mon Sep 17 00:00:00 2001 From: Oz Tiram Date: Sun, 23 Jul 2023 08:31:31 +0200 Subject: [PATCH 08/10] Fix ruff warnings in tests/integration --- tests/integration/test_install_misc.py | 6 +++--- tests/integration/test_install_twists.py | 8 +++----- tests/integration/test_install_uri.py | 6 +++--- tests/integration/test_lock.py | 12 ++++++------ tests/integration/test_project.py | 17 +++++++---------- 5 files changed, 22 insertions(+), 27 deletions(-) diff --git a/tests/integration/test_install_misc.py b/tests/integration/test_install_misc.py index e91da8271b..503d409fc4 100644 --- a/tests/integration/test_install_misc.py +++ b/tests/integration/test_install_misc.py @@ -7,15 +7,15 @@ def test_install_uri_with_extras(pipenv_instance_private_pypi): file_uri = "http://localhost:8080/packages/plette/plette-0.2.2-py2.py3-none-any.whl" with pipenv_instance_private_pypi() as p: with open(p.pipfile_path, 'w') as f: - contents = """ + contents = f""" [[source]] -url = "{index}" +url = "{p.index_url}" verify_ssl = false name = "testindex" [packages] plette = {{file = "{file_uri}", extras = ["validation"]}} -""".format(file_uri=file_uri, index=p.index_url) +""" f.write(contents) c = p.pipenv("install") assert c.returncode == 0 diff --git a/tests/integration/test_install_twists.py b/tests/integration/test_install_twists.py index 04370aa38a..79a97e94af 100644 --- a/tests/integration/test_install_twists.py +++ b/tests/integration/test_install_twists.py @@ -210,13 +210,11 @@ def test_install_local_uri_special_character(pipenv_instance_private_pypi, tests os.makedirs(artifact_path, exist_ok=True) shutil.copy(source_path, os.path.join(artifact_path, file_name)) with open(p.pipfile_path, "w") as f: - contents = """ + contents = f""" # Pre comment [packages] -six = {{path = "./artifacts/{}"}} - """.format( - file_name - ) +six = {{path = "./artifacts/{file_name}"}} + """ f.write(contents.strip()) c = p.pipenv("install") assert c.returncode == 0 diff --git a/tests/integration/test_install_uri.py b/tests/integration/test_install_uri.py index 53ed3e1836..1ef124b011 100644 --- a/tests/integration/test_install_uri.py +++ b/tests/integration/test_install_uri.py @@ -219,7 +219,7 @@ def test_vcs_entry_supersedes_non_vcs(pipenv_instance_pypi): jinja2_uri = p._pipfile.get_fixture_path("git/jinja2").as_uri() with open(p.pipfile_path, "w") as f: f.write( - """ + f""" [[source]] url = "https://pypi.org/simple" verify_ssl = true @@ -227,8 +227,8 @@ def test_vcs_entry_supersedes_non_vcs(pipenv_instance_pypi): [packages] Flask = "*" -Jinja2 = {{ref = "2.11.0", git = "{}"}} - """.format(jinja2_uri).strip() +Jinja2 = {{ref = "2.11.0", git = "{jinja2_uri}"}} + """.strip() ) c = p.pipenv("install") assert c.returncode == 0 diff --git a/tests/integration/test_lock.py b/tests/integration/test_lock.py index f3e21c060c..1064f066d8 100644 --- a/tests/integration/test_lock.py +++ b/tests/integration/test_lock.py @@ -477,15 +477,15 @@ def test_vcs_lock_respects_top_level_pins(pipenv_instance_private_pypi): @pytest.mark.lock def test_lock_after_update_source_name(pipenv_instance_pypi): with pipenv_instance_pypi() as p: - contents = """ + contents = f""" [[source]] -url = "{}" +url = "{p.index_url}" verify_ssl = true name = "test" [packages] six = "*" - """.format(p.index_url).strip() + """.strip() with open(p.pipfile_path, 'w') as f: f.write(contents) c = p.pipenv("lock") @@ -644,9 +644,9 @@ def test_dev_lock_use_default_packages_as_constraint(pipenv_instance_private_pyp @pytest.mark.lock def test_lock_specific_named_category(pipenv_instance_private_pypi): with pipenv_instance_private_pypi(pipfile=False) as p: - contents = """ + contents = f""" [[source]] -url = "{}" +url = "{p.index_url}" verify_ssl = true name = "test" @@ -655,7 +655,7 @@ def test_lock_specific_named_category(pipenv_instance_private_pypi): [prereq] six = "*" - """.format(p.index_url).strip() + """.strip() with open(p.pipfile_path, 'w') as f: f.write(contents) c = p.pipenv("lock --categories prereq") diff --git a/tests/integration/test_project.py b/tests/integration/test_project.py index ce80a2a25f..e9067bcc77 100644 --- a/tests/integration/test_project.py +++ b/tests/integration/test_project.py @@ -38,9 +38,9 @@ def test_pipfile_envvar_expansion(pipenv_instance_pypi): def test_get_source(pipenv_instance_private_pypi, lock_first): with pipenv_instance_private_pypi() as p: with open(p.pipfile_path, 'w') as f: - contents = """ + contents = f""" [[source]] -url = "{}" +url = "{p.index_url}" verify_ssl = false name = "testindex" @@ -54,7 +54,7 @@ def test_get_source(pipenv_instance_private_pypi, lock_first): six = {{version = "*", index = "pypi"}} [dev-packages] - """.format(p.index_url).strip() + """.strip() f.write(contents) if lock_first: @@ -106,10 +106,7 @@ def test_maintain_file_line_endings(pipenv_instance_pypi, newlines): with open(fn) as f: f.read() # Consumes the content to detect newlines. actual_newlines = f.newlines - assert actual_newlines == newlines, '{!r} != {!r} for {}'.format( - actual_newlines, newlines, fn, - ) - # message because of https://github.com/pytest-dev/pytest/issues/3443 + assert actual_newlines == newlines, f'{actual_newlines!r} != {newlines!r} for {fn}' @pytest.mark.project @@ -118,9 +115,9 @@ def test_maintain_file_line_endings(pipenv_instance_pypi, newlines): def test_many_indexes(pipenv_instance_pypi): with pipenv_instance_pypi() as p: with open(p.pipfile_path, 'w') as f: - contents = """ + contents = f""" [[source]] -url = "{}" +url = "{p.index_url}" verify_ssl = false name = "testindex" @@ -139,7 +136,7 @@ def test_many_indexes(pipenv_instance_pypi): six = {{version = "*", index = "pypi"}} [dev-packages] - """.format(p.index_url).strip() + """.strip() f.write(contents) c = p.pipenv('install') assert c.returncode == 0 From e8d8dcf24fb0ad1417cfc2b0b599b5cef9919514 Mon Sep 17 00:00:00 2001 From: Oz Tiram Date: Sun, 23 Jul 2023 08:34:16 +0200 Subject: [PATCH 09/10] Add news snippet --- news/5807.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 news/5807.bugfix.rst diff --git a/news/5807.bugfix.rst b/news/5807.bugfix.rst new file mode 100644 index 0000000000..3d00999b1e --- /dev/null +++ b/news/5807.bugfix.rst @@ -0,0 +1 @@ + Fix all ruff linter warnings From 3cf75e8d8fa332fe86c2f0a3b09c905952ca5148 Mon Sep 17 00:00:00 2001 From: Oz Tiram Date: Sun, 23 Jul 2023 20:30:54 +0200 Subject: [PATCH 10/10] Fix refactoring of check routine --- pipenv/routines/check.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipenv/routines/check.py b/pipenv/routines/check.py index b9735995c9..c2f5d12feb 100644 --- a/pipenv/routines/check.py +++ b/pipenv/routines/check.py @@ -129,7 +129,7 @@ def do_check( if output in formats: options.append(formats.get(output, "")) - elif output in ["screen", "default"]: + elif output not in ["screen", "default"]: options.append(f"--output={output}") if save_json: