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
Closed

Reloader fails on setuptools script installed as an egg #1600

pokoli opened this issue Jul 5, 2019 · 6 comments
Labels
Milestone

Comments

@pokoli
Copy link

pokoli 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 pushed a commit to pokoli/werkzeug that referenced this issue Jul 5, 2019
The main __script__ may not have a package when running as setup
scripts

Closes pallets#1600
@pokoli
Copy link
Author

pokoli 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
Copy link
Member

davidism 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
Copy link
Author

pokoli 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 has been minimized.

@davidism
Copy link
Member

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
@pokoli
Copy link
Author

pokoli commented Jul 12, 2019

Thanks!!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants