packaging.python.org
packaging.python.org copied to clipboard
note an alternative for running src packages locally.
Upon converting a package to src structure, a user is left unable to run their code via the normal python command, python src/awesome_project/__main__.py
This PR adds an alternative approach that doesn't require an in file workaround.
📚 Documentation preview 📚: https://python-packaging-user-guide--1661.org.readthedocs.build/en/1661/discussions/src-layout-vs-flat-layout/#running-a-command-line-interface-from-source-with-src-layout
I don't think we should have this in the guide. The whole point of the src layout is to not do that, and by "that" I mean importing from the current working directory, because it is cause for shooting oneself in the foot.
If we want to have this, it should be a small foot note hidden somewhere no one looks. Well maybe not that bad, but it definitely should not be the first suggestion. The first suggestion should be to install (as editable).
If we want to have this, it should be a small foot note hidden somewhere no one looks. Well maybe not that bad, but it definitely should not be the first suggestion. The first suggestion should be to install (as editable).
Ah thank you, I see your point.
I have updated to address that.
Honestly, I share @sinoroc's sentiment on including dark sorcery into this document. Runpy scripts usually need dependencies, that are declared in the packaging metadata. So it doesn't really make sense to showcase an execution method that is broken half the time, forcing the reader to track down what they have to install. OTOH, pip install -e . will always put both dependencies and the importables on $PYTHONPATH. Always correctly.
Should we really indulge a PYTHONPATH=src/ python -m awesome_package in this case? Wouldn't it create more confusion to an entire class of newcomers?
@ekohilas looks like the concensus is that this shouldn't be in packaging guides. I'm going to close this PR so it doesn't hang around forever, but thanks for the effort nevertheless!