tutor-deck/.hatch_build.py
Régis Behmo 46f7d7af30 ci: fix scss build on building
We add a custom hook to our sdist target, such that "make scss" is run
whenever we run `python -m build --sdist`.
2025-04-16 16:34:17 +02:00

31 lines
907 B
Python

# https://hatch.pypa.io/latest/how-to/config/dynamic-metadata/
import os
import subprocess
import typing as t
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
from hatchling.metadata.plugin.interface import MetadataHookInterface
HERE = os.path.dirname(__file__)
class CustomBuildHook(BuildHookInterface):
def initialize(self, version, build_data):
# This runs before the build starts
subprocess.check_call(["make", "scss"])
class MetaDataHook(MetadataHookInterface):
def update(self, metadata: dict[str, t.Any]) -> None:
about = load_about()
metadata["version"] = about["__version__"]
def load_about() -> dict[str, str]:
about: dict[str, str] = {}
with open(
os.path.join(HERE, "tutordeck", "__about__.py"), "rt", encoding="utf-8"
) as f:
exec(f.read(), about) # pylint: disable=exec-used
return about