22
33For AIPCC requirements (konflux-aipcc, konflux-build-aipcc), runs uv pip compile
44inside Docker containers for each target architecture, then merges the
5- per-architecture hashes into a single output file.
5+ per-architecture hashes into a single output file. Packages explicitly listed
6+ in requirements/konflux-pypi.in are omitted from the final-image AIPCC output
7+ so SBOM and CVE tooling see a single source of truth per shipped package.
68
79For PyPI requirements (konflux-pypi), runs a single uv pip compile since these
810packages are built from source and don't need multi-arch hashes.
2022import tempfile
2123from concurrent .futures import ThreadPoolExecutor , as_completed
2224from dataclasses import dataclass , field
25+ from functools import cache
2326from pathlib import Path
2427from typing import Any
2528
4144}
4245
4346REPO_ROOT = Path (__file__ ).resolve ().parent .parent
47+ KONFLUX_PYPI_IN = REPO_ROOT / "requirements/konflux-pypi.in"
4448
4549
4650@dataclass
@@ -92,6 +96,14 @@ def _canonicalize(name: str) -> str:
9296 return re .sub (r"[-_.]+" , "-" , name ).lower ()
9397
9498
99+ @cache
100+ def read_requirements_names (path : Path ) -> frozenset [str ]:
101+ session = PipSession ()
102+ return frozenset (
103+ _canonicalize (ireq .req .name ) for ireq in parse_requirements (str (path ), session = session )
104+ )
105+
106+
95107def run_uv_compile_in_docker (
96108 target : CompileTarget ,
97109 arch : str ,
@@ -204,7 +216,10 @@ def parse_and_collect_hashes(
204216 detail = ", " .join (f"{ a } : { v } " for a , v in sorted (arch_versions .items ()))
205217 raise SystemExit (
206218 f"Version mismatch for { name } : { detail } . "
207- "All architectures must resolve to the same version."
219+ "All architectures must resolve to the same version. "
220+ "Add an explicit constraint for this package to the relevant "
221+ "AIPCC input file (for example `requirements/konflux-aipcc.in`) "
222+ "and rerun `python requirements/compile.py`."
208223 )
209224
210225 return canonical_ireqs , merged_hashes
@@ -214,6 +229,7 @@ def write_multiarch_output(
214229 target : CompileTarget ,
215230 canonical_ireqs : dict [str , Any ],
216231 merged_hashes : dict [str , set [str ]],
232+ excluded_names : set [str ] | None = None ,
217233) -> None :
218234 out_path = REPO_ROOT / target .out_file
219235 parts : list [str ] = []
@@ -232,6 +248,8 @@ def write_multiarch_output(
232248 parts .append (f"--index-url { target .index_url } \n \n " )
233249
234250 for name in sorted (canonical_ireqs ):
251+ if excluded_names and name in excluded_names :
252+ continue
235253 ireq = canonical_ireqs [name ]
236254 hashes = merged_hashes [name ]
237255 parts .append (format_requirement (ireq , hashes = hashes ) + "\n " )
@@ -289,7 +307,12 @@ def compile_multiarch(target: CompileTarget, image: str) -> None:
289307
290308 canonical_ireqs , merged_hashes = parse_and_collect_hashes (arch_outputs )
291309
292- write_multiarch_output (target , canonical_ireqs , merged_hashes )
310+ excluded_names = (
311+ read_requirements_names (KONFLUX_PYPI_IN ) if target .name == "konflux-aipcc" else None
312+ )
313+ write_multiarch_output (
314+ target , canonical_ireqs , merged_hashes , excluded_names = excluded_names
315+ )
293316 finally :
294317 for arch_tag in arch_images .values ():
295318 subprocess .run (["docker" , "rmi" , arch_tag ], capture_output = True )
0 commit comments