ENH add --negate flag to pygrep#1643
Conversation
d1913e7 to
ee3af6f
Compare
|
Marking as ready for review as I'd like to think this is enough to tell whether it's the right direction / whether the feature would be welcome. Thanks for the 'don't put logic in tests' link! |
| for line in f: | ||
| if pattern.search(line): | ||
| retv = 0 | ||
| break |
There was a problem hiding this comment.
this can be return 0
and then below you can
else:
output.write_line(filename)
return 1There was a problem hiding this comment.
Yes, much simpler, thanks!
Though here there wouldn't be an else, would there? It's necessary to check through all the lines before deciding to return 1
There was a problem hiding this comment.
Ah, I see, thanks! I see you have a video about this too, will watch now https://youtu.be/8P7lXLXR_3c
abac169 to
8c1a551
Compare
| retv |= _process_filename_at_once(pattern, filename) | ||
| else: | ||
| retv |= _process_filename_by_line(pattern, filename) | ||
| process_fn = FNS[Choice(multiline=args.multiline, negate=args.negate)] |
There was a problem hiding this comment.
this should be outside the loop, otherwise you're doing this work every iteration instead of just once
8c1a551 to
a0658c0
Compare
|
Thank you so much for the mentorship you provided me here, I really appreciate it, it's very kind of you! |

xref this comment on StackOverflow: https://stackoverflow.com/a/64344519/9988333
A use-case comes from
PyMC3, where there is a pre-commit hook to check that all notebooks have a watermark. Currently, this is done by definingin https://github.com/pymc-devs/pymc3/blob/master/.pre-commit-config.yaml, and then
in https://github.com/pymc-devs/pymc3/blob/master/scripts/check_watermark.py .
I think the output should be a file which does not contain the pattern...I'll work on this tomorrow