Skip to content

Commit 0379923

Browse files
committed
refactor: Split packagesettings module into a package
The `packagesettings` module has grown to over 1,200 lines of code. With upcoming plans to improve resolver, downloader, and patching, the code is going to grow even more. Split the module into a package with several private modules. The public interface of the `fromager.packagesettings` is mostly staying the same. Only one monkey-patching case for testing had to be changed. Co-Authored-By: Claude <claude@anthropic.com> Signed-off-by: Christian Heimes <cheimes@redhat.com>
1 parent 5b096c0 commit 0379923

9 files changed

Lines changed: 1397 additions & 1247 deletions

File tree

src/fromager/packagesettings.py

Lines changed: 0 additions & 1245 deletions
This file was deleted.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
"""Package settings for Fromager build system."""
2+
3+
from ._hooks import default_update_extra_environ, get_extra_environ
4+
from ._models import (
5+
BuildOptions,
6+
DownloadSource,
7+
GitOptions,
8+
PackageSettings,
9+
ProjectOverride,
10+
ResolverDist,
11+
VariantInfo,
12+
)
13+
from ._pbi import PackageBuildInfo
14+
from ._settings import Settings, SettingsFile
15+
from ._templates import substitute_template
16+
from ._typedefs import (
17+
MODEL_CONFIG,
18+
Annotations,
19+
BuildDirectory,
20+
EnvKey,
21+
EnvVars,
22+
GlobalChangelog,
23+
Package,
24+
PackageVersion,
25+
PatchMap,
26+
RawAnnotations,
27+
Template,
28+
Variant,
29+
VariantChangelog,
30+
)
31+
32+
__all__ = (
33+
"MODEL_CONFIG",
34+
"Annotations",
35+
"BuildDirectory",
36+
"BuildOptions",
37+
"DownloadSource",
38+
"EnvKey",
39+
"EnvVars",
40+
"GitOptions",
41+
"GlobalChangelog",
42+
"Package",
43+
"PackageBuildInfo",
44+
"PackageSettings",
45+
"PackageVersion",
46+
"PatchMap",
47+
"ProjectOverride",
48+
"RawAnnotations",
49+
"ResolverDist",
50+
"Settings",
51+
"SettingsFile",
52+
"Template",
53+
"Variant",
54+
"VariantChangelog",
55+
"VariantInfo",
56+
"default_update_extra_environ",
57+
"get_extra_environ",
58+
"substitute_template",
59+
)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"""Hook functions for extra environment variable management."""
2+
3+
from __future__ import annotations
4+
5+
import pathlib
6+
import typing
7+
8+
from packaging.requirements import Requirement
9+
from packaging.version import Version
10+
11+
from .. import overrides
12+
13+
if typing.TYPE_CHECKING:
14+
from .. import build_environment, context
15+
16+
17+
def default_update_extra_environ(
18+
*,
19+
ctx: context.WorkContext,
20+
req: Requirement,
21+
version: Version | None,
22+
sdist_root_dir: pathlib.Path,
23+
extra_environ: dict[str, str],
24+
build_env: build_environment.BuildEnvironment,
25+
) -> None:
26+
"""Update extra_environ in-place"""
27+
return None
28+
29+
30+
def get_extra_environ(
31+
*,
32+
ctx: context.WorkContext,
33+
req: Requirement,
34+
version: Version | None,
35+
sdist_root_dir: pathlib.Path,
36+
build_env: build_environment.BuildEnvironment,
37+
) -> dict[str, str]:
38+
"""Get extra environment variables from settings and update hook"""
39+
pbi = ctx.package_build_info(req)
40+
extra_environ = pbi.get_extra_environ(
41+
build_env=build_env,
42+
version=version,
43+
)
44+
overrides.find_and_invoke(
45+
req.name,
46+
"update_extra_environ",
47+
default_update_extra_environ,
48+
ctx=ctx,
49+
req=req,
50+
version=version,
51+
sdist_root_dir=sdist_root_dir,
52+
extra_environ=extra_environ,
53+
build_env=build_env,
54+
)
55+
return extra_environ

0 commit comments

Comments
 (0)