tbillington / kondo

Cleans dependencies and build artifacts from your projects.
MIT License
1.79k stars 51 forks source link

Does not delete all `__pycache__` directories #108

Open jwodder opened 10 months ago

jwodder commented 10 months ago

It seems that, currently, kondo only deletes __pycache__ directories located in the root of a Python project, but this is not the only place they can occur (and often there isn't even one in the root). A __pycache__ directory can be created in any directory containing a .py file, and .py files can be organized in any arbitrary assortment of directories with any depth.

tbillington commented 10 months ago

Do you have any good resources I could read about python project structures?

For example is it possible to "nest" python projects, or are all directories underneath considered part of the same "project"?

jwodder commented 10 months ago

Do you have any good resources I could read about python project structures?

Not really. In a perfect world, this would all be documented at https://packaging.python.org, but that site is still lacking in many respects after many years.

Note that __pycache__ technically isn't specific to Python "projects" (if you're defining a project as anything more than a quick script) but rather something created by the python interpreter itself when an import statement is processed[^1]; this link seems like a good overview.

[^1]: Unlike in Rust, in Python it's perfectly normal to write code without involving the packaging systems.

For example is it possible to "nest" python projects, or are all directories underneath considered part of the same "project"?

I believe best practice is against trying to nest projects, but there are various ways to abuse some of the tooling to achieve nested projects. However, I don't think I've ever actually seen nested Python projects, and you should be fine with not trying to support such a (mis)feature.