Repository: python-wheel-build/fromager

Issue:
build order files should include the original requirement and constrained requirement
Now that we are constraining some components, we need to report that in the build order files. We should add a new field for the constrained requirement and ensure that the "req" field includes the original requirement.

Discussion:

Patch:
diff --git a/src/fromager/context.py b/src/fromager/context.py
index 2208a17..190123e 100644
--- a/src/fromager/context.py
+++ b/src/fromager/context.py
@@ -89,6 +89,7 @@ class WorkContext:
         source_url: str,
         source_url_type: str,
         prebuilt: bool = False,
+        constraint: Requirement | None = None,
     ):
         # We only care if this version of this package has been built,
         # and don't want to trigger building it twice. The "extras"
@@ -103,6 +104,7 @@ class WorkContext:
         info = {
             "type": req_type,
             "req": str(req),
+            "constraint": str(constraint) if constraint else "",
             "dist": canonicalize_name(req.name),
             "version": str(version),
             "why": why,
diff --git a/src/fromager/sdist.py b/src/fromager/sdist.py
index ec95e26..cefeef9 100644
--- a/src/fromager/sdist.py
+++ b/src/fromager/sdist.py
@@ -169,12 +169,13 @@ def handle_requirement(
     # fails.
     ctx.add_to_build_order(
         req_type=req_type,
-        req=req,
+        req=original_req,
         version=resolved_version,
         why=why,
         source_url=source_url,
         source_url_type=source_url_type,
         prebuilt=pre_built,
+        constraint=constraint,
     )
 
     if not pre_built:


Test patch:
diff --git a/tests/test_context.py b/tests/test_context.py
index 641f145..2ebe98c 100644
--- a/tests/test_context.py
+++ b/tests/test_context.py
@@ -56,6 +56,7 @@ def test_build_order(tmp_context):
             "prebuilt": False,
             "source_url": "url",
             "source_url_type": "sdist",
+            "constraint": "",
         },
         {
             "type": "dependency",
@@ -66,6 +67,7 @@ def test_build_order(tmp_context):
             "prebuilt": False,
             "source_url": "url",
             "source_url_type": "sdist",
+            "constraint": "",
         },
     ]
     assert expected == contents
@@ -108,6 +110,7 @@ def test_build_order_repeats(tmp_context):
             "prebuilt": False,
             "source_url": "url",
             "source_url_type": "sdist",
+            "constraint": "",
         },
     ]
     assert expected == contents
@@ -142,6 +145,7 @@ def test_build_order_name_canonicalization(tmp_context):
             "prebuilt": False,
             "source_url": "url",
             "source_url_type": "sdist",
+            "constraint": "",
         },
     ]
     assert expected == contents