|
3 | 3 |
|
4 | 4 | from pdm.backend.hooks import Context |
5 | 5 |
|
6 | | -TIANGOLO_BUILD_PACKAGE = os.getenv("TIANGOLO_BUILD_PACKAGE", "fastapi-cli") |
| 6 | +TIANGOLO_BUILD_PACKAGE = os.getenv("TIANGOLO_BUILD_PACKAGE") |
7 | 7 |
|
8 | 8 |
|
9 | | -def pdm_build_initialize(context: Context): |
| 9 | +def pdm_build_initialize(context: Context) -> None: |
10 | 10 | metadata = context.config.metadata |
| 11 | + # Get main version |
| 12 | + version = metadata["version"] |
11 | 13 | # Get custom config for the current package, from the env var |
12 | | - config: dict[str, Any] = context.config.data["tool"]["tiangolo"][ |
| 14 | + all_configs_config: dict[str, Any] = context.config.data["tool"]["tiangolo"][ |
13 | 15 | "_internal-slim-build" |
14 | | - ]["packages"].get(TIANGOLO_BUILD_PACKAGE) |
15 | | - if not config: |
| 16 | + ]["packages"] |
| 17 | + |
| 18 | + if TIANGOLO_BUILD_PACKAGE not in all_configs_config: |
16 | 19 | return |
| 20 | + |
| 21 | + config = all_configs_config[TIANGOLO_BUILD_PACKAGE] |
17 | 22 | project_config: dict[str, Any] = config["project"] |
18 | 23 | # Override main [project] configs with custom configs for this package |
19 | 24 | for key, value in project_config.items(): |
20 | 25 | metadata[key] = value |
| 26 | + # Get custom build config for the current package |
| 27 | + build_config: dict[str, Any] = ( |
| 28 | + config.get("tool", {}).get("pdm", {}).get("build", {}) |
| 29 | + ) |
| 30 | + # Override PDM build config with custom build config for this package |
| 31 | + for key, value in build_config.items(): |
| 32 | + context.config.build_config[key] = value |
| 33 | + # Get main dependencies |
| 34 | + dependencies: list[str] = metadata.get("dependencies", []) |
| 35 | + # Sync versions in dependencies |
| 36 | + new_dependencies = [] |
| 37 | + for dep in dependencies: |
| 38 | + new_dep = f"{dep}>={version}" |
| 39 | + new_dependencies.append(new_dep) |
| 40 | + metadata["dependencies"] = new_dependencies |
0 commit comments