Skip to content

Commit

Permalink
fix: use subprocess
Browse files Browse the repository at this point in the history
  • Loading branch information
phi-friday committed Dec 26, 2024
1 parent 78ca05f commit 92b2f68
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
- id: sync-uv-pre-commit
name: Sync uv and pre commit
description: Sync uv and pre commit
language: script
entry: "uv run script.py"
language: python
entry: sync_uv_pre_commit
minimum_pre_commit_version: "3.5.0"
require_serial: true
always_run: true
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ classifiers = [
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
]
scripts = { generate_cli_script = "sync_uv_pre_commit.render:generate_script" }
dependencies = [
"packaging",
"pre-commit>=3.5.0",
"tomlkit>=0.13.2",
"typing-extensions>=4.12.2",
]

[project.scripts]
generate_cli_script = "sync_uv_pre_commit.render:generate_script"
sync_uv_pre_commit = "sync_uv_pre_commit.script:main"

[dependency-groups]
dev = [
"ruff==0.8.4",
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/sync_uv_pre_commit/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def generate_script() -> None:
pyproject_file = Path(__file__).parent.parent.parent / "pyproject.toml"
export_template_file = Path(__file__).parent / "export.py.j2"
export_script_file = Path(__file__).parent / "export.py"
output = Path(__file__).parent.parent.parent / "script.py"
output = Path(__file__).parent / "output.py"

pyproject = read_pyproject(pyproject_file)
with export_template_file.open("r") as f:
Expand Down
27 changes: 27 additions & 0 deletions src/sync_uv_pre_commit/script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from __future__ import annotations

import subprocess
import sys
from pathlib import Path

from sync_uv_pre_commit.log import ExitCode, logger


def main() -> None: # noqa: D103
process = subprocess.run( # noqa: S603
["uv", "run", str(Path(__file__).parent / "output.py")], # noqa: S607
check=False,
capture_output=True,
text=True,
)
try:
process.check_returncode()
except subprocess.CalledProcessError as exc:
logger.error("error: %s", exc.stderr)
if exc.returncode == ExitCode.MISSING.value:
sys.exit(ExitCode.MISSING)
if exc.returncode == ExitCode.PARSING.value:
sys.exit(ExitCode.PARSING)
sys.exit(ExitCode.UNKNOWN)
else:
logger.info("success: %s", process.stdout)

0 comments on commit 92b2f68

Please sign in to comment.