-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Reloader, python -m, and sys.path #461
Comments
I don't think it would not harm if Werkzeug spawned the subprocess with actually the same arguments, using |
@untitaker, I don’t understand what you mean. What’s Can we detect in Python if |
I camne across a StackOverflow answer that explained how to get the current module name. A simple test shows that in Python 2,
The In Python 3, both the module executed with So, in Python 2 we can detect if we're running with |
Also the detection is very limited either, so you only can detect inside the directly executed module if |
I just came across this bug myself. I expected the Is there any kind of workaround for this? |
Yes, one is presented in pallets/flask#1246 On 9 July 2015 15:08:30 CEST, Wayne Werner notifications@github.com wrote:
Sent from my Android device with K-9 Mail. Please excuse my brevity. |
I have a similar issue, where relative imports fail because the reloader executes the module as a non-package:
Using the comments from @untitaker, in Python < 3.3 we can detect if try:
sys.argv = ['-m', __loader__.fullname] + sys.argv[1:]
except NameError:
pass But this is quite a hacky workaround (and only for Python < 3.3). The current implementation in #531 doesn't fix this particular problem and unfortunately I don't see any way how it could. |
I think I tried to fix this with loader once, but it showed vastly On Thu, Sep 10, 2015 at 01:26:56PM -0700, Martijn Vermaat wrote:
|
The Werkzeug reloader is disabled by default due to a bug with using it in combination with `python -m mutalyzer.entrypoints.website`. pallets/werkzeug#461 (comment)
Sadly, $ python -m werkzeug.serving weasyprint.navigator:app --reload --debug
|
This bug of python can't be fixed propperly with python, so I suggest to provide a console-script |
This comment has been minimized.
This comment has been minimized.
I managed to get around the issue by doing something like: PYTHONPATH=$PWD:$PYTHONPATH python -m myapp.entrypoints.website Edit: realized the solution was just above ⬆️ |
Using absolute imports broke the debug target due to a Werkzeug bug: pallets/werkzeug#461 Solution is to avoid running Flask apps using "python -m", and to use "flask run". This also gets rid of the coverage exception for "__main__.py".
See Kozea/WeasyPrint#133
What’s going on is:
python -m weasyprint.navigator
is run[sys.executable] + sys.argv
is['…/python', '…/weasyprint/navigator.py']
-m
, so Python add’s the .py file’s parent directory tosys.path
html.entities
weasyprint/html.py
Nobody here is doing anything obviously wrong. How do you suggest dealing with this situation? What do you think of having
…/weasyprint/navigator.py
(which is expected to be mostly used withpython -m
) remove its parent directory fromsys.path
if it’s there?The text was updated successfully, but these errors were encountered: