serhii.net

In the middle of the desert you can say anything you want

22 Jun 2022

Directory structure for python research-y projects

Evergreen topic (Day 841 - serhii.net dealt more with “data science projects”, 220105-1142 Order of directories inside a python project is about using ./src and there’s also “put tests inside ./tests in folder/file names that directly mirror the ones in the package”).

Problem: If you have a nested package that’s loosely coupled, where do you put random stuff that’s not python package code or tests?

Things I found or learned when looking for ideas:

  1. Structuring Your Project — The Hitchhiker’s Guide to Python Suggests this structure and describes it well:
README.rst
LICENSE
setup.py
requirements.txt
sample/__init__.py
sample/core.py
sample/helpers.py
docs/conf.py
docs/index.rst
tests/test_basic.py
tests/test_advanced.py

2.What is the best project structure for a Python application? - Stack Overflow - Really nice discussion and links, including to Jp Calderone 3. Filesystem structure of a Python project - Jp Calderone — LiveJournal It had this gem that I REALLY needed to hear:

Don’t:

  • try to come up with magical hacks to make Python able to import your module or package without having the user add the directory containing it to their import path (either via PYTHONPATH or some other mechanism). You will not correctly handle all cases and users will get angry at you when your software doesn’t work in their environment.
Nel mezzo del deserto posso dire tutto quello che voglio.