Skip to content

Commit d970a53

Browse files
committed
Enhance pre-commit configuration and improve author/version extraction in hatch_build.py
1 parent 639897b commit d970a53

3 files changed

Lines changed: 28 additions & 88 deletions

File tree

.pre-commit-config.yaml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,21 @@ repos:
77
- repo: https://github.com/pre-commit/pre-commit-hooks
88
rev: v6.0.0
99
hooks:
10+
- id: check-toml
1011
- id: end-of-file-fixer
1112
types: [python]
1213
- id: trailing-whitespace
1314
types: [python]
14-
# - repo: https://github.com/tox-dev/pyproject-fmt
15-
# rev: "v2.16.1"
16-
# hooks:
17-
# - id: pyproject-fmt
15+
- id: check-merge-conflict
16+
- id: detect-private-key
17+
- repo: https://github.com/gitleaks/gitleaks
18+
rev: v8.30.1
19+
hooks:
20+
- id: gitleaks
21+
- repo: https://github.com/astral-sh/uv-pre-commit
22+
rev: 0.9.18
23+
hooks:
24+
- id: uv-lock
1825
- repo: https://github.com/astral-sh/ruff-pre-commit
1926
rev: "v0.15.2"
2027
hooks:

configuration_example.yaml

Lines changed: 0 additions & 53 deletions
This file was deleted.

hatch_build.py

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
import subprocess
1+
# SPDX-FileCopyrightText: 2026 Defensive Lab Agency
2+
# SPDX-FileContributor: u039b <git@0x39b.fr>
3+
#
4+
# SPDX-License-Identifier: GPL-3.0-or-later
5+
6+
import re
27
from pathlib import Path
8+
from typing import List, Dict, Optional
39

410
from hatchling.metadata.plugin.interface import MetadataHookInterface
5-
import re
611

7-
from typing import List, Dict, Optional
812

9-
def get_authors(changelog_path: str) -> List[Dict[str, str]]:
13+
def get_authors(changelog_path: Path) -> List[Dict[str, str]]:
1014
"""
1115
Extract all unique authors from a Debian changelog file.
1216
@@ -20,11 +24,11 @@ def get_authors(changelog_path: str) -> List[Dict[str, str]]:
2024
Returns:
2125
List of dicts, e.g. [{"name": "John Doe", "email": "john@example.com"}]
2226
"""
23-
author_pattern = re.compile(r'^ -- (.*?) <([^>]+)>')
27+
author_pattern = re.compile(r"^ -- (.*?) <([^>]+)>")
2428
authors = []
2529
seen = set()
2630

27-
with open(changelog_path, 'r', encoding='utf-8') as f:
31+
with changelog_path.open(mode="r", encoding="utf-8") as f:
2832
for line in f:
2933
match = author_pattern.match(line)
3034
if match:
@@ -37,7 +41,8 @@ def get_authors(changelog_path: str) -> List[Dict[str, str]]:
3741

3842
return authors
3943

40-
def get_latest_version(changelog_path: str) -> Optional[str]:
44+
45+
def get_latest_version(changelog_path: Path) -> Optional[str]:
4146
"""
4247
Extract the latest version from a Debian changelog file.
4348
@@ -47,30 +52,20 @@ def get_latest_version(changelog_path: str) -> Optional[str]:
4752
Returns:
4853
Version string (e.g., "1.0.2") or None if not found.
4954
"""
50-
version_pattern = re.compile(r'^[^\s]+\s+\(([^)]+)\)')
51-
52-
with open(changelog_path, 'r', encoding='utf-8') as f:
53-
for line in f:
54-
match = version_pattern.match(line)
55-
if match:
56-
return match.group(1)
57-
return None
55+
version_pattern = re.compile(r"^[^\s]+\s+\(([^)]+)\)")
5856

59-
def get_latest_xxversion(changelog_path):
60-
version_pattern = re.compile(r'^[^\s]+\s+\(([^)]+)\)')
61-
62-
with open(changelog_path, 'r', encoding='utf-8') as f:
57+
with changelog_path.open(mode="r", encoding="utf-8") as f:
6358
for line in f:
6459
match = version_pattern.match(line)
6560
if match:
66-
return match.group(1) # captured version
61+
return match.group(1)
6762
return None
6863

6964

7065
class DebianChangelogHook(MetadataHookInterface):
7166
def update(self, metadata):
72-
# Only run for the 'metadata' phase
7367
changelog_path = Path(self.root) / "debian" / "changelog"
68+
7469
if not changelog_path.exists():
7570
return
7671

@@ -81,15 +76,6 @@ def update(self, metadata):
8176
raise Exception("Not version found")
8277

8378
if authors:
84-
metadata["authors"] = authors
79+
metadata["authors"] = authors
8580

8681
metadata["version"] = version
87-
print(metadata)
88-
89-
90-
#class JSONMetaDataHook(MetadataHookInterface):
91-
# def update(self, meta data):
92-
# version = subprocess.check_output(["dpkg-parsechangelog", "--show-field", "Version"])
93-
# metadata["version"] = version
94-
# print(metadata)
95-

0 commit comments

Comments
 (0)