ActiveState / appdirs

A small Python module for determining appropriate platform-specific dirs, e.g. a "user data dir".
http://pypi.python.org/pypi/appdirs
MIT License
1.05k stars 98 forks source link

Explicitly decode appdirs.py as UTF-8 #152

Closed neirbowj closed 3 years ago

neirbowj commented 4 years ago

When setup.py reads appdirs.py without an encoding defined, it can sometimes fail having guessed the wrong encoding. For example:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc8 in position 129: ordinal not in range(128)

Whereas the builtin open does not accept the encoding argument until 3.0, io.open supports encoding under all versions supported by appdirs.

nchepanov commented 4 years ago

I'm seeing this problem too.

asottile commented 4 years ago

here is a reproduction with python3.6 on linux:

$ LANG=C python3 -m pip wheel .
Processing /tmp/appdirs
    ERROR: Command errored out with exit status 1:
     command: /tmp/appdirs/venv/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-aidjyogf/setup.py'"'"'; __file__='"'"'/tmp/pip-req-build-aidjyogf/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-iozfgf3t
         cwd: /tmp/pip-req-build-aidjyogf/
    Complete output (9 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-req-build-aidjyogf/setup.py", line 19, in <module>
        for line in read("appdirs.py").splitlines():
      File "/tmp/pip-req-build-aidjyogf/setup.py", line 13, in read
        out = "\n" + inf.read().replace("\r\n", "\n")
      File "/usr/lib/python3.6/encodings/ascii.py", line 26, in decode
        return codecs.ascii_decode(input, self.errors)[0]
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xc8 in position 107: ordinal not in range(128)
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
WARNING: You are using pip version 20.2.1; however, version 20.2.3 is available.
You should consider upgrading via the '/tmp/appdirs/venv/bin/python3 -m pip install --upgrade pip' command.
nchepanov commented 3 years ago

The 1.4.4 version of the package is still unusable in Python 3.

zoofood commented 3 years ago

Thanks for the submission. Cheers.