pdm_build.py
This file
Path
pdm_build.py
55 lines · 2.3 KiB · Python
Last changed by
🐛 Fix broken installation when upgrading from `typer <0.12.0` to `typer >=0.12.0`, make `typer` independent of `typer-slim`, include `typer` command in `typer` package (#791)Sebastián Ramírezbefore adoption05ffb24
History of this fileTake it
🐛 Fix broken installation when upgrading from `typer <0.12.0` to `typer >=0.12.0`, make `typer` independent of `typer-slim`, include `typer` command in `typer` package (#791)Sebastián Ramírezbefore adoption05ffb24
lines 1–55why, one step back1import os2from typing import Any, Dict, List34from pdm.backend.hooks import Context56TIANGOLO_BUILD_PACKAGE = os.getenv("TIANGOLO_BUILD_PACKAGE", "typer")789def pdm_build_initialize(context: Context):10 metadata = context.config.metadata11 # Get main version12 version = metadata["version"]13 # Get package names to keep in sync with the same main version14 sync_dependencies: List[str] = context.config.data["tool"]["tiangolo"][15 "_internal-slim-build"16 ]["sync-dependencies"]17 # Get custom config for the current package, from the env var18 config: Dict[str, Any] = context.config.data["tool"]["tiangolo"][19 "_internal-slim-build"20 ]["packages"][TIANGOLO_BUILD_PACKAGE]21 project_config: Dict[str, Any] = config["project"]22 # Get main optional dependencies, extras23 optional_dependencies: Dict[str, List[str]] = metadata.get(24 "optional-dependencies", {}25 )26 # Get custom optional dependencies name to always include in this (non-slim) package27 include_optional_dependencies: List[str] = config.get(28 "include-optional-dependencies", []29 )30 # Override main [project] configs with custom configs for this package31 for key, value in project_config.items():32 metadata[key] = value33 # Get custom build config for the current package34 build_config: Dict[str, Any] = (35 config.get("tool", {}).get("pdm", {}).get("build", {})36 )37 # Override PDM build config with custom build config for this package38 for key, value in build_config.items():39 context.config.build_config[key] = value40 # Get main dependencies41 dependencies: List[str] = metadata.get("dependencies", [])42 # Add optional dependencies to the default dependencies for this (non-slim) package43 for include_optional in include_optional_dependencies:44 optional_dependencies_group = optional_dependencies.get(include_optional, [])45 dependencies.extend(optional_dependencies_group)46 # Sync versions in dependencies47 new_dependencies = []48 for dep in dependencies:49 if dep in sync_dependencies:50 new_dep = f"{dep}=={version}"51 new_dependencies.append(new_dep)52 else:53 new_dependencies.append(dep)54 if new_dependencies != dependencies:55 metadata["dependencies"] = new_dependencies