Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails to detect Python projects that don't have a .py file in their root #105

Open
jwodder opened this issue Dec 7, 2023 · 2 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@jwodder
Copy link
Contributor

jwodder commented Dec 7, 2023

It appears that kondo (as of commit 69c153b) detects Python projects by looking for a file with a .py extension, at which point the directory in which this file is located is taken as the project root. However, this easily results in false negatives for modern Python packages, in which directories that need cleaning can be located above the directory of .py files.

Note the following about Python projects:

  • If a Python project is intended for distribution on PyPI, it will have a setup.py file (historical and now somewhat discouraged, but there's a lot of history), setup.cfg (declarative form of setup.py that was recommended for a while), and/or pyproject.toml file (new standard) in the project root.
  • If a Python project is not intended for distribution, it may or may not have any of setup.py/setup.cfg/pyproject.toml. If all are absent, the most reliable marker for a project root is probably a requirements.txt file, but this is purely conventional.
    • Some other reliable markers of Python project roots are configuration files for Python tools, such as tox.ini or noxfile.py.
  • Except in very simple or very messy projects, .py files tend to be organized under a directory with the same or similar name to that of the project. This directory is either located in the project root or nested inside a src/ directory in the project root (though, in the latter case, I'd expect such projects to also be the kind to have a setup.py, setup.cfg, or pyproject.toml file).
  • Due to how namespace packages are implemented, it is technically possible for the directory containing the .py files to be located inside one or more levels of otherwise-empty non-src/ directories, though I think it'd be highly unusual to do this if you weren't planning on distributing the project.
@tbillington
Copy link
Owner

Hmm, That's interesting, thank you for the context, I haven't done python in quite a while.

I have been working on a rework which allows easier use of more complicated project detection logic so this is a great example of what it would need to support.

@tbillington tbillington added the bug Something isn't working label Dec 7, 2023
@jwodder
Copy link
Contributor Author

jwodder commented Dec 8, 2023

For the record, ALE (a Vim LSP plugin) detects Python project roots as described here:

https://github.com/dense-analysis/ale/blob/32ee7039d0ee7afcc134756cfac78678cffc7017/doc/ale-python.txt#L37-L69

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants