-
Notifications
You must be signed in to change notification settings - Fork 466
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
Set exit status if a file does not exist #2157
base: master
Are you sure you want to change the base?
Set exit status if a file does not exist #2157
Conversation
6961d99
to
73d80f7
Compare
Should we |
73d80f7
to
5d08777
Compare
I'd have thought so, otherwise we'll just get a load of new bug reports for people not sure why they're getting non-zero exit codes. I guess the only question is whether there's a legitimate reason for this behaviour at all? And hence whether we need an option to be able to skip it. |
5d08777
to
553d56e
Compare
Note that |
Also, I don't think there are legitimate reasons to explictly call |
553d56e
to
1d6c2f9
Compare
Makes sense, could you chuck a comment in before parse_file in the directory case so someone doesn't got and add it in future. I assume it will complete successfully at least if that corner case was hit?
Glad you agree and nice workaround if required. I was imaginging some complicated flag to maintain.
Cool, although I meant with ls at least, you can't match a non-existent file with a glob as there's nothing to expand on. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just the comment on the dir walk to add.
Actually also are things like skip, exclude and ignore files covered too?
Indeed, after my latest changes, I have left absolutely no change in the relevant code path (directory passed as argument). |
It is irrelevant in the directory case, because in the directory case the directory exists (otherwise we don't know it is a directory): codespell/codespell_lib/_codespell.py Line 873 in 88b7d7e
|
That's not quite the same thing as whether the current code doesn't break or not...
I'm not disputing that, just suggesting we put a comment before the directory branch of parse_files saying something like "File iterated from directory which exists so don't need to check the file exists". |
Ah, I had misunderstood: you're asking about the current code, not my changes. Function codespell/codespell_lib/_codespell.py Lines 626 to 628 in bb7d185
It might fail with an exception later on, in this specific piece of code, including if the file itself it unreadable (but the enclosing directory is readable): codespell/codespell_lib/_codespell.py Line 630 in bb7d185
Then, it would again ignore the missing file: codespell/codespell_lib/_codespell.py Lines 635 to 638 in bb7d185
I could protect $ mkdir -p foo/bar
$ touch foo/bar/file
$ chmod a= foo/bar/file
$
$ cd foo
$
$ codespell
Traceback (most recent call last):
File "/home/user/.local/bin/codespell", line 11, in <module>
load_entry_point('codespell', 'console_scripts', 'codespell')()
File "/my/path/codespell/codespell_lib/_codespell.py", line 746, in _script_main
return main(*sys.argv[1:])
File "/my/path/codespell/codespell_lib/_codespell.py", line 892, in main
uri_ignore_words, context, options)
File "/my/path/codespell/codespell_lib/_codespell.py", line 630, in parse_file
text = is_text_file(filename)
File "/my/path/codespell/codespell_lib/_codespell.py", line 488, in is_text_file
with open(filename, mode='rb') as f:
PermissionError: [Errno 13] Permission denied: './bar/file'
$ I'd rather do that in a different issue / merge request though.
There is no directory branch in codespell/codespell_lib/_codespell.py Line 873 in 88b7d7e
|
1d6c2f9
to
db798cc
Compare
db798cc
to
b8a2d6c
Compare
b8a2d6c
to
9ca8af9
Compare
41d47d4
to
45dc42b
Compare
Rebased, @peternewman and @larsoner, could you have a look, time permitting? |
context, | ||
options, | ||
) | ||
if not os.path.exists(filename): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than a new conditional here, why not modify line 842 to have:
print("ERROR: file does not exist: %s" % filename, file=sys.stderr)
bad_count += 1
it seems like a better place to add the check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@larsoner I had to rebase, so I am not certain which line 842 you are referring to. Perhaps this one?
codespell/codespell_lib/_codespell.py
Line 849 in a239c80
bad_count += 1 |
In any case, the idea is that we report an error if the files passed as arguments do not exist. We are merely checking command line arguments here.
946b9b8
to
38f8626
Compare
38f8626
to
b720448
Compare
b720448
to
bd25794
Compare
bd25794
to
f53288a
Compare
Fixes #2129.