zenlc2000 / pyp3

Pyed Piper tool by Toby Rosen at Sony Imageworks converted to Python 3
34 stars 13 forks source link

Unmatched lines return empty lines #3

Closed bobpaul closed 7 years ago

bobpaul commented 7 years ago

In the original pyp, unmatched lines are removed. Ex:

$ echo -e "This\nis\nmany\nlines" | pyp "p.re('many')"
many

But in pyp3, all the unmatched lines appear.

$ echo -e "This\nis\nmany\nlines" | pyp3 "p.re('many')"

many
bobpaul commented 7 years ago

It looks like this was caused by the fixing of issue 10 on the old Google Code project, released as pyp-beta (pyp 2.11 is the latest version in pypi, which is what I was using). You must have based this repo on the beta code?

I believe issue 10 was fixed incorrectly. The option --ignore_blanks is defined as "remove blank lines from output". But it's implemented as "remove blank lines from input". This means that if you have non-blank lines in your input which result in a blank line of output, you get a blank line in your output. It also means you can't use --ignore_blanks with --blank_inputs n.

--ignore_blanks should be changed such that it's a filter on the output. I'll try to find the original commit(s) that implemented this so they can be reverted and this can be re-implemented as documented. doesn't look like they developed in the open; just pushed when changes were ready.

bobpaul commented 7 years ago

Also.... maybe someone should go through the examples in the manual and see how this affects them. I wouldn't be surprised if some of the examples broken by this change in default behavior.

bobpaul commented 7 years ago

After reviewing the output of pyp -h a bit more I think my proposal above was wrong.

--ignore_blanks documentation should say it removes blank lines from input. p.re() (sp.re, fp.re...) should return False for blank lines, just like filters do. If a user wants the blanks, they can use the --keep_false option. This also remains consistent with older versions of pyp.