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
27from pathlib import Path
8+ from typing import List , Dict , Optional
39
410from 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
7065class 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