-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix issue #3901: environment variables parse in commands #4192
Conversation
Fixed stupid bug in UnixShellEnvironmentVariable.
Fixed bug in Script in case env_vars is None.
This comment has been minimized.
This comment has been minimized.
…GEX in case of unquoted variable assignment.
Add exclusion of some characters (&, |, <,>) in the regex ENV_VAR_VALUE_RE…
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
add file in news.
I’m inclined to use structured input instead: serve = {
cmd = "uvicorn mysite:app --reload",
env = { DEBUG = true },
} This gets rid of all the parsing and platform-specific behaviours. Multiple commands can be supported by supplying an array to I don’t think it’s a good idea to re-invent Bash command parsing. Just let the user pass in something structured, it’s easier for everyone. (And by everyone I mean including the user. Most people in the world likely don’t use shell syntaxes as a native mental model, so requireing the input to be shell syntax means they also need to “serialise” their thought.) |
@uranusjr This makes sense, I felt like I was re-inventing the wheel. |
@Hammond95 Definitely. It should continue to exist and work identically to |
Oh, I just spotted a mistake in my structured example. Environment variable values must be strings (of course): serve = {
cmd = "uvicorn mysite:app --reload",
env = { DEBUG = 'true' },
} This brings up an interesting point. We’ll either need to do some introspection before passing the env values to |
@uranusjr Yeah, that's a good point, I will give a look at this. Another question:
Does it make sense to have the options |
I had a separate discussion recently with @ncoghlan about this question. The answer is 'probably not', but most likely we should address that in a separate PR since we have a lot of extra flags and arguments being passed around |
Not sure if this requires a dedicated issue, but I have also found a possible problem in the file In the method: def build_script(self, name, extra_args=None):
try:
script = Script.parse(self.parsed_pipfile["scripts"][name])
except KeyError:
script = Script(name)
if extra_args:
script.extend(extra_args)
return script in case you provide a non-existing key, pipenv will try to treat the string as a command, so the following will work as expected:
this won't:
|
Yes, This is the desired behavior
This seems like a bug and it also seems kind of silly that we wouldn't be calling try:
script = project.build_script(command, args)
cmd_string = ' '.join([script.command] + script.args)
if environments.is_verbose():
click.echo(crayons.normal("$ {0}".format(cmd_string)), err=True)
except ScriptEmptyError:
click.echo("Can't run script {0!r}-it's empty?", err=True)
run_args = [script] I vaguely recall having a conversation with @uranusjr about this and whether there is any reason not to just parse the command all the time. @uranusjr -- can you think of any reason to tackle this a bit differently? As I recall there was a reason... |
I’m confused. Do you mean |
@uranusjr Well maybe you're right and the command provided in quotes shouldn't be run as But probably we should avoid inline command execution at all 🤔 and keep that only as a "caller" of the keys defined in the Also in this case the command ( |
Honestly, I agree (maybe except I’d keep |
Merging Master of pipenv
Issue/3901
Put back old behaviour in Script.parse.
changed back to single variable usage.
The issue
This fixes #3901
The fix
My code will fix the specific use case reported in the issue, however this code still requires some improvements in my opinion. Before proceeding with these improvement, I think that we should define which use cases this feature should cover.
Some examples:
${MYVAR} or $MY_VAR
echo "hello"; python --version
|
or&&
or||
operators?Some possible improvements
The checklist
news/
directory to describe this fix with the extension.bugfix
,.feature
,.behavior
,.doc
..vendor
. or.trivial
(this will appear in the release changelog). Use semantic line breaks and name the file after the issue number or the PR #.