pre-commit-uv
Advanced tools
+2
-2
| Metadata-Version: 2.4 | ||
| Name: pre-commit-uv | ||
| Version: 4.2.0 | ||
| Version: 4.2.1 | ||
| Summary: Run pre-commit with uv | ||
| Project-URL: Bug Tracker, https://github.com/tox-dev/pre-commit-uv/issues | ||
| Project-URL: Changelog, https://github.com/tox-dev/pre-commit-uv/releases | ||
| Project-URL: Source Code, https://github.com/tox-dev/pre-commit-uv | ||
| Project-URL: Documentation, https://github.com/tox-dev/pre-commit-uv/ | ||
| Project-URL: Source Code, https://github.com/tox-dev/pre-commit-uv | ||
| Author-email: Bernat Gabor <gaborjbernat@gmail.com> | ||
@@ -10,0 +10,0 @@ License: Permission is hereby granted, free of charge, to any person obtaining a |
+8
-7
@@ -47,4 +47,4 @@ [build-system] | ||
| urls."Changelog" = "https://github.com/tox-dev/pre-commit-uv/releases" | ||
| urls."Source Code" = "https://github.com/tox-dev/pre-commit-uv" | ||
| urls.Documentation = "https://github.com/tox-dev/pre-commit-uv/" | ||
| urls."Source Code" = "https://github.com/tox-dev/pre-commit-uv" | ||
@@ -81,2 +81,3 @@ [tool.hatch] | ||
| "ISC001", # Conflict with formatter | ||
| "RUF067", # `__init__` module should only contain docstrings and re-exports | ||
| "S104", # Possible binding to all interfaces | ||
@@ -115,4 +116,6 @@ ] | ||
| [tool.coverage] | ||
| html.show_contexts = true | ||
| html.skip_covered = false | ||
| run.parallel = true | ||
| run.plugins = [ | ||
| "covdefaults", | ||
| ] | ||
| paths.source = [ | ||
@@ -128,6 +131,4 @@ "src", | ||
| report.fail_under = 63 | ||
| run.parallel = true | ||
| run.plugins = [ | ||
| "covdefaults", | ||
| ] | ||
| html.show_contexts = true | ||
| html.skip_covered = false | ||
@@ -134,0 +135,0 @@ [tool.mypy] |
@@ -12,2 +12,18 @@ """Package root.""" | ||
| def _is_calling_pre_commit() -> bool: | ||
| if "FORCE_PRE_COMMIT_UV_PATCH" in os.environ: | ||
| return True | ||
| if not sys.argv or not sys.argv[0]: | ||
| return False | ||
| # case when pre-commit is called via python -m pre_commit | ||
| if sys.argv[0] == "-m" and "-m" in sys.orig_argv and "pre_commit" in sys.orig_argv: | ||
| return True | ||
| calling = sys.argv[1] if sys.argv[0] == sys.executable and len(sys.argv) >= 1 else sys.argv[0] | ||
| # case when pre-commit is called directly | ||
| if os.path.split(calling)[1] == f"pre-commit{'.exe' if sys.platform == 'win32' else ''}": | ||
| return True | ||
| # case when pre-commit is called due to a git commit | ||
| return "-m" in sys.argv and "hook-impl" in sys.argv | ||
| def _patch() -> None: | ||
@@ -17,13 +33,4 @@ global _original_main | ||
| return | ||
| calling_pre_commit = "FORCE_PRE_COMMIT_UV_PATCH" in os.environ | ||
| if not calling_pre_commit and sys.argv and sys.argv[0]: # must have arguments | ||
| calling = sys.argv[1] if sys.argv[0] == sys.executable and len(sys.argv) >= 1 else sys.argv[0] | ||
| if ( | ||
| os.path.split(calling)[1] == f"pre-commit{'.exe' if sys.platform == 'win32' else ''}" | ||
| # case when pre-commit is called due to a git commit | ||
| or ("-m" in sys.argv and "hook-impl" in sys.argv) | ||
| ): | ||
| calling_pre_commit = True | ||
| if calling_pre_commit and os.environ.get("DISABLE_PRE_COMMIT_UV_PATCH") is None: | ||
| if _is_calling_pre_commit() and os.environ.get("DISABLE_PRE_COMMIT_UV_PATCH") is None: | ||
| from pre_commit import main # noqa: PLC0415 | ||
@@ -79,2 +86,3 @@ | ||
| "venv", | ||
| "--seed", | ||
| environment_dir(prefix, python.ENVIRONMENT_DIR, version), | ||
@@ -81,0 +89,0 @@ "-p", |
+18
-2
| from __future__ import annotations | ||
| import sys | ||
| from importlib.metadata import version | ||
@@ -50,4 +51,4 @@ from subprocess import check_call, check_output | ||
| def test_call_as_module() -> None: | ||
| run_result = check_output(["python3", "-m", "pre_commit", "run", "-a", "--color", "never"], encoding="utf-8") | ||
| assert f"[INFO] Using pre-commit with uv {uv} via pre-commit-uv {self}" not in run_result.splitlines() | ||
| run_result = check_output([sys.executable, "-m", "pre_commit", "run", "-a", "--color", "never"], encoding="utf-8") | ||
| assert f"[INFO] Using pre-commit with uv {uv} via pre-commit-uv {self}" in run_result.splitlines() | ||
@@ -72,2 +73,17 @@ | ||
| def test_install_seeds_pip(git_repo: Path, monkeypatch: pytest.MonkeyPatch) -> None: | ||
| monkeypatch.setenv("FORCE_PRE_COMMIT_UV_PATCH", "1") | ||
| import pre_commit_uv # noqa: PLC0415 | ||
| pre_commit_uv._patch() # noqa: SLF001 | ||
| main.main(["install-hooks", "-c", str(git_repo / precommit_file)]) | ||
| env_dirs = list((git_repo / "store").rglob("py_env-*")) | ||
| assert env_dirs, "expected at least one hook environment" | ||
| py = next((env_dirs[0] / "bin").glob("python*")) | ||
| result = check_output([str(py), "-c", "import pip"], encoding="utf-8") | ||
| assert not result | ||
| test_install_with_uv_config_cases: list[tuple[str, str]] = [ | ||
@@ -74,0 +90,0 @@ ( |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
23780
3.78%246
7.42%