So I'm trying to expand my knowledge and skill of Python by moving from small scripts and web development to desktop applications, and am having some trouble understanding entry points with setup.py
and the effect they have on imports. I also don't have a deep understanding of how imports work in Python, which doesn't help.
My confusion comes from looking at example code of a large desktop application, specifically Deluge, a torrenting app written in Python.
Looking at it's code, it seems that all imports for its own modules are absolute, for example:
# deluge/core/core.py
import deluge.common
from deluge.core.eventmanager import EventManager
But interestingly all it's entrypoints, as defined in setup.py
are also deeper within the program:
# setup.py
entry_points = {
'console_scripts': [
'deluge-console = deluge.ui.console:start',
'deluge-web = deluge.ui.web:start',
'deluged = deluge.core.daemon_entry:start_daemon'
],
'gui_scripts': [
'deluge = deluge.ui.ui_entry:start_ui',
'deluge-gtk = deluge.ui.gtkui:start'
],
'deluge.ui': [
'console = deluge.ui.console:Console',
'web = deluge.ui.web:Web',
'gtk = deluge.ui.gtkui:Gtk',
],
}
From what I can tell, according to the answer for this SO question, this would not normally be possible. To use absolute imports the program would have to be started from a file in the projects root.
As far as my understanding goes, deluge must be changing its PYTHONPATH somehow, such as with sys.path
, however searching the code only finds one instance of it, but it only seems to be related to the documentation, not the actually software code.
So how would one have an entry point for their Python program deeper within the modules, but use absolute imports from the project root? Deluge seems to have done it, but I don't know how, and I would like to do so in my project.
And as a side question, if you know of any other large desktop apps written in Python that I can look at for examples, I'd love it if you told me about it :)
Cheers