From 7f16bc1987bef8b3c4db9bc9f207d6e892941fb5 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos Orfanos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Mon, 13 May 2024 19:16:27 +0200 Subject: [PATCH] Apply ruff rule RUF010 (#1407) --- scripts/update_package_cache.py | 12 ++++++------ src/pipx/commands/common.py | 14 +++++++------- src/pipx/commands/run.py | 4 ++-- src/pipx/commands/upgrade.py | 6 +++--- src/pipx/main.py | 8 ++++---- tests/conftest.py | 2 +- tests/test_animate.py | 4 ++-- tests/test_run.py | 16 ++++++++-------- 8 files changed, 33 insertions(+), 33 deletions(-) diff --git a/scripts/update_package_cache.py b/scripts/update_package_cache.py index be4076b177..5f430c6b50 100644 --- a/scripts/update_package_cache.py +++ b/scripts/update_package_cache.py @@ -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( @@ -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 @@ -89,7 +89,7 @@ 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 @@ -97,9 +97,9 @@ def update_test_packages_cache(package_list_dir_path: Path, pipx_package_cache_p 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 = [] diff --git a/src/pipx/commands/common.py b/src/pipx/commands/common.py index 40aaabe2c4..582bbdf83d 100644 --- a/src/pipx/commands/common.py +++ b/src/pipx/commands/common.py @@ -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) @@ -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: @@ -141,13 +141,13 @@ 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, @@ -155,7 +155,7 @@ def _symlink_package_resource( ) 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: @@ -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 ( diff --git a/src/pipx/commands/run.py b/src/pipx/commands/run.py index 78706918f5..c68dfcf8a2 100644 --- a/src/pipx/commands/run.py +++ b/src/pipx/commands/run.py @@ -304,7 +304,7 @@ 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() @@ -312,7 +312,7 @@ def _prepare_venv_cache(venv: Venv, bin_path: Optional[Path], use_cache: bool) - 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) diff --git a/src/pipx/commands/upgrade.py b/src/pipx/commands/upgrade.py index b074f8d842..f69f154a7f 100644 --- a/src/pipx/commands/upgrade.py +++ b/src/pipx/commands/upgrade.py @@ -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}) """ ) ) @@ -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}) """ ) ) @@ -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. """ ) diff --git a/src/pipx/main.py b/src/pipx/main.py index de2b74d600..0846d357af 100644 --- a/src/pipx/main.py +++ b/src/pipx/main.py @@ -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}. """ ) @@ -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). """, diff --git a/tests/conftest.py b/tests/conftest.py index d88b771ca7..7b3b250d2c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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)}" diff --git a/tests/test_animate.py b/tests/test_animate.py index 08e9b69140..683bf24ac7 100644 --- a/tests/test_animate.py +++ b/tests/test_animate.py @@ -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] diff --git a/tests/test_run.py b/tests/test_run.py index 564acc6076..489ee65c1d 100644 --- a/tests/test_run.py +++ b/tests/test_run.py @@ -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() ) @@ -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", @@ -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", @@ -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() ) @@ -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() ) @@ -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() ) @@ -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() ) @@ -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() )