You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"Interaction" with pre-commit: ideally should skip the skipped files. #3196
I ran into it before but forgot to report, and now didn't find open issue. Currently inspired by PrefectHQ/prefect#10893 where running codespell in CLI directly results in no hits, but pre-commit reports:
codespell................................................................Failed
- hook id: codespell
- exit code: 65
.github/ISSUE_TEMPLATE/5_maintenance_ticket.yaml:1: maintenence ==> maintenance
.github/workflows/python-tests.yaml:62: automaticlly ==> automatically
.github/workflows/python-tests.yaml:246: automaticlly ==> automatically
.github/ISSUE_TEMPLATE/2_ui_bug_report.yaml:69: Browers ==> Browsers
ui/package-lock.json:2999: OT ==> TO, OF, OR, NOT
ui/package-lock.json:8411: OT ==> TO, OF, OR, NOT
src/prefect/_vendor/fastapi/utils.py:131: unecessary ==> unnecessary
Problems:
If I define files to skip in codespell configuration (e.g. in .codespellrc), those files will not be skipped in pre-commit run --all since ( I guess) pre-commit would pass those paths explicitly to codespell invocation and thus it would not account for skip.
Also, complimentary, may be codespell should check in .dotdirs like .github etc?
yeah, probably since otherwise no way for all path components consideration, but then I think only the relative to CWD should be taken since otherwise the full path could contain it e.g. /home/mine/a/b/some/project/do/not/skip/me
and the same when I run from subfolder. So - relative paths. I even did modification of a single file within subfolder and invoked within subfolder -- got relative path from the top
Ran into this from a different angle and went looking for the mechanism, since the thread has the symptom well characterised but I couldn't find the line responsible written down anywhere. It's a plain asymmetry between the two branches of the file loop in _codespell.py.
The walk branch (os.path.isdir(filename)) tests the skip glob four times:
line
test
catches
:1500
glob_match.match(root)
absolute directory path
:1509
glob_match.match(file_)
basename
:1512
glob_match.match(fname)
full path
:1531
dirs[:] = [... if not glob_match.match(dir_)]
relative directory
The explicit-file branch tests it once, against the literal argument string:
elifnotglob_match.match(filename): # :1538
So skip = _vendor is matched against src/prefect/_vendor/fastapi/utils.py as a whole string, fails, and the file is checked. Same skip list, same file — the answer depends only on whether the path arrived via os.walk or via argv.
Reproducer, same tree and same typo both times:
$ codespell --skip="./src/3rdParty" .
./src/app/main.py:1: teh ==> the # vendor.py correctly skipped
$ codespell --skip="./src/3rdParty" ./src/3rdParty/vendor.py ./src/app/main.py
./src/3rdParty/vendor.py:1: teh ==> the # <-- not skipped
./src/app/main.py:1: teh ==> the
A basename pattern behaves the same way — --skip=vendor.py . skips it, --skip=vendor.py ./src/3rdParty/vendor.py doesn't. That's the :1509 check having no counterpart in the explicit branch.
This is also why it shows up as a pre-commit problem specifically: .pre-commit-hooks.yaml here is entry: codespell with types: [text], and pre-commit always passes explicit filenames, so the hook takes the one-check branch every time. Nothing about .codespellrc loading — the config is read fine, it just isn't applied to the same things.
On @DimitriPapadopoulos's "If the skip list contains b/c, it should work with all of..." and @yarikoptic's "should paths be normalised?" — I think those are still the live questions, and they're the reason I'm not opening a PR. Making the explicit branch match basenames and ancestors would start skipping files that someone who typed an explicit path may well expect to be checked, and "an explicit argument overrides the filters" is a defensible position that ripgrep and black both take. So it's a behaviour decision rather than a missing line.
If it's useful, the shapes I can see are:
Mirror the walk branch — check basename and each ancestor directory of the explicit path. Fixes pre-commit; changes behaviour for anyone relying on explicit paths winning.
Ancestors only, not basename — narrower; addresses the skip = _vendor / directory case from the original report without touching the --skip=*.js style.
Leave it, document it — say plainly in the README and --help that --skip applies to traversal, and point pre-commit users at exclude: in .pre-commit-config.yaml instead.
Existing tests don't pin any of this either way: test_ignore covers basename (--skip=bad.txt) and bare directory names, but every case goes through tmp_path, i.e. the walk branch. The one explicit-file case (--skip=*.js) only passes because the leading * happens to absorb the whole path under fnmatch.
Happy to put up whichever of the three you'd want — just don't want to guess at the semantics on a two-year-old thread where the question was already raised and not settled.
(Disclosure: AI-assisted. The reproducer, the line-by-line comparison of the two branches, and the test-coverage check are all things I ran and read rather than assumed.)
Activity
Exclude pre-commit codespell on package-lock.json and _vendored files
DimitriPapadopoulos commentedon Nov 3, 2023
.codespellrcis not taken into account when codespell is run by pre-commit?-H/--check-hiddenhelp?yarikoptic commentedon Nov 3, 2023
I think it might be more of the case of directories listed in
skipoh, it does! besides that I need to
skip.codespellrcexplicitly then. I should probably make this "default" in my "codespellit" script.DimitriPapadopoulos commentedon Nov 3, 2023
Mmmh.. I wonder whether we should always skip files named
.codespellrc.DimitriPapadopoulos commentedon Nov 3, 2023
It looks like we don't test well enough the root directory passed as an argument.
yarikoptic commentedon Nov 28, 2023
FWIW, if I have missed the point above -- seems to apply also for target filename, not just folder:
Duplicate ignore of requirements.txt and js in pre-commit config
Add codespell: workflow, (#1888)
Add codespell: workflow, (GoogleCloudPlatform#1888)
Add codespell: workflow, (GoogleCloudPlatform#1888)
yarikoptic commentedon Jan 22, 2024
ping on this issue -- any hope to get it addressed soon? need help?
Workaround for the codespell issue - duplicate exclude of testdata in…
Workaround for the codespell issue - duplicate exclude of testdata in…
DimitriPapadopoulos commentedon Jan 23, 2024
I think this one is tougher than it seems.
Suppose we have this setup:
If the skip list contains
b/c, it should work with all of:Perhaps all cases are not relevant with pre-commit, but they should be addressed nevertheless.
To properly work under Windows, the path separator may need to be normalised.
Also should paths be normalised?
Add codespell: config, workflow, pre-commit config and make it fix fe…
yarikoptic commentedon Jan 23, 2024
yeah, probably since otherwise no way for all path components consideration, but then I think only the relative to CWD should be taken since otherwise the full path could contain it e.g.
/home/mine/a/b/some/project/do/not/skip/meDimitriPapadopoulos commentedon Jan 24, 2024
It depends on how pre-commit calls codespell. Paths relative to CWD or absolute paths?
yarikoptic commentedon Jan 25, 2024
while at it (in django-rest-framework)
protocol from a single invocation of `pre-commit run --all -v codespell`
and the same when I run from subfolder. So - relative paths. I even did modification of a single file within subfolder and invoked within subfolder -- got relative path from the top
BF: pre-commit needs to duplicate some of the skips for codespell
BF: pre-commit needs to duplicate some of the skips for codespell
Add codespell: config + workflow to detect new typos. Get some typos …
We need to explicitely exclude locale/ in pre-commit for codespell du…
yarikoptic commentedon Oct 28, 2024
ping on this issue. keep running into it.
Exclude tools/string_list.json from codespell in pre-commit
We need to explicitely exclude locale/ in pre-commit for codespell du…
Use patched FakeIt
Use patched FakeIt
chuenchen309 commentedon Jul 17, 2026
Ran into this from a different angle and went looking for the mechanism, since the thread has the symptom well characterised but I couldn't find the line responsible written down anywhere. It's a plain asymmetry between the two branches of the file loop in
_codespell.py.The walk branch (
os.path.isdir(filename)) tests the skip glob four times::1500glob_match.match(root):1509glob_match.match(file_):1512glob_match.match(fname):1531dirs[:] = [... if not glob_match.match(dir_)]The explicit-file branch tests it once, against the literal argument string:
So
skip = _vendoris matched againstsrc/prefect/_vendor/fastapi/utils.pyas a whole string, fails, and the file is checked. Same skip list, same file — the answer depends only on whether the path arrived viaos.walkor viaargv.Reproducer, same tree and same typo both times:
A basename pattern behaves the same way —
--skip=vendor.py .skips it,--skip=vendor.py ./src/3rdParty/vendor.pydoesn't. That's the:1509check having no counterpart in the explicit branch.This is also why it shows up as a pre-commit problem specifically:
.pre-commit-hooks.yamlhere isentry: codespellwithtypes: [text], and pre-commit always passes explicit filenames, so the hook takes the one-check branch every time. Nothing about.codespellrcloading — the config is read fine, it just isn't applied to the same things.On @DimitriPapadopoulos's "If the skip list contains
b/c, it should work with all of..." and @yarikoptic's "should paths be normalised?" — I think those are still the live questions, and they're the reason I'm not opening a PR. Making the explicit branch match basenames and ancestors would start skipping files that someone who typed an explicit path may well expect to be checked, and "an explicit argument overrides the filters" is a defensible position thatripgrepandblackboth take. So it's a behaviour decision rather than a missing line.If it's useful, the shapes I can see are:
skip = _vendor/ directory case from the original report without touching the--skip=*.jsstyle.--helpthat--skipapplies to traversal, and point pre-commit users atexclude:in.pre-commit-config.yamlinstead.Existing tests don't pin any of this either way:
test_ignorecovers basename (--skip=bad.txt) and bare directory names, but every case goes throughtmp_path, i.e. the walk branch. The one explicit-file case (--skip=*.js) only passes because the leading*happens to absorb the whole path underfnmatch.Happy to put up whichever of the three you'd want — just don't want to guess at the semantics on a two-year-old thread where the question was already raised and not settled.
(Disclosure: AI-assisted. The reproducer, the line-by-line comparison of the two branches, and the test-coverage check are all things I ran and read rather than assumed.)