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

INP001: Skip scripts, for example Python files with shebang #8690

Closed
sanmai-NL opened this issue Nov 15, 2023 · 5 comments · Fixed by #8710
Closed

INP001: Skip scripts, for example Python files with shebang #8690

sanmai-NL opened this issue Nov 15, 2023 · 5 comments · Fixed by #8710
Assignees
Labels
needs-decision Awaiting a decision from a maintainer rule Implementing or modifying a lint rule

Comments

@sanmai-NL
Copy link

sanmai-NL commented Nov 15, 2023

A Python script isn't meant to be imported as a package, and so INP001 is not applicable.

image

There are multiple criteria that each imply a file is a script, in particular in combination:

  • It contains a shebang (not necessary but sufficient).
  • It's outside the src directory (only necessary and sufficient if you stick to the src-layout, perhaps).

ruff 0.1.5.

@sanmai-NL
Copy link
Author

sanmai-NL commented Nov 15, 2023

Work-around for src/ criterion in pyproject.toml. This ignores INP001 for all files not under src/.

[tool.ruff.per-file-ignores]
"[!s][!r][!c]*/**" = ["INP001"]

@charliermarsh
Copy link
Member

I thought (2) was already respected to some degree -- we skip files that are direct children of the project root, and of any of the declared src directories. This tends to catch most scripts. I'm wondering if declaring your .gitlab-ci directory as a source root would solve the problem here?

@sanmai-NL
Copy link
Author

sanmai-NL commented Nov 15, 2023

Do you mean skipped when traversing a root target directory? A CI tool/Git hook may specify a Python file path explicitly.

@charliermarsh
Copy link
Member

I mean if you have a source set, like:

[tool.ruff]
src = ["src", ".gitlab-ci"]

Then any files that are direct children of those directories get skipped.

@charliermarsh
Copy link
Member

We could ignore files with shebangs though.

@charliermarsh charliermarsh added rule Implementing or modifying a lint rule needs-decision Awaiting a decision from a maintainer labels Nov 16, 2023
@charliermarsh charliermarsh self-assigned this Nov 16, 2023
charliermarsh added a commit that referenced this issue Nov 16, 2023
## Summary

I think it's reasonable to avoid raising `INP001` for scripts, and
shebangs are one sufficient way to detect scripts.

Closes #8690.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-decision Awaiting a decision from a maintainer rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants