-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Teach poetry run
to find .cmd
scripts on Windows
#3395
Teach poetry run
to find .cmd
scripts on Windows
#3395
Conversation
The Poetry script generation creates `.cmd` scripts, not `.exe` files, but `poetry run` did not know to look for `.cmd` scripts resulting in a `FileNotFoundError` when running custom scripts on Windows. This doesn’t reproduce with `poetry shell` because the executable search happens in the shell (like PowerShell). Because this function now needs to search across two suffixes on Windows (and this may increase in the future due to Windows’ use of file extensions to mark a file executable), it was refactored and the negative logic flipped to read more clearly: 1. Get the path to the bin in Poetry’s environment 2. On Windows, test if path.(exe, cmd) exists, and return it (handling the existing edge case with base paths). 3. If the path (without an extension) exists, return it 4. Return the original ‘bin’ if none of the above succeeded
Related: #2481 Also look at this change: master...huwper:master From this comment: #2481 (comment) |
I see.. Maybe you all 3 could collaborate on figuring out what is the best solution, discuss the pros and cons of each approach. |
e42cdea
to
ff3383d
Compare
@sinoroc @kevincon My recommendation would be to take this PR. Setting With the logic to find binaries in place as it should be on Windows (see start's docs) P.S. Here are some of Python's own security considerations for using
|
This is the built-in Windows environment variable which lists all extensions that Windows recognizes as “executable” and should be used in place of our hard-coded list with exe and cmd.
ff3383d
to
57f6ef5
Compare
I think it would be good if a maintainer could confirm this, but my interpretation of the goal of
Yes I think that would be appropriate since you copied the code from my PR, and I saw you updated this PR already to do that, so thank you. |
Keep in mind that |
Thanks @andschwa for adding me in. Just tested it and it solves the issue I was having, however I see 2 issues still present:
Would be good to solve 1 here. Not sure what is best to do about 2 edit: maybe https://docs.python.org/dev/library/shutil.html#shutil.which is a reasonable answer in both cases |
Good to see you all collaborating. I can't help with the PR itself, since I do not know the code and to be honest I do not understand the reason why there is a need for poetry to be intrusive here (my naive assumption was that just setting some environment variable would have been enough to run a command in the virtual environment, but obviously that is not as simple). Let's ping @abn and/or @finswimmer, to hopefully help you move forward. |
I am back from holiday and would love to get this fix in. @huwper what are you suggesting, and have you tried anything in the interim? |
Hey @andschwa, your comment inspired me to try something. see this: I believe resolves the issues 1 and 2 I made above. |
…on versions. Update tests to user mocker.patch rather than hacking my own patch. Update tests for the case where the script is in the current dir
Hi, I'm sorry, but I'm sadly no longer working on Python projects at work and won't be able to work on this further. I am glad you've found a good way to do this @huwper. I'll merge that PR so it shows up here, but it looks like it may need to be rebased and such. If that's the case, please feel free to take any/all changes you need and replace this PR. |
@huwper did you get a chance to replace this PR? I hope so. I'll leave the branch around but I'm closing the PR itself (just trying to do some cleanup work). |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
The Poetry script generation creates
.cmd
scripts, not.exe
files, butpoetry run
did not know to look for.cmd
scripts resulting in aFileNotFoundError
when running custom scripts on Windows.This doesn’t reproduce with
poetry shell
because the executable search happens in the shell (like PowerShell).Because this function now needs to search across a list of suffixes on Windows (from
PATHEXT
), it was refactored and the negative logic flipped to read more clearly:PATHEXT
) exists, and return it (handling the existing edge case with base paths).Pull Request Check List