Skip to content

Commit

Permalink
chore: update pre-commit and modernize Ruff config
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii committed Nov 1, 2023
1 parent ce27a75 commit a88bf3d
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 22 deletions.
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: end-of-file-fixer
- id: check-added-large-files
- id: trailing-whitespace
- id: check-yaml
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.254
rev: v0.1.3
hooks:
- id: ruff
- repo: https://github.com/psf/black
rev: 23.1.0
rev: 23.10.1
hooks:
- id: black
# mypy args:
Expand All @@ -27,7 +27,7 @@ repos:
# cannot use --warn-unused-ignores because it conflicts with
# --ignore-missing-imports
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.1.1
rev: v1.6.1
hooks:
- id: mypy
args: ['--warn-unused-ignores', '--strict-equality','--no-implicit-optional']
Expand Down
4 changes: 2 additions & 2 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ sudo PIPX_HOME=/opt/pipx PIPX_BIN_DIR=/usr/local/bin pipx install PACKAGE
| `~/.local/pipx/venvs` | `platformdirs.user_data_dir()/pipx/venv` |
| `~/.local/pipx/.cache` | `platformdirs.user_cache_dir()/pipx` |
| `~/.local/pipx/logs` | `platformdirs.user_log_dir()/pipx/log` |
`user_data_dir()`, `user_cache_dir()` and `user_log_dir()` resolve to appropriate platform-specific user data, cache and log directories.

