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.

# root dir: Flask
β”œβ”€β”€ docs
β”œβ”€β”€ flask # here, too!
β”œβ”€β”€ tests

Repeating ‘flask’ = repetitive path


repeat offendersξ…—

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, src.

Make sense, yes?


Pythonistas, help me understandξ…—

Strangest of all:

# 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…