Skip to content

Commit 0ae8b5d

Browse files
committed
fix: use subprocess
1 parent 78ca05f commit 0ae8b5d

File tree

6 files changed

+36
-6
lines changed

6 files changed

+36
-6
lines changed

.pre-commit-hooks.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
- id: sync-uv-pre-commit
22
name: Sync uv and pre commit
33
description: Sync uv and pre commit
4-
language: script
5-
entry: "uv run script.py"
4+
language: python
5+
entry: sync_uv_pre_commit
66
minimum_pre_commit_version: "3.5.0"
77
require_serial: true
88
always_run: true

pyproject.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@ classifiers = [
1212
"Programming Language :: Python :: 3.12",
1313
"Programming Language :: Python :: Implementation :: CPython",
1414
]
15-
scripts = { generate_cli_script = "sync_uv_pre_commit.render:generate_script" }
1615
dependencies = [
1716
"packaging",
1817
"pre-commit>=3.5.0",
1918
"tomlkit>=0.13.2",
2019
"typing-extensions>=4.12.2",
2120
]
21+
22+
[project.scripts]
23+
generate_cli_script = "sync_uv_pre_commit.render:generate_script"
24+
sync_uv_pre_commit = "sync_uv_pre_commit.script:main"
25+
2226
[dependency-groups]
2327
dev = [
2428
"ruff==0.8.4",

src/sync_uv_pre_commit/export.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
import sys
44
from pathlib import Path
55

6-
WORKSPACE = Path(__file__).parent
7-
sys.path.append(str(WORKSPACE / "src"))
6+
sys.path.append(str(Path(__file__).parent.parent))
87

98

109
if __name__ == "__main__":

src/sync_uv_pre_commit/render.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def generate_script() -> None:
1212
pyproject_file = Path(__file__).parent.parent.parent / "pyproject.toml"
1313
export_template_file = Path(__file__).parent / "export.py.j2"
1414
export_script_file = Path(__file__).parent / "export.py"
15-
output = Path(__file__).parent.parent.parent / "script.py"
15+
output = Path(__file__).parent / "output.py"
1616

1717
pyproject = read_pyproject(pyproject_file)
1818
with export_template_file.open("r") as f:

src/sync_uv_pre_commit/script.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from __future__ import annotations
2+
3+
import subprocess
4+
import sys
5+
from pathlib import Path
6+
7+
from sync_uv_pre_commit.log import ExitCode, logger
8+
9+
10+
def main() -> None: # noqa: D103
11+
process = subprocess.run( # noqa: S603
12+
["uv", "run", str(Path(__file__).parent / "output.py")], # noqa: S607
13+
check=False,
14+
capture_output=True,
15+
text=True,
16+
)
17+
try:
18+
process.check_returncode()
19+
except subprocess.CalledProcessError as exc:
20+
logger.error("error: %s", exc.stderr)
21+
if exc.returncode == ExitCode.MISSING.value:
22+
sys.exit(ExitCode.MISSING)
23+
if exc.returncode == ExitCode.PARSING.value:
24+
sys.exit(ExitCode.PARSING)
25+
sys.exit(ExitCode.UNKNOWN)
26+
else:
27+
logger.info("success: %s", process.stdout)

0 commit comments

Comments
 (0)