I’m a bit lost on what to do after having copied the “workaround” suggested at src layout vs flat layout - Python Packaging User Guide?
In other words, what should be done in <PKG>/__main__.py to use an SRC layout when using python -m <PKG>.
You put all the source in src including the __main__.py.
You should put your__main__.pyin “src/pkg/”.
Instead of the workaround, you can also install it using:
pip install --editable .
Often, you can also do a cd srcbefore running the code.
As an example of a small project:
$ tree ssh_wait
ssh_wait
├── LICENSE
├── pyproject.toml
├── README.md
├── run-test.sh
└── src
└── ssh_wait
├── __init__.py
└── __main__.py
Based on the feedback and Barry’s answer you can do it in multiple ways:
PYTHONPATH=./src python3 -m <pkg>_me
python3 -m src.<pkg>_me
pip install -e $PWD
cd ./src; python3 -m <pkg>_me
Regarding the “workaround” in the User Guide, I’m not sure how useful it is to use it!