Repository: python-wheel-build/fromager

Issue:
quotes in env files confuse users and break builds
If an entry in an env file has format `NAME="value"`, the quotes are passed through to the underlying program. If we were a shell, the quotes would have been stripped and the bare value would be passed. This difference in behavior throws a lot of people off.

The simple thing to do would be strip `"` and `'` around the value. We should think about whether that's dangerous for any reason, though. Maybe only strip if both the start and end have the same quote, for example? Or maybe use the `shlex` module to do the stripping for us?

Discussion:

Patch:
diff --git a/src/fromager/overrides.py b/src/fromager/overrides.py
index ce646a5..5a1afd4 100644
--- a/src/fromager/overrides.py
+++ b/src/fromager/overrides.py
@@ -108,6 +108,9 @@ def extra_environ_for_pkg(
                 key, _, value = line.strip().partition("=")
                 key = key.strip()
                 value = value.strip()
+                # remove quotes if they surround the value
+                if value[0] == value[-1] and (value[0] == '"' or value[0] == "'"):
+                    value = value[1:-1]
                 if "$(" in value:
                     raise ValueError(f"'{value}': subshell '$()' is not supported.")
                 value = string.Template(value).substitute(template_env)


Test patch:
diff --git a/tests/test_overrides.py b/tests/test_overrides.py
index 6bd7a9c..689417e 100644
--- a/tests/test_overrides.py
+++ b/tests/test_overrides.py
@@ -68,13 +68,23 @@ def test_extra_environ_for_pkg_expansion(tmp_path: pathlib.Path):
         f.write("EGG = Python\n")
         f.write("SPAM=Monty ${EGG}!\n")
         f.write("KNIGHT=$NAME\n")
+        f.write("FOO='Bar'\n")
+        f.write("XYZ=A\"BC'\n")
+        f.write('HELLO="World"\n')
 
     with mock.patch.dict(os.environ) as environ:
         environ.clear()
         environ["NAME"] = "Ni"
         extra_environ = overrides.extra_environ_for_pkg(tmp_path, pkg_name, variant)
 
-    assert extra_environ == {"EGG": "Python", "SPAM": "Monty Python!", "KNIGHT": "Ni"}
+    assert extra_environ == {
+        "EGG": "Python",
+        "SPAM": "Monty Python!",
+        "KNIGHT": "Ni",
+        "FOO": "Bar",
+        "XYZ": "A\"BC'",
+        "HELLO": "World",
+    }
 
     # unknown key
     with env_file.open("w", encoding="utf=8") as f: