Skip to content

Commit c470c33

Browse files
committed
🔨 Add PDM build script for fastapi-cli and fastapi-cli-slim
1 parent 06b7f6a commit c470c33

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

pdm_build.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import os
2+
from typing import Any, Dict, List
3+
4+
from pdm.backend.hooks import Context
5+
6+
TIANGOLO_BUILD_PACKAGE = os.getenv("TIANGOLO_BUILD_PACKAGE", "fastapi-cli")
7+
8+
9+
def pdm_build_initialize(context: Context):
10+
metadata = context.config.metadata
11+
# Get custom config for the current package, from the env var
12+
config: Dict[str, Any] = context.config.data["tool"]["tiangolo"][
13+
"_internal-slim-build"
14+
]["packages"][TIANGOLO_BUILD_PACKAGE]
15+
project_config: Dict[str, Any] = config["project"]
16+
# Get main optional dependencies, extras
17+
optional_dependencies: Dict[str, List[str]] = metadata.get(
18+
"optional-dependencies", {}
19+
)
20+
# Get custom optional dependencies name to always include in this (non-slim) package
21+
include_optional_dependencies: List[str] = config.get(
22+
"include-optional-dependencies", []
23+
)
24+
# Override main [project] configs with custom configs for this package
25+
for key, value in project_config.items():
26+
metadata[key] = value
27+
# Get custom build config for the current package
28+
build_config: Dict[str, Any] = (
29+
config.get("tool", {}).get("pdm", {}).get("build", {})
30+
)
31+
# Override PDM build config with custom build config for this package
32+
for key, value in build_config.items():
33+
context.config.build_config[key] = value
34+
# Get main dependencies
35+
dependencies: List[str] = metadata.get("dependencies", [])
36+
# Add optional dependencies to the default dependencies for this (non-slim) package
37+
for include_optional in include_optional_dependencies:
38+
optional_dependencies_group = optional_dependencies.get(include_optional, [])
39+
dependencies.extend(optional_dependencies_group)

0 commit comments

Comments
 (0)