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

Reloader fails on setuptools script installed as an egg #1600

Closed
pokoli opened this issue Jul 5, 2019 · 6 comments

Comments

@pokoli
Copy link
Contributor

commented Jul 5, 2019

We use werkzeug as router component of trytond. Everything worked on previous versions but since 0.15 (concretly after #1416 was merged), running the server from an package script and activating the reloader causes the following error:

Traceback (most recent call last):
  File "/home/pokoli/.virtualenvs/kaialde/bin/trytond", line 4, in <module>
    __import__('pkg_resources').run_script('trytond==5.0.9', 'trytond')
  File "/home/pokoli/.virtualenvs/kaialde/lib/python3.7/site-packages/pkg_resources/__init__.py", line 666, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/home/pokoli/.virtualenvs/kaialde/lib/python3.7/site-packages/pkg_resources/__init__.py", line 1453, in run_script
    exec(code, namespace, namespace)
  File "/home/pokoli/.virtualenvs/kaialde/lib/python3.7/site-packages/trytond-5.0.9-py3.7.egg/EGG-INFO/scripts/trytond", line 47, in <module>
    use_reloader=options.dev)
  File "/home/pokoli/.virtualenvs/kaialde/lib/python3.7/site-packages/werkzeug/serving.py", line 1007, in run_simple
    run_with_reloader(inner, extra_files, reloader_interval, reloader_type)
  File "/home/pokoli/.virtualenvs/kaialde/lib/python3.7/site-packages/werkzeug/_reloader.py", line 332, in run_with_reloader
    sys.exit(reloader.restart_with_reloader())
  File "/home/pokoli/.virtualenvs/kaialde/lib/python3.7/site-packages/werkzeug/_reloader.py", line 159, in restart_with_reloader
    args = _get_args_for_reloading()
  File "/home/pokoli/.virtualenvs/kaialde/lib/python3.7/site-packages/werkzeug/_reloader.py", line 76, in _get_args_for_reloading
    if __main__.__package__ is None:
AttributeError: module '__main__' has no attribute '__package__'

pokoli added a commit to pokoli/werkzeug that referenced this issue Jul 5, 2019

User getattr for getting reloader package.
The main __script__ may not have a package when running as setup
scripts

Closes pallets#1600
@pokoli

This comment has been minimized.

Copy link
Contributor Author

commented Jul 5, 2019

The issue is present on 0.15.x but not on 0.14.x
So we need a backport for it.

@davidism davidism added the reloader label Jul 10, 2019

@davidism

This comment has been minimized.

Copy link
Member

commented Jul 10, 2019

Could you be more specific about what you mean by "a package script"? I'm fine with the fix, but I want to understand under what circumstances __main__ does not have a __package__ attribute. For example, the flask command is an entry point, and it does not seem to have this issue.

@davidism davidism changed the title Unable to launch dependendat app with entry_point Reloader fails when script is an entry_point Jul 10, 2019

@pokoli

This comment has been minimized.

Copy link
Contributor Author

commented Jul 11, 2019

@davidism I'm reproducing the issue when using trytond declared as script on setup.py

We have a package that depends on trytond, and the issue is reproducible by installing this package in editable mode (python setup.py develop or pip -e . ) on a virtualenv. I'm using python3.7

Here are my steps to reproduce it:

mkvirtualenv test 
hg clone https://hg.tryton.org/modules/stock -b 5.2
cd stock
python setup.py develop
trytond --dev

Please note that the --dev flag is required in order to activate the reloader, so the issue is not pressent without this flag.

Let me know if this is enought or you need some additional information.

@davidism

This comment was marked as outdated.

Copy link
Member

commented Jul 11, 2019

I could not reproduce this issue with the following sample project:

setup.py:

from setuptools import setup

setup(
    name="example",
    version="0.1.0",
    py_modules=["app"],
    scripts=["scripts/run-example.py"],
)

scripts/run-example.py:

from werkzeug.serving import run_simple
from app import app

run_simple("localhost", 5000, app, use_reloader=True)

app.py:

from flask import Flask

app = Flask(__name__)

@app.route("/")
def index():
    return "Hello, World!"
@davidism

This comment has been minimized.

Copy link
Member

commented Jul 12, 2019

This only occurs when you do python setup.py develop, not pip install -e ., because develop uses setuptools to do the install, and that results in eggs being installed. On the other hand, pip always installs packages unzipped.

I think setuptools maintainers are trying to move away from setuptools being the thing that manages the environment, in favor of pip, so you'll probably have a better compatibility experience in general by using pip install -e . going forward. That said, eggs should still be supported for now, so I'll merge the fix.

@davidism davidism changed the title Reloader fails when script is an entry_point Reloader fails on setuptools script installed as an egg Jul 12, 2019

@davidism davidism added this to the 0.15.5 milestone Jul 12, 2019

@davidism davidism closed this Jul 12, 2019

@pokoli

This comment has been minimized.

Copy link
Contributor Author

commented Jul 12, 2019

Thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.