pants icon indicating copy to clipboard operation
pants copied to clipboard

Overrides not working with parametrized default

Open isra17 opened this issue 1 year ago • 2 comments

Describe the bug I took the time to create an example off the example python repo. See here:

--- a/BUILD
+++ b/BUILD
@@ -4,4 +4,8 @@
 # A macro that turns every entry in this directory's requirements.txt into a
 # `python_requirement_library` target. Refer to
 # https://www.pantsbuild.org/docs/python-third-party-dependencies.
-python_requirements(name="reqs")
+python_requirements(name="reqs", resolve="python-default")
+python_requirements(name="other-reqs", resolve="python-other")
+
+__defaults__(all=dict(resolve=parametrize("python-default", "python-other")))
+
diff --git a/helloworld/translator/BUILD b/helloworld/translator/BUILD
index 7086f94..23ddf0b 100644
--- a/helloworld/translator/BUILD
+++ b/helloworld/translator/BUILD
@@ -4,6 +4,10 @@
 # This target sets the metadata for all the Python non-test files in this directory.
 python_sources(
     name="lib",
+    overrides={
+      "translator.py": dict(resolve="python-other"),  # Not working
+      "__init__.py": dict(resolve=parametrize("python-other")),  # Working
+    }
 )

After this patch, I would expect both helloworld/translator/translator.py and helloworld/translator/__init__.py to be only in python-other resolve.

However I get the following result:

$ pants list "helloworld/translator/translator.py"
helloworld/translator/translator.py:lib@resolve=python-default
helloworld/translator/translator.py:lib@resolve=python-other

$ pants list "helloworld/translator/__init__.py"
helloworld/translator/__init__.py:lib@resolve=python-other

Note that not using parametrize in the __defaults__ also make this work.

Pants version Which version of Pants are you using?

2.20.0

isra17 avatar May 18 '24 22:05 isra17

I nailed it down to this: https://github.com/isra17/pants/commit/1cc132b92bd148cc40f65e71b1758400bbb177ad

Parametrize.expand with the override will only update the address given the value is a Parametrize. Is suppose the fix is to check if an override is also one of the current address parameter and update as needed.

isra17 avatar May 19 '24 00:05 isra17

Excellent find!

I'd just like to point out that this is a address issue, the actual resolve is correct:

❯ pants peek --exclude-defaults "helloworld/translator/translator.py"
[
  {
    "address": "helloworld/translator/translator.py:lib@resolve=python-default",
    "target_type": "python_source",
    "dependencies": [],
    "resolve": "python-other",
    "source_raw": "translator.py",
    "sources": [
      "helloworld/translator/translator.py"
    ],
    "sources_fingerprint": "143d1a81fc121bc539e5fa40c79bb8e2fa3806d84420b11b323fc88fca57a61e"
  },
  {
    "address": "helloworld/translator/translator.py:lib@resolve=python-other",
    "target_type": "python_source",
    "dependencies": [],
    "resolve": "python-other",
    "source_raw": "translator.py",
    "sources": [
      "helloworld/translator/translator.py"
    ],
    "sources_fingerprint": "143d1a81fc121bc539e5fa40c79bb8e2fa3806d84420b11b323fc88fca57a61e"
  }
]

kaos avatar May 20 '24 06:05 kaos