Discussion:
[Tutor] Python application with same name as its corresponding project
Anthony DuPont
2015-07-31 15:13:48 UTC
Permalink
I am trying to setup my python application in a more standard way. In my
research, the general recommendation seems to be that if my application is
called projectgendocs, here is an acceptable structure:

ProjectParent
|-- bin/
| |-- projectgendocs.py
|
|-- projectgendocs
| |-- unittest
| | |-- __init__.py
| | |-- test_main.py
| |
| |-- __init__.py
| |-- main.py
|
|-- setup.py
|-- README


It is my understanding that ProjectParent would be added to the PYTHONPATH
so the projectgendocs project could be discovered for importing. The
problem I am encountering is that when the bin/projectgendocs.py is run, it
breaks the imports in the ProjectParent/projectgendocs files that have

import projectgendocs.somefile.py

I discovered this is due to the fact that the bin/projectgendocs is
discovered in the search for a package called projectgendocs because the
bin directory is added to the search path. I verified this by renaming the
bin/projectgendocs.py file to something different. So, my question is this:
How can a python application (the file installed in the bin folder) have
the same name as its corresponding python project and not break the
absolute imports? Or is the only way to do this is by using relative
imports?
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Chris Warrick
2015-07-31 18:16:58 UTC
Permalink
Post by Anthony DuPont
I am trying to setup my python application in a more standard way. In my
research, the general recommendation seems to be that if my application is
ProjectParent
|-- bin/
| |-- projectgendocs.py
|
|-- projectgendocs
| |-- unittest
| | |-- __init__.py
| | |-- test_main.py
| |
| |-- __init__.py
| |-- main.py
|
|-- setup.py
|-- README
It is my understanding that ProjectParent would be added to the PYTHONPATH
so the projectgendocs project could be discovered for importing. The
problem I am encountering is that when the bin/projectgendocs.py is run, it
breaks the imports in the ProjectParent/projectgendocs files that have
import projectgendocs.somefile.py
I discovered this is due to the fact that the bin/projectgendocs is
discovered in the search for a package called projectgendocs because the
bin directory is added to the search path. I verified this by renaming the
How can a python application (the file installed in the bin folder) have
the same name as its corresponding python project and not break the
absolute imports? Or is the only way to do this is by using relative
imports?
_______________________________________________
https://mail.python.org/mailman/listinfo/tutor
Don’t create custom bin/ scripts, use setuptools entry points. I
described it on my blog:

https://chriswarrick.com/blog/2014/09/15/python-apps-the-right-way-entry_points-and-scripts/
--
Chris Warrick <https://chriswarrick.com/>
PGP: 5EAAEA16
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
h
Japhy Bartlett
2015-07-31 18:28:30 UTC
Permalink
Like Chris mentions, usually you don't write your own stuff in /bin/.

To make what you've written work anyhow, you can run them from inside
/ProjectParent/, not from inside /ProjectParent/bin/.

eg, `python bin/projectgendocs.py`
Post by Anthony DuPont
Post by Anthony DuPont
I am trying to setup my python application in a more standard way. In my
research, the general recommendation seems to be that if my application
is
Post by Anthony DuPont
ProjectParent
|-- bin/
| |-- projectgendocs.py
|
|-- projectgendocs
| |-- unittest
| | |-- __init__.py
| | |-- test_main.py
| |
| |-- __init__.py
| |-- main.py
|
|-- setup.py
|-- README
It is my understanding that ProjectParent would be added to the
PYTHONPATH
Post by Anthony DuPont
so the projectgendocs project could be discovered for importing. The
problem I am encountering is that when the bin/projectgendocs.py is run,
it
Post by Anthony DuPont
breaks the imports in the ProjectParent/projectgendocs files that have
import projectgendocs.somefile.py
I discovered this is due to the fact that the bin/projectgendocs is
discovered in the search for a package called projectgendocs because the
bin directory is added to the search path. I verified this by renaming
the
Post by Anthony DuPont
bin/projectgendocs.py file to something different. So, my question is
How can a python application (the file installed in the bin folder) have
the same name as its corresponding python project and not break the
absolute imports? Or is the only way to do this is by using relative
imports?
_______________________________________________
https://mail.python.org/mailman/listinfo/tutor
Don’t create custom bin/ scripts, use setuptools entry points. I
https://chriswarrick.com/blog/2014/09/15/python-apps-the-right-way-entry_points-and-scripts/
--
Chris Warrick <https://chriswarrick.com/>
PGP: 5EAAEA16
_______________________________________________
https://mail.python.org/mailman/listinfo/tutor
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/ma

Loading...