pip-check-reqs
pip-check-reqs copied to clipboard
Encoding config support
add python script encoding config support, to handle some error like
UnicodeDecodeError: 'gbk' codec can't decode byte 0xac in position 797: illegal multibyte sequence
Thank you @iamgd67 . I know this is an old PR, but I would be happy to get a fix in for your issue.
Could you provide either/both of (ideally both) the following:
- An issue which describes how to reproduce this problem.
- A test case in this PR which fails without the fix.
in my situation, it failes because when I process files with utf-8 encoding and contains chinese character on windows platform, looks like on windows open
use gbk encoding default, and decode file failed.
It seems that ast.parse()
can handle the encoding, so we can use open(filename, mode='rb')
to solve this problem.
The gbk encoding script file should add # coding: gbk
line, see PEP263.
Thanks for the work @zhu . Please ping me when tests are passing or I can help!
Getting the same kind of error:
(venv) root@web:/var/www/html/python-tests/pronunciation-demo# pip-extra-reqs .
Traceback (most recent call last):
File "/var/www/html/python-tests/pronunciation-demo/venv/bin/pip-extra-reqs", line 8, in <module>
sys.exit(main())
File "/var/www/html/python-tests/pronunciation-demo/venv/lib/python3.9/site-packages/pip_check_reqs/find_extra_reqs.py", line 211, in main
extras = find_extra_reqs(
File "/var/www/html/python-tests/pronunciation-demo/venv/lib/python3.9/site-packages/pip_check_reqs/find_extra_reqs.py", line 35, in find_extra_reqs
used_modules = common.find_imported_modules(
File "/var/www/html/python-tests/pronunciation-demo/venv/lib/python3.9/site-packages/pip_check_reqs/common.py", line 151, in find_imported_modules
content = file_obj.read()
File "/usr/lib/python3.9/codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa4 in position 64: invalid start byte
Maybe more annoying is that it won't tell me on which file scan.