-
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
Poetry scripts are breaking the documented behavior of sys.argv #7528
Comments
I'm not sure if I'm interpreting the docs/patch correctly, but that only appears to be fixing the issue for installed scripts. Does Poetry install scripts in editable mode? When is a script installed vs not?
|
If I remember correctly: If you don't run If you run |
Yeah, so in that case the linked PR won't help, since while you're developing you'll have the project installed in editable mode. Poetry currently turns
but it needs to generate a slightly different command that will set import sys
from importlib import import_module
mod = import_module('hello')
sys.argv[0] = mod.__file__
sys.exit(mod.run()) |
I'm saying that with the PR |
Ah ok, that makes more sense. |
There are +/- 2 sides here, I think:
As a side note, I think we can achieve both with Poetry by not rewriting |
@davidism by checking documented behavior, I don't understand how you intend to rely on it. After a few random checks, I got that For instance, I expected the following to print $ python3.10 -c "import sys; print(sys.argv)"
['-c'] |
This issue was noticed because of Werkzeug's reloader, but it's not actually related to fixing that issue or being able to relaunch a process. The issue with Poetry is that it's changing The Fixing Poetry by making it use You proposed one solution, which is to not rewrite |
Here you're overstating. Remember
It is never an acceptable fix, for the reason I mentioned above.
|
@davidism I recommend you to create a discussion (Discord or GitHub) with your point if you still feel that you need (or to create a new issue). |
@wagnerluis1982 I think @davidism was able to create a workaround to handle it on Flask's side, but I honestly don't think this is the proper fix for that I understand that For example, I have another PR that I think can be related to the same issue. On that issue, if we run a Python application without using Poetry we can successfully attach a debugger to it (using nvim-dap), but if we use Poetry it simply breaks as soon as the server launches I'm still not 100% sure it is a related issue (I still need to debug it), but based on the current discussion I'm almost sure it is |
Are we still talking about Poetry 1.3.2 behavior? If so, a fix is already provided, only waiting for 1.4.0 release to happen (very soon).
Here, while may be related to the design decisions of For all the things, do you mind to try to test with a Poetry installed on latest |
Hi @delucca, poetry 1.4.0 is released. Can you give a check with your use cases? |
@wagnerluis1982 just tried here and the issue remains 😢 |
@davidism I also tried updating Flask to the latest version, but the issue persists |
That's because there's no new version of Werkzeug yet. But that shouldn't matter, if Poetry did add the full path to the Python file in |
@davidism but you have the full path to the entry point (once is installed). If you want the full path to the module, you can simply do |
You mean the issue described in the issue? If so, did you install the entry point via |
I could see a case for if you first activate the environment and then just run Edit: or anyway, that's what happens on my operating system. In view of the "operating system dependent" I'd suggest that it's unwise to rely on the full path being available anyway |
Looks like everything works correctly with Poetry 1.4.0. from flask import Flask
app = Flask(__name__)
@app.get("/")
def index():
return "Hello, Poetry!"
def dev_server():
app.run(debug=True) [tool.poetry.scripts]
dev_server = "example:dev_server"
Both commands work as expected and the reloader works correctly.
|
As said multiple times, makes no sense |
When not installed, But as I said, this works for installed projects now, you're welcome to close it if you don't want to address uninstalled projects. |
Adding to the discussion, I feel the wrongness feeling is being fueled by the fact that So, I feel that poetry should forbid at all to run non installed entry points. What do maintainers think about it? |
At the moment, I don't see a use case why it should be necessary to run non installed entry points. However, before we forbid it we should deprecate it and see if people do complain. |
oh, do I need to run I'm running a installed entry point (the entry point of my app). I'll try it again to see if it works and let you know. |
@wagnerluis1982 okay, I ran Since I didn't add any new dependencies, I didn't know I had to run poetry install before testing. So, I think it is fixed 😄 |
I open a discussion at #7599 to we use to decide what to do with |
@wagnerluis1982 perfect 😄 I think we can close this one |
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. |
Poetry version: 1.3.2
Python version: 3.10
OS version and name: Arch Linux
pyproject.toml: Not relevant (more info on the issue)
I am on the latest stable Poetry version, installed using a recommended method.
I have searched the issues of this repo and believe that this is not a duplicate.
I have consulted the FAQ and blog for any relevant entries or release notes.
If an exception occurs when executing a command, I executed it again in debug mode (
-vvv
option) and have included the output below.Issue
This issue is a follow-up of flask#2588. You can get the full context there.
When running a script, Poetry is mutating the
sys.argv
. This breaks and violates the documented behavior ofsys.argv
and, therefore, must be avoided.Regarding the practical issue (besides breaking the documented behavior of sys.argv), Flask reloader relies on
sys.argv
to reload the application automatically. Due to this, we can't launch a Flask application with the reloader enabled due to this issue.You can replicate this bug by doing the following:
FLASK_DEBUG=1
poetry run dev
dev
(due to the fact that Poetry script is settingsys.argv = ["dev"]
FLASK_DEBUG=0
I've already opened that issue on Flask, and you can check Flask's team explanation about why this issue isn't related to them on this comment
The text was updated successfully, but these errors were encountered: