REPETITIVE PATHS IN PYTHON PROJECTS
💡tldr: Python projects often use repetitive paths, which seems weird and un-Pythonic.
Repetitive paths are confusing for both your tools and your developers. Unnecessary nesting doesn’t help anybody (unless they’re nostalgic for monolithic SVN repos). - Ken Reitz (the guy who wrote the Requests library)
Flat is better than nested. - PEP 20 - Zen of Python
wtf is a repetitive path?
First, what is a repetitive path?
Let me show you.
Go to Flask’s Github repo.
- name of root directory:
- name of sub-directory holding source code:
# root dir: Flask ├── docs ├── flask # here, too! ├── tests
Repeating ‘flask’ = repetitive path
Same thing in mypy:
# root dir: mypy ├── docs ├── misc ├── mypy # we get it!
Django does it, and so does Celery, Guake, httpie.
There are some variations on the theme, too. pip does this:
# root dir: pip ├── docs ├── src │ └── pip # somehow better and worse simultaneously ├── tests
sqlalchemy does this:
# root dir: sqlalchemy ├── doc ├── lib │ └── sqlalchemy # fine, whatever ├── test
signs of hope
There are exceptions. pytest and Pillow both put their source code in, well,
Make sense, yes?
Pythonistas, help me understand
Strangest of all:
- my opening quote hating on repetitive paths comes from Ken Reitz
- Ken is the guy behind requests
requestsis a project whose repo, you guessed it, looks like this:
# root dir: requests ├── docs ├── requests # up is down, left is right ├── tests
I want to ask Python people about this.
I’d ask StackOverflow but the mob would sweep me away in a wave of downvotes. Maybe IRC…