cuvner icon indicating copy to clipboard operation
cuvner copied to clipboard

cuvner is incompatible with ansicolors 1.1.6

Open exarkun opened this issue 7 years ago • 9 comments

(txkube) exarkun@baryon:~/Work/LeastAuthority/txkube$ git diff origin/master... | cuv diff -
skip: MANIFEST.in                                                                                                                                                                                                  
skip: README.rst                                                                                                                                                                                                   
skip: src/txkube/extra-1.5.json                                                                                                                                                                                    
b/src/txkube/__init__.py                                                                                                                                                                                           
      "IObject", "IKubernetes", "IKubernetesClient",

  

      "KubernetesError", "UnrecognizedVersion", "UnrecognizedKind",

 -    "v1", "v1beta1", "iobject_from_raw", "iobject_to_raw",


Traceback (most recent call last):
  File "/home/exarkun/Environments/txkube/bin/cuv", line 11, in <module>
    sys.exit(cuv())
  File "/home/exarkun/Environments/txkube/local/lib/python2.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/home/exarkun/Environments/txkube/local/lib/python2.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/home/exarkun/Environments/txkube/local/lib/python2.7/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/exarkun/Environments/txkube/local/lib/python2.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/exarkun/Environments/txkube/local/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/home/exarkun/Environments/txkube/local/lib/python2.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/home/exarkun/Environments/txkube/local/lib/python2.7/site-packages/cuv/cli.py", line 315, in diff
    diff_color(input_file, ctx.obj)
  File "/home/exarkun/Environments/txkube/local/lib/python2.7/site-packages/cuv/diff.py", line 117, in diff_color
    pager.echo(colors.color(u'\u258f', fg='green'), nl=False, color=True)
  File "/home/exarkun/Environments/txkube/local/lib/python2.7/site-packages/colors/colors.py", line 109, in color
    return '\x1b[{0}m{1}\x1b[0m'.format(_join(*codes), s)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u258f' in position 0: ordinal not in range(128)
(txkube) exarkun@baryon:~/Work/LeastAuthority/txkube$ 

This goes away when I downgrade ansicolors to 1.0.2.

exarkun avatar May 30 '17 19:05 exarkun

Hmm, looks like https://github.com/jonathaneunice/colors/blob/master/colors/colors.py#L109 should be a unicode literal to work properly on Python2?

meejah avatar May 30 '17 20:05 meejah

Seems plausible - but the docstring for color makes it unclear whether the function is meant to operate on bytes or unicode.

exarkun avatar May 30 '17 20:05 exarkun

otoh, reading the return docs suggests yes it should work on unicode.

exarkun avatar May 30 '17 20:05 exarkun

Merely changing that string to a unicode literal will break usage like color(encoded_utf8_bytes) though. Really, "bytes or unicode" is not a happy type to have to work with.

exarkun avatar May 30 '17 20:05 exarkun

Looks to me like this was unintended fallout from this commit: https://github.com/jonathaneunice/colors/commit/67dd97f9edf4ff527bd1ae1d23735f4c9ebad35a#diff-3358adf77afc6138373d66e0d18cd3b6L101

...because: str + unicode + str will be a unicode, but str.format(unicode) will not be...

meejah avatar May 30 '17 20:05 meejah

"Yes" to your last comment. Hmm... I'll file an issue on colors and see what we come up with? But this will just not work, ever: "something {}".format(u"\u258f") and yeah the docstring says I should be able to give it a unicode string and get a unicode back...

meejah avatar May 30 '17 20:05 meejah

Hmm, maybe @jonathaneunice can comment here? It seems colors isn't using the github bugtracker (and I don't see any other thing being used).

meejah avatar May 30 '17 20:05 meejah

I guess for now I can pin cuvner to 1.0.2

meejah avatar May 30 '17 20:05 meejah

Okay, I did that and released 17.3.0

meejah avatar May 30 '17 20:05 meejah