python-wheel-build / fromager

Build your own wheels
https://pypi.org/project/fromager/
Apache License 2.0
3 stars 9 forks source link

quotes in env files confuse users and break builds #203

Closed dhellmann closed 1 month ago

dhellmann commented 1 month ago

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?

shubhbapna commented 1 month ago

How about a regex? Something like: .+=\"(.+)\"$

dhellmann commented 1 month ago

How about a regex? Something like: .+=\"(.+)\"$

We have a good parser in the shlex module, so I'd rather start there than trying to anticipate the way values might be formatted ourselves.

Another option is to covert those files to a different format entirely (YAML?), but having them in that format was convenient for some development tasks.

shubhbapna commented 1 month ago

I am not sure how shlex will help us get rid of the quotes. Another way is we could just check if the first and last character of the value is " and if it is then we just remove them. Similary for '

dhellmann commented 1 month ago

I am not sure how shlex will help us get rid of the quotes. Another way is we could just check if the first and last character of the value is " and if it is then we just remove them. Similary for '

I thought there was an opposite to shlex.quote, but apparently not. So, yes, the approach you mention, if the string starts and ends with the same type of quote character, remove the first and last characters, is probably safest.