[Tutor] Python application with same name as its corresponding project

Japhy Bartlett japhy at pearachute.com
Fri Jul 31 20:28:30 CEST 2015


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`

On Fri, Jul 31, 2015 at 1:16 PM, Chris Warrick <kwpolska at gmail.com> wrote:

> On 31 July 2015 at 17:13, Anthony DuPont <acdupont at mtu.edu> wrote:
> > 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  -  Tutor at python.org
> > To unsubscribe or change subscription options:
> > 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  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list