Skip to content

Commit 4b905e0

Browse files
Apply assorted ruff rules (#1415)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent bab0ea6 commit 4b905e0

16 files changed

+31
-47
lines changed

get-pipx.py

100644100755
File mode changed.

scripts/generate_man.py

100644100755
File mode changed.

scripts/list_test_packages.py

100644100755
+1-3
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ def process_command_line(argv: List[str]) -> argparse.Namespace:
4040
# switches/options:
4141
parser.add_argument("-v", "--verbose", action="store_true", help="Maximum verbosity, especially for pip operations.")
4242

43-
args = parser.parse_args(argv)
44-
45-
return args
43+
return parser.parse_args(argv)
4644

4745

4846
def parse_package_list(package_list_file: Path) -> List[Dict[str, Any]]:

scripts/migrate_pipsi_to_pipx.py

100644100755
File mode changed.

scripts/test_packages_support.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414

1515

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

2019

2120
def get_platform_packages_dir_path(pipx_package_cache_path: Path) -> Path:
22-
platform_packages_dir_path = pipx_package_cache_path / f"{PYTHON_VERSION_STR}"
23-
return platform_packages_dir_path
21+
return pipx_package_cache_path / f"{PYTHON_VERSION_STR}"

scripts/update_package_cache.py

100644100755
+5-4
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,11 @@ def update_test_packages_cache(package_list_dir_path: Path, pipx_package_cache_p
115115
package_name = package_spec_re.group(1)
116116
package_ver = package_spec_re.group(2)
117117
package_dist_patt = re.escape(package_name) + r"-" + re.escape(package_ver) + r"(.tar.gz|.zip|-)"
118-
matches = []
119-
for output_dir_file in packages_dir_files:
120-
if re.search(package_dist_patt, output_dir_file.name):
121-
matches.append(output_dir_file)
118+
matches = [
119+
output_dir_file
120+
for output_dir_file in packages_dir_files
121+
if re.search(package_dist_patt, output_dir_file.name)
122+
]
122123
if len(matches) == 1:
123124
packages_dir_files.remove(matches[0])
124125
packages_dir_hits.append(matches[0])

src/pipx/commands/common.py

+9-10
Original file line numberDiff line numberDiff line change
@@ -350,20 +350,19 @@ def _get_list_output(
350350

351351
if new_install and (exposed_binary_names or unavailable_binary_names):
352352
output.append(" These apps are now globally available")
353-
for name in exposed_binary_names:
354-
output.append(f" - {name}")
355-
for name in unavailable_binary_names:
356-
output.append(f" - {red(name)} (symlink missing or pointing to unexpected location)")
353+
output.extend(f" - {name}" for name in exposed_binary_names)
354+
output.extend(
355+
f" - {red(name)} (symlink missing or pointing to unexpected location)" for name in unavailable_binary_names
356+
)
357357
if new_install and (exposed_man_pages or unavailable_man_pages):
358358
output.append(" These manual pages are now globally available")
359-
for name in exposed_man_pages:
360-
output.append(f" - {name}")
361-
for name in unavailable_man_pages:
362-
output.append(f" - {red(name)} (symlink missing or pointing to unexpected location)")
359+
output.extend(f" - {name}" for name in exposed_man_pages)
360+
output.extend(
361+
f" - {red(name)} (symlink missing or pointing to unexpected location)" for name in unavailable_man_pages
362+
)
363363
if injected_packages:
364364
output.append(" Injected Packages:")
365-
for name in injected_packages:
366-
output.append(f" - {name} {injected_packages[name].package_version}")
365+
output.extend(f" - {name} {injected_packages[name].package_version}" for name in injected_packages)
367366
return "\n".join(output)
368367

369368

src/pipx/commands/interpreter.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ def list_interpreters(
4848
used_in = get_interpreter_users(interpreter, venvs)
4949
if used_in:
5050
output.append(" Used in:")
51-
for p in used_in:
52-
output.append(f" - {p.main_package.package} {p.main_package.package_version}")
51+
output.extend(f" - {p.main_package.package} {p.main_package.package_version}" for p in used_in)
5352
else:
5453
output.append(" Unused")
5554

src/pipx/interpreter.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@
1818
def has_venv() -> bool:
1919
try:
2020
import venv # noqa: F401
21-
22-
return True
2321
except ImportError:
2422
return False
23+
return True
2524

2625

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

103102
if fetch_missing_python or FETCH_MISSING_PYTHON:
104103
try:
105-
standalone_executable = download_python_build_standalone(python_version)
106-
return standalone_executable
104+
return download_python_build_standalone(python_version)
107105
except PipxError as e:
108106
raise InterpreterResolutionError(source="the python-build-standalone project", version=python_version) from e
109107

src/pipx/package_specifier.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,7 @@ def parse_specifier_for_metadata(package_spec: str) -> str:
172172
* Convert local paths to absolute paths
173173
"""
174174
parsed_package = _parse_specifier(package_spec)
175-
package_or_url = _parsed_package_to_package_or_url(parsed_package, remove_version_specifiers=False)
176-
return package_or_url
175+
return _parsed_package_to_package_or_url(parsed_package, remove_version_specifiers=False)
177176

178177

179178
def parse_specifier_for_upgrade(package_spec: str) -> str:
@@ -185,8 +184,7 @@ def parse_specifier_for_upgrade(package_spec: str) -> str:
185184
* Convert local paths to absolute paths
186185
"""
187186
parsed_package = _parse_specifier(package_spec)
188-
package_or_url = _parsed_package_to_package_or_url(parsed_package, remove_version_specifiers=True)
189-
return package_or_url
187+
return _parsed_package_to_package_or_url(parsed_package, remove_version_specifiers=True)
190188

191189

192190
def get_extras(package_spec: str) -> Set[str]:

src/pipx/pipx_metadata_file.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def default(self, obj: Any) -> Any:
2222

2323

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

src/pipx/standalone_python.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def list_pythons(use_cache: bool = True) -> Dict[str, str]:
175175
python_version = match[1]
176176
python_versions[python_version] = link
177177

178-
sorted_python_versions = {
178+
return {
179179
version: python_versions[version]
180180
for version in sorted(
181181
python_versions,
@@ -184,7 +184,6 @@ def list_pythons(use_cache: bool = True) -> Dict[str, str]:
184184
reverse=True,
185185
)
186186
}
187-
return sorted_python_versions
188187

189188

190189
def resolve_python_version(requested_version: str):

src/pipx/util.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def run_subprocess(
185185
stdout=subprocess.PIPE if capture_stdout else None,
186186
stderr=subprocess.PIPE if capture_stderr else None,
187187
encoding="utf-8",
188-
universal_newlines=True,
188+
text=True,
189189
check=False,
190190
cwd=run_dir,
191191
)
@@ -381,7 +381,7 @@ def exec_app(
381381
stdout=None,
382382
stderr=None,
383383
encoding="utf-8",
384-
universal_newlines=True,
384+
text=True,
385385
check=False,
386386
).returncode
387387
)
@@ -427,6 +427,6 @@ def is_paths_relative(path: Path, parent: Path):
427427
# Can be replaced with path.is_relative_to() if support for python3.8 is dropped
428428
try:
429429
path.resolve().relative_to(parent.resolve())
430-
return True
431430
except ValueError:
432431
return False
432+
return True

src/pipx/venv_inspect.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ def inspect_venv(
305305
str(Path(dep_path.parent.name) / dep_path.name) for dep_path in man_paths_of_dependencies[dep]
306306
]
307307

308-
venv_metadata = VenvMetadata(
308+
return VenvMetadata(
309309
apps=apps,
310310
app_paths=app_paths,
311311
apps_of_dependencies=apps_of_dependencies,
@@ -317,5 +317,3 @@ def inspect_venv(
317317
package_version=root_dist.version,
318318
python_version=venv_python_version,
319319
)
320-
321-
return venv_metadata

tests/package_info.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66

77

88
def _exe_if_win(apps):
9-
app_strings = []
10-
app_strings = [f"{app}.exe" if WIN else app for app in apps]
11-
return app_strings
9+
return [f"{app}.exe" if WIN else app for app in apps]
1210

1311

1412
# Versions of all packages possibly used in our tests

tests/test_install_all_packages.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -214,16 +214,14 @@ def format_report_table_row(package_data: PackageData) -> str:
214214
else:
215215
sys_install_time = ""
216216

217-
row_string = (
217+
return (
218218
f"{package_data.package_spec:24}{package_data.overall_pf_str:12}"
219219
f"{package_data.clear_pip_pf_str:8}{package_data.clear_pipx_pf_str:8}"
220220
f"{clear_install_time:8}"
221221
f"{package_data.sys_pip_pf_str:8}{package_data.sys_pipx_pf_str:8}"
222222
f"{sys_install_time:8}"
223223
)
224224

225-
return row_string
226-
227225

228226
def format_report_table_footer(module_globals: ModuleGlobalsData) -> str:
229227
fail_list = []
@@ -272,7 +270,7 @@ def verify_installed_resources(
272270
resource_name_long = {"app": "apps", "man": "manual pages"}[resource_type]
273271
package_resources = PKG[package_name][resource_name].copy()
274272
if deps:
275-
package_resources += PKG[package_name]["%s_of_dependencies" % resource_name]
273+
package_resources += PKG[package_name][f"{resource_name}_of_dependencies"]
276274
if len(package_resources) == 0:
277275
return True
278276

0 commit comments

Comments
 (0)