-
Notifications
You must be signed in to change notification settings - Fork 433
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
run app appargs fix for -- double-dash #268
Conversation
A force push was recently done, so this PR will have to be rebased onto origin/master. Apologies for the inconvenience. See #270. |
I attempted to rebase this in the |
9c73737
to
545cfdf
Compare
Done--rebased. |
Note output of parse_args with monkeypatched sys.argv.
Due to tests, I found the previous method was wrong.
tests/test_run.py
Outdated
def test_appargs_doubledash(pipx_temp_env, capsys, monkeypatch): | ||
parser = pipx.main.get_command_parser() | ||
|
||
input_argv = [ | ||
["pipx", "run", "pycowsay", "--", "hello"], | ||
["pipx", "run", "pycowsay", "--", "--", "hello"], | ||
["pipx", "run", "pycowsay", "hello", "--"], | ||
["pipx", "run", "pycowsay", "hello", "--", "--"], | ||
["pipx", "run", "pycowsay", "--"], | ||
["pipx", "run", "pycowsay", "--", "--"], | ||
["pipx", "run", "--", "pycowsay", "--", "hello"], | ||
["pipx", "run", "--", "pycowsay", "--", "--", "hello"], | ||
["pipx", "run", "--", "pycowsay", "hello", "--"], | ||
["pipx", "run", "--", "pycowsay", "hello", "--", "--"], | ||
["pipx", "run", "--", "pycowsay", "--"], | ||
["pipx", "run", "--", "pycowsay", "--", "--"], | ||
] | ||
expected_appargs = [ | ||
["--", "hello"], | ||
["--", "--", "hello"], | ||
["hello", "--"], | ||
["hello", "--", "--"], | ||
["--"], | ||
["--", "--"], | ||
["--", "hello"], | ||
["--", "--", "hello"], | ||
["hello", "--"], | ||
["hello", "--", "--"], | ||
["--"], | ||
["--", "--"], | ||
] | ||
for i, input_argv in enumerate(input_argv): | ||
monkeypatch.setattr(sys, "argv", input_argv) | ||
parsed_pipx_args = pipx.main.parse_args(parser) | ||
assert parsed_pipx_args.appargs == expected_appargs[i] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome. pytest has a parameterize
decorator that adds some nice reporting if something fails. Recommend using it, but not a big deal. It does make pairing the input with the expected value a little easier to read. The way it's currently written you have to search to match up the elements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, perfect case for a parametrized test. It'll allow each one to pass or fail individually.
Alternatively, zip would be my preferred way to keep input and output iterating in sync with each other.
tests/test_run.py
Outdated
|
||
input_argv = [ | ||
["pipx", "run", "pycowsay", "--", "hello"], | ||
["pipx", "run", "pycowsay", "--", "--", "hello"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An intuitive interface to pipx
, IMO, with be to support the --
argument like nox does. pipx would forward anything after the first --
to the app. So pipx pycowsay -- hello
would say "hello", not "-- hello".
pipx run nox -- -s lint
would run nox -s lint
and pipx run nox -- -s lint -- nox_posargs
would run nox -s lint -- nox_posargs
. It looks like currently the way it's implemented in this PR, it would pass nox -- -s lint -- nox_posargs
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's how it works now. But I am confused, because before I was trying to use a pipx run
with nox in the past, and it seemed like pipx was removing the --
wherever it was. But now while writing the tests, it appears that pipx only removes the first --
if it is not inside the appargs. i.e. it may only remove the first argument after the app name if it is --
.
So somehow it seems to behave differently now than when I was testing it a week or so ago. I don't know if that's my mistake or code difference.
The other thing is that to my mind things get confusing if pipx or its argparse is doctoring anything after pipx run <appname>
In my mind I really expect that all to go verbatim to the app, as if the command line was <appname> [...]
for pipx run <appname [...]
.
If we told the user to always put a --
before <appname>
then it would basically work fine without any code modification. That was one way I was thinking about addressing this, with just specifying the help text.
Now that I see the only unwanted possible @cs01, how about I just add some text to the help to make sure that users know the first |
I think documenting that |
I think the way you prefer seems confusing to me 🙃, especially when you have two apps (like pipx and nox) getting important information (and possibly removing) the My preference would be that everything starting with the app/package name would be passed on verbatim as if instead of The way out of this currently would be to be explicit, and put the double-dash
That way I can think in my head what I'm really trying to run is
and I don't have to worry that pipx is going to remove a Is my example above ok to put as guidance in the help? To put the Otherwise to my mind we say, "pipx will remove the first double-dash after the app name, unless you also put a double-dash anywhere beforehand in the pipx command. Also if you put the double-dash later after the app name (not the first argument after the app name), it will be left intact and sent to the app." That is VERY confusing to me. |
How do either of those options compare to tools like node's |
This is a really good thought. Unfortunately it seems that that each one does it a different way, one the way I prefer, the other one like @cs01 prefers.
wheras bundler sends
|
Perfect <_< If in doubt, I'd go with npm's behaviour as a tiebreaker, as it's probably more widely used. Familiarity over purity. |
The double dash is a guideline set by POSIX in IEEE Std 1003.1, Chapter 12: Utility Conventions, subchapter 12.2: Utility Syntax Guidelines, Guideline 10:
See also: |
I understand about the double-dash, I think the discussion was more about whether our doc guidance should position the double-dash between the command to run and the list of its arguments, OR whether it should should precede both. |
It should precede both. If anything I would rather get rid of pipx's support for working without the |
Sounds perfect! |
I understand your motivation, I'm just worried it's different than expected for users accustomed to the usual unix CLI behavior of If I'm belaboring this a little, it's because it sounds like the next release of pipx my be a major API-changing one and it seems now is the time to discuss this. I always think of app and appargs being tightly coupled, as one command invocation that is run inside of a temporary pipx environment. I'm wondering if other users think the same way. One very easy solution would to make app_and_appargs all one argument, giving it the But I'll defer to @cs01 if this is just not the way you want to go. 🙂 |
Could you remind me if you are advocating for requiring |
I'd be up for not requiring anything. I'm requesting that the Because as @suominen notes, it's not the usual unix CLI behavior for a My solution would be to replace |
This sounds good to me, let's do it. |
Note that pipx does support the case of a URL being the app, but I don't think that should be unworkable with the solution you proposed. |
LMK when this is ready for review 👍 |
I've summarized our current test suite for @suominen, could you take a look at it and see if the arguments are being parsed as you expect?
|
If we all like the way AFAIK, the only changes compared to current release
|
LGTM -- thank you! |
@itsayellow you rock 🤘 Looks good besides the Windows CI failure (which is unrelated to your changes). Created #296. I am fine merging this before the Windows CI issue is fixed. |
Fixes #267
This PR allows all arguments after
pip run <app_name>
to be sent verbatim to the<app_name>
app. Currently a--
argument is possible to be removed by argparse before sending the list of arguments to the app.The code included in a new
parse_args()
function doubles a--
argument if it will be removed by argparse. argparse will only remove the first--
in a line, so this ensures that the appargs specified by the user will all be sent to the app.