Python project structure
Project folder vs Source folder
Project folder
- everything we have under version control, including README
, docs
, setup.py
, etc.
Source folder
- subfolder of the project folder, contains source code mainly.
Best practice is to keep Project folder
== Source folder
.
myproject - myproject -- __init__.py -- file.py - README.md - setup.py
Tests folder
tests
project must be on the same level with the project modules, or inside each module. Not outside source folder.
Bad:
myproject - myproject -- mymodule1 -- mymodule2 - tests
It is bad because there may be another tests module in the python path or a local tests module. So from tests import ...
may be a source of errors (from myproject.tests import ...
is more reliable).
Good:
myproject - myproject -- mymodule1 -- mymodule2 -- tests
And tests per module is even better idea as we can distribute module together with tests.
Code style guide enforcement
See flake8.
myproject - .flake8
Licensed under CC BY-SA 3.0