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

Chris Warrick kwpolska at gmail.com
Fri Jul 31 20:16:58 CEST 2015


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


More information about the Tutor mailing list