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

Could ruff also check files according to file's shebang? #13122

Open
praiskup opened this issue Aug 27, 2024 · 8 comments
Open

Could ruff also check files according to file's shebang? #13122

praiskup opened this issue Aug 27, 2024 · 8 comments
Labels
cli Related to the command-line interface needs-design Needs further design before implementation

Comments

@praiskup
Copy link

$ ruff  check .
warning: No Python files found under the given path(s)
All checks passed!
$ head -1 vcs-diff-lint
#! /usr/bin/python3
$ ruff check vcs-diff-lint
All checks passed!

Even though the file is not *.py, it still is a Python file and it is worth checking.

@dhruvmanila
Copy link
Member

Related #2192

tl;dr It's recommended to use the include / extend-include config options to explicitly list down the files that you want Ruff to check for. Adding support for it might come with a performance cost although not sure.

@dhruvmanila dhruvmanila added cli Related to the command-line interface wish Not on the current roadmap; maybe in the future labels Aug 28, 2024
@dhruvmanila
Copy link
Member

Does using include / extend-include solve your use case? If so, we can close this issue.

@praiskup
Copy link
Author

praiskup commented Aug 28, 2024

The differential analysis tool we develop uses Ruff as one of the backends, and while we appreciate Ruff's overall performance - analyzing the shebang is worth it in our case.

The goal is to make future project enablements (= "start using vcs-diff-lint + ruff" in more projects) as trivial as possible. Explicitly asking for include/extend-include per/project raises the initial enablement barrier, and incomplete analysis is also not nice...

That said, having something like analyze-shebangs = true opt-in would be completely fine for our use case; we can afford to spend some time on this.

@praiskup
Copy link
Author

fedora-copr/vcs-diff-lint#25 seems to help a bit here; vcs-diff-lint knows the set of changed Python, including those that do not end with *.py. So we can indeed use extend-include to at least cover those changed files, but we are still not checking unchanged non-*.py files.

praiskup added a commit to fedora-copr/vcs-diff-lint that referenced this issue Aug 28, 2024
@MichaReiser MichaReiser added needs-decision Awaiting a decision from a maintainer needs-design Needs further design before implementation and removed wish Not on the current roadmap; maybe in the future needs-decision Awaiting a decision from a maintainer labels Sep 2, 2024
@MichaReiser
Copy link
Member

Detecting all Python files based on shebang has the downside that Ruff needs to read at least the first 80 or so bytes to determine whether the file should be included in the analysis. This is significantly more costly than just looking at a file extension, so I would not want this behavior to be the default. I'm open to adding such a feature if we can come up with an interface that doesn't penalty the default use case where this isn't needed.

@praiskup
Copy link
Author

praiskup commented Sep 2, 2024

Detecting all Python files based on shebang has the downside that Ruff needs to read at least the first 80 or so

Could we, e.g., only include files with no "suffixes"? That would be the most common case, I assume.

Otherwise, opt-in is completely fine!

@pmp-p
Copy link

pmp-p commented Oct 12, 2024

Also some html files - though valid python - have a non standard shebang (like it used to be on MS-DOS) that Ruff cannot yet support/handle ( unlike black -x / python -x , fails with SyntaxError: Expected a statement )

eg source : https://github.com/pygame-web/showroom/blob/main/pygame-scripts/org.pygame.touchpong.html

for run with python-wasm or python3 -x : https://pygame-web.github.io/showroom/pygame-scripts/org.pygame.touchpong.html

ref: psf/black#3214

@praiskup
Copy link
Author

praiskup commented Dec 6, 2024

Also some html files - though valid python - have a non standard shebang

Indeed, this should be only an additional/optional analysis, and I don't think we need to have 100% success rate (nb. the basic .py suffix rule isn't 100% correct either).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli Related to the command-line interface needs-design Needs further design before implementation
Projects
None yet
Development

No branches or pull requests

4 participants