-
Notifications
You must be signed in to change notification settings - Fork 463
/
Copy path.hatch_build.py
37 lines (29 loc) · 1.17 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
# https://hatch.pypa.io/latest/how-to/config/dynamic-metadata/
import os
import typing as t
from hatchling.metadata.plugin.interface import MetadataHookInterface
HERE = os.path.dirname(__file__)
class MetaDataHook(MetadataHookInterface):
def update(self, metadata: dict[str, t.Any]) -> None:
about = load_about()
metadata["version"] = about["__package_version__"]
metadata["dependencies"] = load_requirements("base.in")
metadata["optional-dependencies"] = {
"dev": load_requirements("dev.txt"),
"full": load_requirements("plugins.txt"),
}
def load_about() -> dict[str, str]:
about: dict[str, str] = {}
with open(os.path.join(HERE, "tutor", "__about__.py"), "rt", encoding="utf-8") as f:
exec(f.read(), about) # pylint: disable=exec-used
return about
def load_requirements(filename: str) -> list[str]:
requirements = []
with open(
os.path.join(HERE, "requirements", filename), "rt", encoding="utf-8"
) as f:
for line in f:
line = line.strip()
if line != "" and not line.startswith("#"):
requirements.append(line)
return requirements