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

Actually switch directory with --directory/-C #7897

Open
2 tasks done
brandonchinn178 opened this issue May 9, 2023 · 9 comments
Open
2 tasks done

Actually switch directory with --directory/-C #7897

brandonchinn178 opened this issue May 9, 2023 · 9 comments
Labels
kind/feature Feature requests/implementations status/triage This issue needs to be triaged

Comments

@brandonchinn178
Copy link
Contributor

brandonchinn178 commented May 9, 2023

  • I have searched the issues of this repo and believe that this is not a duplicate.
  • I have searched the FAQ and general documentation and believe that my question is not already covered.

Feature Request

Previous issues have been raised asking about the behavior of --directory: (#7363, #7507). They have both been closed as "working as expected", so this issue is an official request to change the behavior OR change the flag OR update the docs.

Most GNU tools like make or git will make git -C dir ... equivalent to (cd dir && git ...). Using the same flag implies the same behavior, when it's not currently the case:

this is expected. Poetry just loads the pyproject.toml from the given directory and does not switch to the directory.
#7363 (comment)

Ideally, the behavior would be changed to actually change the directory; I don't see why a simple addition of os.chdir in the beginning of the CLI main function would break things.

@brandonchinn178 brandonchinn178 added kind/feature Feature requests/implementations status/triage This issue needs to be triaged labels May 9, 2023
@dimbleby
Copy link
Contributor

dimbleby commented May 9, 2023

You don't need to make an "official request" to fix the docs, just submit a merge request - make it happen yourself!

(Reporters in both of the issues that you linked were also invited to fix the docs)

@brandonchinn178
Copy link
Contributor Author

Sure, but ideally the behavior would be changed, so this is a request mostly for that

@dimbleby
Copy link
Contributor

dimbleby commented May 9, 2023

I think a docs clarification is more likely to succeed - two issues declaring this working-as-designed tells its own story - but: same deal. If you care about this and want it to happen, your best shot is to do it yourself.

@brandonchinn178
Copy link
Contributor Author

I know the issues were closed as "working-as-designed", but I don't actually think that's the case. The original PR (#6810) says it closes #2179, but that issue is asking for the same behavior as this issue, which isn't solved by the current behavior of -C

@Makman2
Copy link

Makman2 commented Jun 7, 2023

Imo it should not change the directory, because this would defy the whole option at all. It is especially useful to run a script entrypoint via poetry run your-script from a different folder and still be able to pass files relative to your current directory as arguments that are not relative to the pyproject.toml's directory.

So yes, the feature is working as designed I would assume.

@brandonchinn178
Copy link
Contributor Author

@Makman2 I assume you meant poetry -C ../other/dir/ run entry-point?

I don't think that should be a supported usecase. If you're using another poetry project as a tool for another project, you should add it as a dependency, which will register the entrypoint in the second project so you can just do poetry run entry-point project2-file in the second project

@Makman2
Copy link

Makman2 commented Jun 7, 2023

The second project might not be a Python project, and general-purpose tools/helpers not required for building or similar should not be listed in a requirements section normally.

Without this usecase you don't have a chance to sanely invoke a Python entrypoint via poetry and reference any files on command line.

@brandonchinn178
Copy link
Contributor Author

If it's a poetry project, you should certainly add a dev group (or similar) for tools. If it's a non-poetry python project, you should install it to the environment somehow (e.g. requirements-dev.txt or just manually install into the venv venv/bin/pip install ../other/dir)

If it's not a python project, IMO you should install it the same as any other third-party dev tool you use. But as a workaround, you could always do (or write a script to do)

$(poetry -C ../other/dir/ run which entry-point) file1 file2

@MichalVasut
Copy link

I also don't understand why is poetry run exception in how it actually handles -C / --directory flag.

When I am outside of MY_PROJECT_DIR and use

  • poetry --directory=MY_PROJECT_DIR version

it works as expected. But when I run

  • poetry --directory=MY_PROJECT_DIR run MY_COMMAND

it fails with

Poetry could not find a pyproject.toml file in CURRENT_DIR or its parents

Same error as if I wouldn't use flag -C / --directory at all - it's ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Feature requests/implementations status/triage This issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

4 participants