`user_data_dir()`, `user_cache_dir()` and `user_log_dir()` resolve to appropriate platform-specific user data, cache and log directories.
See the [platformdirs documentation](https://platformdirs.readthedocs.io/en/latest/api.html#platforms) for details.

## Upgrade pipx
Expand Down
4 changes: 2 additions & 2 deletions docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ rm -rf test_venv
## Pipx files not in expected locations according to documentation

The default PIPX_HOME is `~/.local/pipx`, prior to the adoption of the XDG base
directory specification after version 1.2.0. To maintain compatibility with older
directory specification after version 1.2.0. To maintain compatibility with older
versions, pipx will automatically detect the old paths and use them accordingly.
For a map of old and new paths, See [Installation](installation.md#installation-options)

To migrate from the old path to the new path, you can remove the `~/.local/pipx` directory and
To migrate from the old path to the new path, you can remove the `~/.local/pipx` directory and
reinstall all packages.

For example, on Linux systems, you could read out `pipx`'s package information in JSON via `jq` (which you might need to install first):
Expand Down
16 changes: 11 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ include = ["/src", "/logo.png", "/pipx_demo.gif", "/*.md"]
skip-magic-trailing-comma = true

[tool.ruff]
line-length = 121

[tool.ruff.lint]
select = [
"A",
"B",
Expand All @@ -67,21 +70,24 @@ select = [
ignore = [
"B904",
]
line-length = 121
show-source = true

[tool.ruff.isort]
[tool.ruff.lint.isort]
known-first-party = ["helpers", "package_info", "pipx"]

[tool.ruff.mccabe]
[tool.ruff.lint.mccabe]
max-complexity = 15

[tool.pytest.ini_options]
markers = ["all_packages: test install with maximum number of packages"]

[tool.mypy]
show_error_codes = true

[[tool.mypy.overrides]]
module = [
"packaging.*",
"platformdirs"
"platformdirs",
"pycowsay.*",
"jinja2",
]
ignore_missing_imports = true
3 changes: 1 addition & 2 deletions scripts/list_test_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def create_test_packages_list(
if verbose:
print(f"CMD: {' '.join(cmd_list)}")
pip_download_process = subprocess.run(
cmd_list, capture_output=True, text=True
cmd_list, capture_output=True, text=True, check=False
)
if pip_download_process.returncode == 0:
print(f"Examined {test_package['spec']}{test_package_option_string}")
Expand Down Expand Up @@ -146,7 +146,6 @@ def create_test_packages_list(
all_packages.append(f"{package_name}=={package_version}")

with platform_package_list_path.open("w") as package_list_fh:
"scripts/list_test_packages.py",
for package in sorted(all_packages):
print(package, file=package_list_fh)

Expand Down
4 changes: 2 additions & 2 deletions scripts/migrate_pipsi_to_pipx.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def main():

error = False
for package in packages:
ret = subprocess.run(["pipsi", "uninstall", "--yes", package])
ret = subprocess.run(["pipsi", "uninstall", "--yes", package], check=False)
if ret.returncode:
error = True
print(
Expand All @@ -49,7 +49,7 @@ def main():
print(
f"uninstalled {package!r} with pipsi. Now attempting to install with pipx."
)
ret = subprocess.run(["pipx", "install", package])
ret = subprocess.run(["pipx", "install", package], check=False)
if ret.returncode:
error = True
print(f"Failed to install {package!r} with pipx.")
Expand Down
2 changes: 1 addition & 1 deletion scripts/pipx_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


def python_mypy_ok(filepath: Path) -> bool:
mypy_proc = subprocess.run(["mypy", filepath])
mypy_proc = subprocess.run(["mypy", filepath], check=False)
return True if mypy_proc.returncode == 0 else False


Expand Down
1 change: 1 addition & 0 deletions scripts/update_package_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def update_test_packages_cache(
],
capture_output=True,
text=True,
check=False,
)
if pip_download_process.returncode == 0:
print(f"Successfully downloaded {package_spec}")
Expand Down
3 changes: 2 additions & 1 deletion src/pipx/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def find_py_launcher_python(python_version: Optional[str] = None) -> Optional[st
[py, f"-{python_version}", "-c", "import sys; print(sys.executable)"],
capture_output=True,
text=True,
check=True,
).stdout.strip()
return py

Expand All @@ -54,7 +55,7 @@ def _find_default_windows_python() -> str:
# https://twitter.com/zooba/status/1212454929379581952

proc = subprocess.run(
[python, "-V"], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL
[python, "-V"], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, check=False
)
if proc.returncode != 0:
# Cover the 9009 return code pre-emptively.
Expand Down
2 changes: 2 additions & 0 deletions src/pipx/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ def run_subprocess(
stderr=subprocess.PIPE if capture_stderr else None,
encoding="utf-8",
universal_newlines=True,
check=False,
)

if capture_stdout and log_stdout:
Expand Down Expand Up @@ -396,6 +397,7 @@ def exec_app(
stderr=None,
encoding="utf-8",
universal_newlines=True,
check=False,
).returncode
)
else:
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def pipx_local_pypiserver(request):
str(PIPX_TESTS_PACKAGE_LIST_DIR),
str(pipx_cache_dir),
]
check_test_packages_process = subprocess.run(check_test_packages_cmd)
check_test_packages_process = subprocess.run(check_test_packages_cmd, check=False)
if check_test_packages_process.returncode != 0:
raise Exception(
f"Directory {str(pipx_cache_dir)} does not contain all "
Expand Down
2 changes: 1 addition & 1 deletion tests/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def test_install_pip_failure(pipx_temp_env, capsys):
def test_install_local_archive(pipx_temp_env, monkeypatch, capsys):
monkeypatch.chdir(Path(TEST_DATA_PATH) / "local_extras")

subprocess.run([sys.executable, "-m", "pip", "wheel", "."])
subprocess.run([sys.executable, "-m", "pip", "wheel", "."], check=True)
assert not run_pipx_cli(["install", "repeatme-0.1-py3-none-any.whl"])
captured = capsys.readouterr()
assert f"- {app_name('repeatme')}\n" in captured.out
Expand Down
2 changes: 1 addition & 1 deletion tests/test_install_all_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def module_globals() -> ModuleGlobalsData:


def pip_cache_purge() -> None:
subprocess.run([sys.executable, "-m", "pip", "cache", "purge"])
subprocess.run([sys.executable, "-m", "pip", "cache", "purge"], check=True)


def write_report_legend(report_legend_path: Path) -> None:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def execvpe_mock(cmd_path, cmd_args, env):
capture_output=False,
encoding="utf-8",
text=True,
check=False,
).returncode
sys.exit(return_code)

Expand Down Expand Up @@ -145,6 +146,7 @@ def test_run_ensure_null_pythonpath():
env=env,
capture_output=True,
text=True,
check=True,
).stdout
)

Expand Down

0 comments on commit a88bf3d

Please sign in to comment.