diff --git a/get-pipx.py b/get-pipx.py old mode 100644 new mode 100755 diff --git a/scripts/generate_man.py b/scripts/generate_man.py old mode 100644 new mode 100755 diff --git a/scripts/list_test_packages.py b/scripts/list_test_packages.py old mode 100644 new mode 100755 index 2dcf5cdbbd..8459f5856b --- a/scripts/list_test_packages.py +++ b/scripts/list_test_packages.py @@ -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]]: diff --git a/scripts/migrate_pipsi_to_pipx.py b/scripts/migrate_pipsi_to_pipx.py old mode 100644 new mode 100755 diff --git a/scripts/test_packages_support.py b/scripts/test_packages_support.py index 0341672870..ee6010ca8b 100644 --- a/scripts/test_packages_support.py +++ b/scripts/test_packages_support.py @@ -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}" diff --git a/scripts/update_package_cache.py b/scripts/update_package_cache.py old mode 100644 new mode 100755 index 32ed45a414..2c33eacb52 --- a/scripts/update_package_cache.py +++ b/scripts/update_package_cache.py @@ -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]) diff --git a/src/pipx/commands/common.py b/src/pipx/commands/common.py index 6f27a9daf6..9f6ebe863e 100644 --- a/src/pipx/commands/common.py +++ b/src/pipx/commands/common.py @@ -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) diff --git a/src/pipx/commands/interpreter.py b/src/pipx/commands/interpreter.py index 4e4b01180c..6fea85b7b1 100644 --- a/src/pipx/commands/interpreter.py +++ b/src/pipx/commands/interpreter.py @@ -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") diff --git a/src/pipx/interpreter.py b/src/pipx/interpreter.py index fda8b1b8cd..1728ad7702 100644 --- a/src/pipx/interpreter.py +++ b/src/pipx/interpreter.py @@ -18,10 +18,9 @@ def has_venv() -> bool: try: import venv # noqa: F401 - - return True except ImportError: return False + return True class InterpreterResolutionError(PipxError): @@ -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 diff --git a/src/pipx/package_specifier.py b/src/pipx/package_specifier.py index 26ced4f471..17304acb87 100644 --- a/src/pipx/package_specifier.py +++ b/src/pipx/package_specifier.py @@ -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: @@ -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]: diff --git a/src/pipx/pipx_metadata_file.py b/src/pipx/pipx_metadata_file.py index 0c3796784c..2f5727f755 100644 --- a/src/pipx/pipx_metadata_file.py +++ b/src/pipx/pipx_metadata_file.py @@ -22,7 +22,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 diff --git a/src/pipx/standalone_python.py b/src/pipx/standalone_python.py index 756b0a4824..465ce2999d 100644 --- a/src/pipx/standalone_python.py +++ b/src/pipx/standalone_python.py @@ -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, @@ -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): diff --git a/src/pipx/util.py b/src/pipx/util.py index e5fd72f276..ff7e51770d 100644 --- a/src/pipx/util.py +++ b/src/pipx/util.py @@ -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, ) @@ -381,7 +381,7 @@ def exec_app( stdout=None, stderr=None, encoding="utf-8", - universal_newlines=True, + text=True, check=False, ).returncode ) @@ -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 diff --git a/src/pipx/venv_inspect.py b/src/pipx/venv_inspect.py index db1eba0b13..3adcaee871 100644 --- a/src/pipx/venv_inspect.py +++ b/src/pipx/venv_inspect.py @@ -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, @@ -317,5 +317,3 @@ def inspect_venv( package_version=root_dist.version, python_version=venv_python_version, ) - - return venv_metadata diff --git a/tests/package_info.py b/tests/package_info.py index 3f2d76dfea..c975f9fa69 100644 --- a/tests/package_info.py +++ b/tests/package_info.py @@ -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 diff --git a/tests/test_install_all_packages.py b/tests/test_install_all_packages.py index 1da8e4dd3c..d1d69b7df0 100644 --- a/tests/test_install_all_packages.py +++ b/tests/test_install_all_packages.py @@ -214,7 +214,7 @@ 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}" @@ -222,8 +222,6 @@ def format_report_table_row(package_data: PackageData) -> str: f"{sys_install_time:8}" ) - return row_string - def format_report_table_footer(module_globals: ModuleGlobalsData) -> str: fail_list = [] @@ -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