rtulke / rp

rp aka red pencil is a simple multicolor command-line tool to highlight the filtered output text.
GNU General Public License v2.0
10 stars 4 forks source link

Python 3 Support #3

Closed mathomp4 closed 3 years ago

mathomp4 commented 4 years ago

@rtulke I'm an avid user of rpen, and I just recently encountered my first system where python is python3.

Now, I was using an older fork that I re-synced up and I saw that you put python2 in the shebang. Thanks!

But with Python3, the error is:

Traceback (most recent call last):
  File "/home/mathomp4/local-SLES11/bin/rpen.py", line 45, in <module>
    op = p.communicate(input=op)[0]
  File "/discover/swdev/mathomp4/anaconda/2019.10_py3.7/2019-12-17/lib/python3.7/subprocess.py", line 939, in communicate
    stdout, stderr = self._communicate(input, endtime, timeout)
  File "/discover/swdev/mathomp4/anaconda/2019.10_py3.7/2019-12-17/lib/python3.7/subprocess.py", line 1666, in _communicate
    input_view = memoryview(self._input)
TypeError: memoryview: a bytes-like object is required, not 'str'

Now, I can get it to work in Python 3 by adding encoding to all the Popen() calls:

p = Popen(["egrep", "|".join(args), "--color=always", "-i"], stdout=PIPE, stdin=PIPE, stderr=STDOUT, env=os.environ.copy(), encoding='utf8')

but that doesn't work in Python 2.

I have been trying to figure out the end of this post: https://stackoverflow.com/a/27775464 which seems like it might have a solution...but I can't get it to work.

rtulke commented 4 years ago

Can you publish your complete working python3 example here? I tried it but it didn't work out at first go.

rtulke commented 3 years ago

fixed in rpen3.py