Skip to content

Commit

Permalink
Apply ruff rule RUF010 (#1407)
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitriPapadopoulos committed May 13, 2024
1 parent 5eed479 commit 7f16bc1
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 33 deletions.
12 changes: 6 additions & 6 deletions scripts/update_package_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def update_test_packages_cache(package_list_dir_path: Path, pipx_package_cache_p

if not platform_package_list_path.exists():
print(
f"WARNING. File {str(platform_package_list_path)}\n" " does not exist. Creating now...",
f"WARNING. File {platform_package_list_path!s}\n" " does not exist. Creating now...",
file=sys.stderr,
)
create_list_returncode = create_test_packages_list(
Expand All @@ -73,14 +73,14 @@ def update_test_packages_cache(package_list_dir_path: Path, pipx_package_cache_p
)
if create_list_returncode == 0:
print(
f"File {str(platform_package_list_path)}\n"
f"File {platform_package_list_path!s}\n"
" successfully created. Please check this file in to the"
" repository for future use.",
file=sys.stderr,
)
else:
print(
f"ERROR. Unable to create {str(platform_package_list_path)}\n" " Cannot continue.\n",
f"ERROR. Unable to create {platform_package_list_path!s}\n" " Cannot continue.\n",
file=sys.stderr,
)
return 1
Expand All @@ -89,17 +89,17 @@ def update_test_packages_cache(package_list_dir_path: Path, pipx_package_cache_p
platform_package_list_fh = platform_package_list_path.open("r")
except OSError:
print(
f"ERROR. File {str(platform_package_list_path)}\n" " is not readable. Cannot continue.\n",
f"ERROR. File {platform_package_list_path!s}\n" " is not readable. Cannot continue.\n",
file=sys.stderr,
)
return 1
else:
platform_package_list_fh.close()

print("Using the following file to specify needed package files:")
print(f" {str(platform_package_list_path)}")
print(f" {platform_package_list_path!s}")
print("Ensuring the following directory contains necessary package files:")
print(f" {str(packages_dir_path)}")
print(f" {packages_dir_path!s}")

packages_dir_hits = []
packages_dir_missing = []
Expand Down
14 changes: 7 additions & 7 deletions src/pipx/commands/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def _copy_package_resource(dest_dir: Path, path: Path, suffix: str = "") -> None
if not dest.parent.is_dir():
mkdir(dest.parent)
if dest.exists():
logger.warning(f"{hazard} Overwriting file {str(dest)} with {str(src)}")
logger.warning(f"{hazard} Overwriting file {dest!s} with {src!s}")
safe_unlink(dest)
if src.exists():
shutil.copy(src, dest)
Expand All @@ -129,7 +129,7 @@ def _symlink_package_resource(
mkdir(symlink_path.parent)

if force:
logger.info(f"Force is true. Removing {str(symlink_path)}.")
logger.info(f"Force is true. Removing {symlink_path!s}.")
try:
symlink_path.unlink()
except FileNotFoundError:
Expand All @@ -141,21 +141,21 @@ def _symlink_package_resource(
is_symlink = symlink_path.is_symlink()
if exists:
if symlink_path.samefile(path):
logger.info(f"Same path {str(symlink_path)} and {str(path)}")
logger.info(f"Same path {symlink_path!s} and {path!s}")
else:
logger.warning(
pipx_wrap(
f"""
{hazard} File exists at {str(symlink_path)} and points
to {symlink_path.resolve()}, not {str(path)}. Not
{hazard} File exists at {symlink_path!s} and points
to {symlink_path.resolve()}, not {path!s}. Not
modifying.
""",
subsequent_indent=" " * 4,
)
)
return
if is_symlink and not exists:
logger.info(f"Removing existing symlink {str(symlink_path)} since it " "pointed non-existent location")
logger.info(f"Removing existing symlink {symlink_path!s} since it " "pointed non-existent location")
symlink_path.unlink()

if executable:
Expand Down Expand Up @@ -186,7 +186,7 @@ def venv_health_check(venv: Venv, package_name: Optional[str] = None) -> Tuple[V
if not python_path.is_file():
return (
VenvProblems(invalid_interpreter=True),
f" package {red(bold(venv_dir.name))} has invalid " f"interpreter {str(python_path)}\r{hazard}",
f" package {red(bold(venv_dir.name))} has invalid " f"interpreter {python_path!s}\r{hazard}",
)
if not venv.package_metadata:
return (
Expand Down
4 changes: 2 additions & 2 deletions src/pipx/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,15 @@ def _is_temporary_venv_expired(venv_dir: Path) -> bool:
def _prepare_venv_cache(venv: Venv, bin_path: Optional[Path], use_cache: bool) -> None:
venv_dir = venv.root
if not use_cache and (bin_path is None or bin_path.exists()):
logger.info(f"Removing cached venv {str(venv_dir)}")
logger.info(f"Removing cached venv {venv_dir!s}")
rmdir(venv_dir)
_remove_all_expired_venvs()


def _remove_all_expired_venvs() -> None:
for venv_dir in Path(paths.ctx.venv_cache).iterdir():
if _is_temporary_venv_expired(venv_dir):
logger.info(f"Removing expired venv {str(venv_dir)}")
logger.info(f"Removing expired venv {venv_dir!s}")
rmdir(venv_dir)


Expand Down
6 changes: 3 additions & 3 deletions src/pipx/commands/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _upgrade_package(
pipx_wrap(
f"""
{display_name} is already at latest version {old_version}
(location: {str(venv.root)})
(location: {venv.root!s})
"""
)
)
Expand All @@ -88,7 +88,7 @@ def _upgrade_package(
pipx_wrap(
f"""
upgraded package {display_name} from {old_version} to
{new_version} (location: {str(venv.root)})
{new_version} (location: {venv.root!s})
"""
)
)
Expand Down Expand Up @@ -133,7 +133,7 @@ def _upgrade_venv(
else:
raise PipxError(
f"""
Package is not installed. Expected to find {str(venv_dir)}, but it
Package is not installed. Expected to find {venv_dir!s}, but it
does not exist.
"""
)
Expand Down
8 changes: 4 additions & 4 deletions src/pipx/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ def prog_name() -> str:
Binaries can either be installed globally into isolated Virtual Environments
or run directly in a temporary Virtual Environment.
Virtual Environment location is {str(paths.ctx.venvs)}.
Symlinks to apps are placed in {str(paths.ctx.bin_dir)}.
Symlinks to manual pages are placed in {str(paths.ctx.man_dir)}.
Virtual Environment location is {paths.ctx.venvs!s}.
Symlinks to apps are placed in {paths.ctx.bin_dir!s}.
Symlinks to manual pages are placed in {paths.ctx.man_dir!s}.
"""
)
Expand Down Expand Up @@ -1055,7 +1055,7 @@ def setup(args: argparse.Namespace) -> None:
pipx_wrap(
f"""
{hazard} A virtual environment for pipx was detected at
{str(old_pipx_venv_location)}. The 'pipx-app' package has been
{old_pipx_venv_location!s}. The 'pipx-app' package has been
renamed back to 'pipx'
(https://github.com/pypa/pipx/issues/82).
""",
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def pipx_local_pypiserver(request, root: Path, tmp_path_factory) -> Iterator[str
check_test_packages_process = subprocess.run(check_test_packages_cmd, check=False, cwd=root)
if check_test_packages_process.returncode != 0:
raise Exception(
f"Directory {str(pipx_cache_dir)} does not contain all "
f"Directory {pipx_cache_dir!s} does not contain all "
"package distribution files necessary to run pipx tests. Please "
"run the following command to populate it: "
f"{' '.join(update_test_packages_cmd)}"
Expand Down
4 changes: 2 additions & 2 deletions tests/test_animate.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def check_animate_output(
print(f"chars_to_test: {chars_to_test}")
for i in range(0, chars_to_test, 40):
i_end = min(i + 40, chars_to_test)
print(f"expected_string[{i}:{i_end}]: {repr(expected_string[i:i_end])}")
print(f"captured.err[{i}:{i_end}] : {repr(captured.err[i:i_end])}")
print(f"expected_string[{i}:{i_end}]: {expected_string[i:i_end]!r}")
print(f"captured.err[{i}:{i_end}] : {captured.err[i:i_end]!r}")

assert captured.err[:chars_to_test] == expected_string[:chars_to_test]

Expand Down
16 changes: 8 additions & 8 deletions tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def test_run_without_requirements(caplog, pipx_temp_env, tmp_path):
textwrap.dedent(
f"""
from pathlib import Path
Path({repr(str(out))}).write_text({repr(test_str)})
Path({str(out)!r}).write_text({test_str!r})
"""
).strip()
)
Expand All @@ -208,7 +208,7 @@ def test_run_with_requirements(caplog, pipx_temp_env, tmp_path):
import certifi
# Check the installed version
from pathlib import Path
Path({repr(str(out))}).write_text(requests.__version__)
Path({str(out)!r}).write_text(requests.__version__)
"""
).strip(),
encoding="utf-8",
Expand All @@ -234,7 +234,7 @@ def test_run_with_requirements_old(caplog, pipx_temp_env, tmp_path):
import certifi
# Check the installed version
from pathlib import Path
Path({repr(str(out))}).write_text(requests.__version__)
Path({str(out)!r}).write_text(requests.__version__)
"""
).strip(),
encoding="utf-8",
Expand Down Expand Up @@ -270,7 +270,7 @@ def test_run_with_args(caplog, pipx_temp_env, tmp_path):
f"""
import sys
from pathlib import Path
Path({repr(str(out))}).write_text(str(int(sys.argv[1]) + 1))
Path({str(out)!r}).write_text(str(int(sys.argv[1]) + 1))
"""
).strip()
)
Expand All @@ -291,7 +291,7 @@ def test_run_with_requirements_and_args(caplog, pipx_temp_env, tmp_path):
import packaging
import sys
from pathlib import Path
Path({repr(str(out))}).write_text(str(int(sys.argv[1]) + 1))
Path({str(out)!r}).write_text(str(int(sys.argv[1]) + 1))
"""
).strip()
)
Expand Down Expand Up @@ -343,7 +343,7 @@ def test_run_script_by_absolute_name(caplog, pipx_temp_env, tmp_path):
textwrap.dedent(
f"""
from pathlib import Path
Path({repr(str(out))}).write_text({repr(test_str)})
Path({str(out)!r}).write_text({test_str!r})
"""
).strip()
)
Expand All @@ -360,7 +360,7 @@ def test_run_script_by_relative_name(caplog, pipx_temp_env, monkeypatch, tmp_pat
textwrap.dedent(
f"""
from pathlib import Path
Path({repr(str(out))}).write_text({repr(test_str)})
Path({str(out)!r}).write_text({test_str!r})
"""
).strip()
)
Expand All @@ -380,7 +380,7 @@ def test_run_with_windows_python_version(caplog, pipx_temp_env, tmp_path):
f"""
import sys
from pathlib import Path
Path({repr(str(out))}).write_text(sys.version)
Path({str(out)!r}).write_text(sys.version)
"""
).strip()
)
Expand Down

0 comments on commit 7f16bc1

Please sign in to comment.