- Notifications
You must be signed in to change notification settings - Fork 722
/
Copy pathpdm_build.py
55 lines (51 loc) · 2.28 KB
/
pdm_build.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
importos
fromtypingimportAny, Dict, List
frompdm.backend.hooksimportContext
TIANGOLO_BUILD_PACKAGE=os.getenv("TIANGOLO_BUILD_PACKAGE", "typer")
defpdm_build_initialize(context: Context):
metadata=context.config.metadata
# Get main version
version=metadata["version"]
# Get package names to keep in sync with the same main version
sync_dependencies: List[str] =context.config.data["tool"]["tiangolo"][
"_internal-slim-build"
]["sync-dependencies"]
# Get custom config for the current package, from the env var
config: Dict[str, Any] =context.config.data["tool"]["tiangolo"][
"_internal-slim-build"
]["packages"][TIANGOLO_BUILD_PACKAGE]
project_config: Dict[str, Any] =config["project"]
# Get main optional dependencies, extras
optional_dependencies: Dict[str, List[str]] =metadata.get(
"optional-dependencies", {}
)
# Get custom optional dependencies name to always include in this (non-slim) package
include_optional_dependencies: List[str] =config.get(
"include-optional-dependencies", []
)
# Override main [project] configs with custom configs for this package
forkey, valueinproject_config.items():
metadata[key] =value
# Get custom build config for the current package
build_config: Dict[str, Any] = (
config.get("tool", {}).get("pdm", {}).get("build", {})
)
# Override PDM build config with custom build config for this package
forkey, valueinbuild_config.items():
context.config.build_config[key] =value
# Get main dependencies
dependencies: List[str] =metadata.get("dependencies", [])
# Add optional dependencies to the default dependencies for this (non-slim) package
forinclude_optionalininclude_optional_dependencies:
optional_dependencies_group=optional_dependencies.get(include_optional, [])
dependencies.extend(optional_dependencies_group)
# Sync versions in dependencies
new_dependencies= []
fordepindependencies:
ifdepinsync_dependencies:
new_dep=f"{dep}=={version}"
new_dependencies.append(new_dep)
else:
new_dependencies.append(dep)
ifnew_dependencies!=dependencies:
metadata["dependencies"] =new_dependencies