-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhatch_build.py
More file actions
81 lines (60 loc) · 2.28 KB
/
Copy pathhatch_build.py
File metadata and controls
81 lines (60 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# SPDX-FileCopyrightText: 2026 Defensive Lab Agency
# SPDX-FileContributor: u039b <git@0x39b.fr>
#
# SPDX-License-Identifier: GPL-3.0-or-later
import re
from pathlib import Path
from typing import List, Dict, Optional
from hatchling.metadata.plugin.interface import MetadataHookInterface
def get_authors(changelog_path: Path) -> List[Dict[str, str]]:
"""
Extract all unique authors from a Debian changelog file.
Each author is represented as a dict with keys 'name' and 'email'.
Authors are identified by lines starting with ' -- ' followed by
'Name <email>'.
Args:
changelog_path: Path to the debian/changelog file.
Returns:
List of dicts, e.g. [{"name": "John Doe", "email": "john@example.com"}]
"""
author_pattern = re.compile(r"^ -- (.*?) <([^>]+)>")
authors = []
seen = set()
with changelog_path.open(mode="r", encoding="utf-8") as f:
for line in f:
match = author_pattern.match(line)
if match:
name = match.group(1).strip()
email = match.group(2).strip()
key = (name, email)
if key not in seen:
seen.add(key)
authors.append({"name": name, "email": email})
return authors
def get_latest_version(changelog_path: Path) -> Optional[str]:
"""
Extract the latest version from a Debian changelog file.
Args:
changelog_path: Path to the debian/changelog file.
Returns:
Version string (e.g., "1.0.2") or None if not found.
"""
version_pattern = re.compile(r"^[^\s]+\s+\(([^)]+)\)")
with changelog_path.open(mode="r", encoding="utf-8") as f:
for line in f:
match = version_pattern.match(line)
if match:
return match.group(1)
return None
class DebianChangelogHook(MetadataHookInterface):
def update(self, metadata):
changelog_path = Path(self.root) / "debian" / "changelog"
if not changelog_path.exists():
return
version = get_latest_version(changelog_path)
authors = get_authors(changelog_path)
if not version:
raise Exception("Not version found")
if authors:
metadata["authors"] = authors
metadata["version"] = version