Skip to content
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

poetry run could handle args better #2741

Closed
3 tasks done
rotu opened this issue Jul 28, 2020 · 5 comments
Closed
3 tasks done

poetry run could handle args better #2741

rotu opened this issue Jul 28, 2020 · 5 comments
Labels
area/cli Related to the command line area/error-handling Bad error messages/insufficient error handling kind/bug Something isn't working as expected

Comments

@rotu
Copy link
Contributor

rotu commented Jul 28, 2020

  • I am on the latest Poetry version.

  • I have searched the issues of this repo and believe that this is not a duplicate.

  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).

  • OS version and name: Ubuntu 20.04

  • Poetry version: 1.0.10

  • Link of a Gist with the contents of your pyproject.toml file: N/A

Issue

When bad arguments are passed to poetry run, it is not immediately obvious what is wrong.

When no argument is provided, poetry run does not complain about the missing argument:

$poetry run

[FileNotFoundError]
[Errno 2] No such file or directory

Contrast with poetry new:

$poetry new
Not enough arguments (missing: "path").

Similarly, if given a flag, it might not be obvious that it is looking for an executable:

$poetry run --help

[FileNotFoundError]
[Errno 2] No such file or directory
@rotu rotu added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Jul 28, 2020
@finswimmer finswimmer added area/cli Related to the command line area/error-handling Bad error messages/insufficient error handling labels Aug 3, 2020
@tomzx
Copy link
Contributor

tomzx commented Aug 7, 2020

In the current implementation, it appears that when poetry run is called without any additional parameter, run is passed as the only argument to the run command. Effectively, it is the same as poetry run run, which explains why you are seeing a "No such file or directory error.

I'm not sure why RunCommand implements a custom argument parser. If I remove RunCommand.__init__, the code seems to behave as one would expect. Running the single test test_run_passes_all_args seems to indicate there is custom logic that is necessary as otherwise the CLI parser considers poetry run python -V as similar to poetry -V and thus gets interrupted during the PRE_HANDLE step of the command dispatcher.

What I suggested seems to be what @sdispater did @ 65ba952, which was then reverted back @ 8fb4f45, so it appears to be a current limitation with clikit.

@kirelagin
Copy link

there is custom logic that is necessary as otherwise the CLI parser considers poetry run python -V as similar to poetry -V

A more-or-less standard approach is to say that, yes, this is how it is supposed to work and instead use the -- separator to stop parsing our arguments and pass everything else to the command. So your example would be poetry run -- python -V.

That will be a pretty major breaking UX change, so, as a compromise, maybe it would be better to say that everything after the first positional argument (command name) is arguments of the commands, but everything before it is ours. This would allow both poetry run python -V and poetry run --help to work.

I’d like to point out that poetry run --help not only not working, but also exiting with an extremely confusing error message is a pretty big deal.

@branchvincent
Copy link
Member

These UX issues have been fixed on master and will be released with the upcoming 1.2:

$ poetry --version
Poetry (version 1.2.0a2)
$ poetry run

Not enough arguments (missing: "args")
$ poetry run --help

Description:
  Runs a command in the appropriate environment.
...

@branchvincent branchvincent removed the status/triage This issue needs to be triaged label Feb 27, 2022
@ghost
Copy link

ghost commented Sep 8, 2023

got Not enough arguments (missing: "args") when trying to run poetry run

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/cli Related to the command line area/error-handling Bad error messages/insufficient error handling kind/bug Something isn't working as expected
Projects
None yet
Development

No branches or pull requests

5 participants