poetry icon indicating copy to clipboard operation
poetry copied to clipboard

poetry run --directory command line help error

Open miohtama opened this issue 2 years ago • 6 comments

  • Poetry version: Poetry (version 1.5.1)

  • Python version: 3.10.8

  • OS version and name: macOS

  • [X] I am on the latest stable Poetry version, installed using a recommended method.

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

  • [x] I have consulted the FAQ and blog for any relevant entries or release notes.

Issue

When doing poetry run --help you get:

 -C, --directory=DIRECTORY  The working directory for the Poetry command (defaults to the current working directory).

However spelling out the --directory argument with = does not seem to work:

poetry run --directory=/Users/moo/code/executor/trade-executor trade-executor
Command not found: --directory=/Users/moo/code/executor/trade-executor

But it does if you use space instead of =

poetry run --directory /Users/moo/code/executor/trade-executor trade-executor
Usage: trade-executor [OPTIONS] COMMAND [ARGS]...
Try 'trade-executor --help' for help.

Error: Missing command.

miohtama avatar Jun 08 '23 20:06 miohtama

wants reporting to cleo

dimbleby avatar Jun 08 '23 21:06 dimbleby

Yeah, this is a known bug in the current CLI parser and the way Poetry implements the run command. Try putting --directory=... before run.

Secrus avatar Jun 08 '23 21:06 Secrus

@Secrus would there be any low-hanging fruits to fix this e.g. to change the command line help text?

miohtama avatar Jun 09 '23 17:06 miohtama

Yeah, this is a known bug in the current CLI parser and the way Poetry implements the run command. Try putting --directory=... before run.

Sadly, doesn't work with Poetry 1.5.1 in my case. Other commands (version, for example) work as described in documentation. So, currently there is no way to set a working directory as a part of poetry command. Hope it'll help to change status of this issue.

C:\Test>poetry --directory=C:\Test\test_project run python builds\health.py

Poetry could not find a pyproject.toml file in C:\Test or its parents

C:\Test>poetry run --directory=C:\Test\test_project python builds\health.py

Poetry could not find a pyproject.toml file in C:\Test or its parents

C:\Test>poetry --directory=test_project version
test-project 0.1.0

C:\Test>poetry --version
Poetry (version 1.5.1)

Tander avatar Aug 16 '23 11:08 Tander

@Tander I think this might be a different problem. you need to execute the poetry run command from your project's root dir (e.g. c:\Test\pyproject.toml must exist and poetry run needs to be executed from c:\Test. The idea of the directory command is to start from root and then set the given directory as cwd for the run command - at least that's what I guess from the description ;-)

LordFckHelmchen avatar Sep 13 '23 09:09 LordFckHelmchen

Then directory command doens't make much sense...

Tander avatar Sep 13 '23 18:09 Tander

This should now be fixed with recent changes to both --directory/--project flags and CLI parsing.

Secrus avatar Feb 17 '25 14:02 Secrus

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[bot] avatar Mar 20 '25 00:03 github-actions[bot]