Skip to content
Snippets Groups Projects
Commit c79f47a6 authored by Thomas Schneider's avatar Thomas Schneider
Browse files

build: Build webpack as part of sdist

parent 8d74ca9f
Branches
Tags
No related merge requests found
from __future__ import annotations
import json
from pathlib import Path
from typing import TYPE_CHECKING
from pynpm import NPMPackage
if TYPE_CHECKING:
from pdm.backend.hooks.base import Context
def pdm_build_update_files(context: Context, files: dict[str, Path]) -> None:
pkg_root = Path("schilder2000")
manifest_path = pkg_root / "static" / "manifest.json"
with (context.root / manifest_path).open() as fp:
def pdm_build_initialize(context: Context) -> None:
if not context.target == "sdist":
return
context.config.build_config.includes.append("schilder2000/static/manifest.json")
if "without-npm" not in context.config_settings:
# Assume built webpack is already present otherwise
context.ensure_build_dir()
pkg = NPMPackage(context.root, commands=["clean-install", "run-script"])
pkg.clean_install()
pkg.run_script(
"build",
"--",
"--output-path",
context.build_dir / "schilder2000" / "static",
)
manifest_path = context.build_dir / "schilder2000" / "static" / "manifest.json"
else:
manifest_path = context.root / "schilder2000" / "static" / "manifest.json"
with manifest_path.open() as fp:
manifest: dict[str, str | dict] = json.load(fp)
for k, v in manifest.items():
if k == "entrypoints" or not isinstance(v, str):
continue
v = v.removeprefix("/")
files[str(pkg_root / v)] = context.root / pkg_root / v
context.config.build_config.includes.append("schilder2000" + v)
......@@ -50,10 +50,9 @@ serve = "flask -A schilder2000 run --debug"
includes = [
"schilder2000/**/*.py",
"schilder2000/templates",
"schilder2000/static/manifest.json",
# Referenced files in manifest.json included via pdm_build.py
]
[build-system]
requires = ["pdm-backend"]
requires = ["pdm-backend", "pynpm"]
build-backend = "pdm.backend"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment