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

Apply assorted ruff rules #1415

Merged
merged 8 commits into from
May 20, 2024
Empty file modified get-pipx.py
100644 → 100755
Empty file.
Empty file modified scripts/generate_man.py
100644 → 100755
Empty file.
4 changes: 1 addition & 3 deletions scripts/list_test_packages.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ def process_command_line(argv: List[str]) -> argparse.Namespace:
# switches/options:
parser.add_argument("-v", "--verbose", action="store_true", help="Maximum verbosity, especially for pip operations.")

args = parser.parse_args(argv)

return args
return parser.parse_args(argv)


def parse_package_list(package_list_file: Path) -> List[Dict[str, Any]]:
Expand Down
Empty file modified scripts/migrate_pipsi_to_pipx.py
100644 → 100755
Empty file.
6 changes: 2 additions & 4 deletions scripts/test_packages_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@


def get_platform_list_path(package_list_dir_path: Path) -> Path:
platform_package_list_path = package_list_dir_path / f"{FULL_PLATFORM}-python{PYTHON_VERSION_STR}.txt"
return platform_package_list_path
return package_list_dir_path / f"{FULL_PLATFORM}-python{PYTHON_VERSION_STR}.txt"


def get_platform_packages_dir_path(pipx_package_cache_path: Path) -> Path:
platform_packages_dir_path = pipx_package_cache_path / f"{PYTHON_VERSION_STR}"
return platform_packages_dir_path
return pipx_package_cache_path / f"{PYTHON_VERSION_STR}"
9 changes: 5 additions & 4 deletions scripts/update_package_cache.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,11 @@ def update_test_packages_cache(package_list_dir_path: Path, pipx_package_cache_p
package_name = package_spec_re.group(1)
package_ver = package_spec_re.group(2)
package_dist_patt = re.escape(package_name) + r"-" + re.escape(package_ver) + r"(.tar.gz|.zip|-)"
matches = []
for output_dir_file in packages_dir_files:
if re.search(package_dist_patt, output_dir_file.name):
matches.append(output_dir_file)
matches = [
output_dir_file
for output_dir_file in packages_dir_files
if re.search(package_dist_patt, output_dir_file.name)
]
if len(matches) == 1:
packages_dir_files.remove(matches[0])
packages_dir_hits.append(matches[0])
Expand Down
19 changes: 9 additions & 10 deletions src/pipx/commands/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,20 +350,19 @@ def _get_list_output(

if new_install and (exposed_binary_names or unavailable_binary_names):
output.append(" These apps are now globally available")
for name in exposed_binary_names:
output.append(f" - {name}")
for name in unavailable_binary_names:
output.append(f" - {red(name)} (symlink missing or pointing to unexpected location)")
output.extend(f" - {name}" for name in exposed_binary_names)
output.extend(
f" - {red(name)} (symlink missing or pointing to unexpected location)" for name in unavailable_binary_names
)
if new_install and (exposed_man_pages or unavailable_man_pages):
output.append(" These manual pages are now globally available")
for name in exposed_man_pages:
output.append(f" - {name}")
for name in unavailable_man_pages:
output.append(f" - {red(name)} (symlink missing or pointing to unexpected location)")
output.extend(f" - {name}" for name in exposed_man_pages)
output.extend(
f" - {red(name)} (symlink missing or pointing to unexpected location)" for name in unavailable_man_pages
)
if injected_packages:
output.append(" Injected Packages:")
for name in injected_packages:
output.append(f" - {name} {injected_packages[name].package_version}")
output.extend(f" - {name} {injected_packages[name].package_version}" for name in injected_packages)
return "\n".join(output)


Expand Down
3 changes: 1 addition & 2 deletions src/pipx/commands/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ def list_interpreters(
used_in = get_interpreter_users(interpreter, venvs)
if used_in:
output.append(" Used in:")
for p in used_in:
output.append(f" - {p.main_package.package} {p.main_package.package_version}")
output.extend(f" - {p.main_package.package} {p.main_package.package_version}" for p in used_in)
else:
output.append(" Unused")

Expand Down
6 changes: 2 additions & 4 deletions src/pipx/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
def has_venv() -> bool:
try:
import venv # noqa: F401

return True
except ImportError:
return False
return True


class InterpreterResolutionError(PipxError):
Expand Down Expand Up @@ -102,8 +101,7 @@ def find_python_interpreter(python_version: str, fetch_missing_python: bool = Fa

if fetch_missing_python or FETCH_MISSING_PYTHON:
try:
standalone_executable = download_python_build_standalone(python_version)
return standalone_executable
return download_python_build_standalone(python_version)
except PipxError as e:
raise InterpreterResolutionError(source="the python-build-standalone project", version=python_version) from e

Expand Down
6 changes: 2 additions & 4 deletions src/pipx/package_specifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ def parse_specifier_for_metadata(package_spec: str) -> str:
* Convert local paths to absolute paths
"""
parsed_package = _parse_specifier(package_spec)
package_or_url = _parsed_package_to_package_or_url(parsed_package, remove_version_specifiers=False)
return package_or_url
return _parsed_package_to_package_or_url(parsed_package, remove_version_specifiers=False)


def parse_specifier_for_upgrade(package_spec: str) -> str:
Expand All @@ -185,8 +184,7 @@ def parse_specifier_for_upgrade(package_spec: str) -> str:
* Convert local paths to absolute paths
"""
parsed_package = _parse_specifier(package_spec)
package_or_url = _parsed_package_to_package_or_url(parsed_package, remove_version_specifiers=True)
return package_or_url
return _parsed_package_to_package_or_url(parsed_package, remove_version_specifiers=True)


def get_extras(package_spec: str) -> Set[str]:
Expand Down
2 changes: 1 addition & 1 deletion src/pipx/pipx_metadata_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def default(self, obj: Any) -> Any:


def _json_decoder_object_hook(json_dict: Dict[str, Any]) -> Union[Dict[str, Any], Path]:
if json_dict.get("__type__", None) == "Path" and "__Path__" in json_dict:
if json_dict.get("__type__") == "Path" and "__Path__" in json_dict:
return Path(json_dict["__Path__"])
return json_dict

Expand Down
3 changes: 1 addition & 2 deletions src/pipx/standalone_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def list_pythons(use_cache: bool = True) -> Dict[str, str]:
python_version = match[1]
python_versions[python_version] = link

sorted_python_versions = {
return {
version: python_versions[version]
for version in sorted(
python_versions,
Expand All @@ -184,7 +184,6 @@ def list_pythons(use_cache: bool = True) -> Dict[str, str]:
reverse=True,
)
}
return sorted_python_versions


def resolve_python_version(requested_version: str):
Expand Down
6 changes: 3 additions & 3 deletions src/pipx/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def run_subprocess(
stdout=subprocess.PIPE if capture_stdout else None,
stderr=subprocess.PIPE if capture_stderr else None,
encoding="utf-8",
universal_newlines=True,
text=True,
check=False,
cwd=run_dir,
)
Expand Down Expand Up @@ -381,7 +381,7 @@ def exec_app(
stdout=None,
stderr=None,
encoding="utf-8",
universal_newlines=True,
text=True,
check=False,
).returncode
)
Expand Down Expand Up @@ -427,6 +427,6 @@ def is_paths_relative(path: Path, parent: Path):
# Can be replaced with path.is_relative_to() if support for python3.8 is dropped
try:
path.resolve().relative_to(parent.resolve())
return True
except ValueError:
return False
return True
4 changes: 1 addition & 3 deletions src/pipx/venv_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def inspect_venv(
str(Path(dep_path.parent.name) / dep_path.name) for dep_path in man_paths_of_dependencies[dep]
]

venv_metadata = VenvMetadata(
return VenvMetadata(
apps=apps,
app_paths=app_paths,
apps_of_dependencies=apps_of_dependencies,
Expand All @@ -317,5 +317,3 @@ def inspect_venv(
package_version=root_dist.version,
python_version=venv_python_version,
)

return venv_metadata
4 changes: 1 addition & 3 deletions tests/package_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@


def _exe_if_win(apps):
app_strings = []
app_strings = [f"{app}.exe" if WIN else app for app in apps]
return app_strings
return [f"{app}.exe" if WIN else app for app in apps]


# Versions of all packages possibly used in our tests
Expand Down
6 changes: 2 additions & 4 deletions tests/test_install_all_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,16 +214,14 @@ def format_report_table_row(package_data: PackageData) -> str:
else:
sys_install_time = ""

row_string = (
return (
f"{package_data.package_spec:24}{package_data.overall_pf_str:12}"
f"{package_data.clear_pip_pf_str:8}{package_data.clear_pipx_pf_str:8}"
f"{clear_install_time:8}"
f"{package_data.sys_pip_pf_str:8}{package_data.sys_pipx_pf_str:8}"
f"{sys_install_time:8}"
)

return row_string


def format_report_table_footer(module_globals: ModuleGlobalsData) -> str:
fail_list = []
Expand Down Expand Up @@ -272,7 +270,7 @@ def verify_installed_resources(
resource_name_long = {"app": "apps", "man": "manual pages"}[resource_type]
package_resources = PKG[package_name][resource_name].copy()
if deps:
package_resources += PKG[package_name]["%s_of_dependencies" % resource_name]
package_resources += PKG[package_name][f"{resource_name}_of_dependencies"]
if len(package_resources) == 0:
return True

Expand Down