-
Notifications
You must be signed in to change notification settings - Fork 0
/
hatch_build.py
42 lines (34 loc) · 1.54 KB
/
hatch_build.py
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
"""Hatch build hook."""
import importlib.util
import sys
from pathlib import Path
from typing import Any, override
from hatchling.metadata.plugin.interface import MetadataHookInterface
class AboutMetadataHookOld(MetadataHookInterface):
"""Hatchling metadata hook that loads dynamic metadata for authors, and URLs from the `__about__.py` file within the project."""
@override
def update(self, metadata: dict[str, Any]) -> None:
"""
Update the metadata dictionary with values from the `__about__.py` file.
Args:
metadata: The dictionary containing the project metadata.
"""
# Dynamically load __about__.py
about_path = Path(self.root) / "src/kajihs_utils/__about__.py"
spec = importlib.util.spec_from_file_location("__about__", about_path)
if spec is None or spec.loader is None:
raise ImportError(f"Could not load metadata from {about_path}") # noqa: TRY003
about = importlib.util.module_from_spec(spec)
sys.modules["__about__"] = about
spec.loader.exec_module(about)
# Map __about__ attributes to metadata fields
authors: list[str] = about.__authors__
emails: list[str] = about.__author_emails__
metadata["authors"] = [
{"name": name, "email": email} for name, email in zip(authors, emails, strict=True)
]
metadata["urls"] = {
"Repository": about.__repo_url__,
"Issues": about.__issues_url__,
# "Documentation": about.__documentation__,
}