LeoIannacone / npm2deb

tool to help debianize Node.js modules
GNU General Public License v3.0
46 stars 34 forks source link

npm2deb depends fails in non UTF-8 locales #59

Closed pravi closed 7 years ago

pravi commented 7 years ago
$ LANG=C npm2deb depends -b -r asn1.js
Dependencies:
NPM                                               Debian
asn1.js (4.9.1)                                   None
Traceback (most recent call last):
  File "/usr/bin/npm2deb", line 7, in <module>
    sys.exit(main(sys.argv))
  File "/usr/lib/python3/dist-packages/npm2deb/scripts.py", line 139, in main
    args.func(args)
  File "/usr/lib/python3/dist-packages/npm2deb/scripts.py", line 247, in show_dependencies
    args.force)
  File "/usr/lib/python3/dist-packages/npm2deb/helper.py", line 151, in search_for_dependencies
    result[dep]['debian'], prefix)
  File "/usr/lib/python3/dist-packages/npm2deb/helper.py", line 195, in print_formatted_dependency
    my_print(formatted.format(u"%s%s" % (prefix, npm), debian))
  File "/usr/lib/python3/dist-packages/npm2deb/helper.py", line 19, in my_print
    print(what)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
shanavas786 commented 7 years ago

The issue lies in python core. Here are some links

  1. https://bugs.python.org/issue19846
  2. http://bugs.python.org/issue28180

We can warn user like what click does here

pravi commented 7 years ago

@shanavas786 can't we convert such literals to unicode literals explicitly? At the minimum we should tell the user to choose a locale with UTF-8. We can also instruct them to run dpkg-reconfigure locales, choose a UTF-8 enabled locale and reboot.

shanavas786 commented 7 years ago

@pravi We can't convert. AFAIK, its a compatibility issue with python3 on non-utf terminals.

At the minimum we should tell the user to choose a locale with UTF-8.

Thats what click does.

$ LANG=C python3 -c 'import click; cli = click.command()(lambda:print("ok")); cli()'

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 675, in main
    _verify_python3_env()
  File "/usr/lib/python3/dist-packages/click/_unicodefun.py", line 119, in _verify_python3_env
    'mitigation steps.' + extra)
RuntimeError: Click will abort further execution because Python 3 was configured to use ASCII as encoding for the environment.  Either run this under Python 2 or consult http://click.pocoo.org/python3/ for mitigation steps.

This system supports the C.UTF-8 locale which is recommended.
You might be able to resolve your issue by exporting the
following environment variables:

    export LC_ALL=C.UTF-8
    export LANG=C.UTF-8