Skip to content

Commit

Permalink
chore: update pre-commit and modernize Ruff config (#1098)
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii authored Nov 30, 2023
1 parent 038361e commit dd441b9
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 20 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
6 changes: 3 additions & 3 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
DOC_DEPENDENCIES = [".", "jinja2", "mkdocs", "mkdocs-material"]
MAN_DEPENDENCIES = [".", "argparse-manpage[setuptools]"]
LINT_DEPENDENCIES = [
"black==22.8.0",
"mypy==1.1.1",
"black==23.10.1",
"mypy==1.6.1",
"packaging>=20.0",
"ruff==0.0.254",
"ruff==0.1.3",
"types-jinja2",
]
# Packages whose dependencies need an intact system PATH to compile
Expand Down
16 changes: 11 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,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 @@ -65,21 +68,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
2 changes: 1 addition & 1 deletion 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
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 dd441b9

Please sign in to comment.