Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ruff-complaints #5807

Merged
merged 11 commits into from
Jul 23, 2023
1 change: 1 addition & 0 deletions news/5807.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix all ruff linter warnings
9 changes: 2 additions & 7 deletions pipenv/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions pipenv/routines/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 3 additions & 4 deletions pipenv/routines/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
13 changes: 5 additions & 8 deletions pipenv/routines/outdated.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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))
5 changes: 1 addition & 4 deletions pipenv/shells.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 1 addition & 3 deletions pipenv/utils/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 3 additions & 7 deletions tasks/vendoring/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down Expand Up @@ -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()]
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/test_install_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions tests/integration/test_install_twists.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/test_install_uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,16 +219,16 @@ 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
name = "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
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/test_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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"

Expand All @@ -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")
Expand Down
17 changes: 7 additions & 10 deletions tests/integration/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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"

Expand All @@ -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
Expand Down
Loading