2

I was trying to set up pylint with pre-commit in my project.
I came to this answer where they tell how to set up my .pre-commit-config.yaml.
When I went to the repository mentioned in the answer, they had written that

This mirror repository is deprecated, use pylint directly.

So I set my .pre-commit-config.yaml file like this

-   repo: https://github.com/pycqa/pylint
    rev: pylint-2.4.4
    hooks:
    -   id: pylint
        args:
        - --limit=8
        - --rcfile=$PROJECT_ROOT/.pylintrc

But now when I tried to do

$ pre-commit run

It gave the following error:

An unexpected error has occurred: CalledProcessError: command: ('/Users/userabc/.cache/pre-commit/repokxyo7uuq/py_env-default/bin/python', '/Users/userabc/.cache/pre-commit/repokxyo7uuq/py_env-default/bin/pip', 'install', '.')
return code: 1
expected return code: 0
stdout:
    Processing /Users/userabc/.cache/pre-commit/repokxyo7uuq

stderr:
        ERROR: Command errored out with exit status 1:
         command: /Users/userabc/.cache/pre-commit/repokxyo7uuq/py_env-default/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/gm/t0h6v8jx4bqd6cj73_k27myw0000gp/T/pip-req-build-5vjdd9f2/setup.py'"'"'; __file__='"'"'/private/var/folders/gm/t0h6v8jx4bqd6cj73_k27myw0000gp/T/pip-req-build-5vjdd9f2/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 /private/var/folders/gm/t0h6v8jx4bqd6cj73_k27myw0000gp/T/pip-req-build-5vjdd9f2/pip-egg-info
             cwd: /private/var/folders/gm/t0h6v8jx4bqd6cj73_k27myw0000gp/T/pip-req-build-5vjdd9f2/
        Complete output (7 lines):
        Traceback (most recent call last):
          File "<string>", line 1, in <module>
          File "/private/var/folders/gm/t0h6v8jx4bqd6cj73_k27myw0000gp/T/pip-req-build-5vjdd9f2/setup.py", line 60, in <module>
            long_description = stream.read()
          File "/Users/userabc/.pyenv/versions/3.5.2/lib/python3.5/encodings/ascii.py", line 26, in decode
            return codecs.ascii_decode(input, self.errors)[0]
        UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 4020: 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.

Check the log at /Users/userabc/.cache/pre-commit/pre-commit.log

My project and virtual environment's python version is 3.5.2.
Is this a bug in pylint or pre-commit? Or am I doing something wrong?

anthony sottile
  • 61,815
  • 15
  • 148
  • 207
saadi
  • 646
  • 6
  • 29

2 Answers2

1

It looks like you're running in an environment with broken/incorrect locales set.

Search for your current locale setting by running env | grep -E '(LC|LANG)' and perhaps python3 -m locale

If configured correctly, python should be picking the UTF-8 encoding -- usually you can correct whatever .bashrc / etc. is setting to an invalid locale, or you can set it yourself

A common value is: LANG=C.UTF-8 or LANG=en_US.UTF-8


EDIT: I'm also fixing pylint here

anthony sottile
  • 61,815
  • 15
  • 148
  • 207
  • so i did `env | grep -E '(LC|LANG)'` & the output i got is `LC_CTYPE=C`. I also ran `python3 -m locale` and I got [this](https://freetexthost.net/aKHFnvx) in output. The relevant content on my `.zshrc` is [this](https://freetexthost.net/AzOIXGr). Note that I ran those commands while being in my virtual env. `LANG=en_US.UTF-8` is already there in my `.zshrc`. What am I missing here? – saadi Mar 19 '20 at 20:10
  • your zshrc isn't doing anything unless those variables are _exported_ (`export LANG=...`) – anthony sottile Mar 19 '20 at 22:57
  • oops, sorry my bad, I did `export LANG=en_US.UTF-8` in `.zshrc`, tried echoing it in terminal & then ran `$ pre-commit run`, the problem persists. Same error. – saadi Mar 20 '20 at 06:03
  • that doesn't match your `python -m locale` output or your sample zshrc paste so something is missing. can you paste fresh those outputs and your full zshrc? – anthony sottile Mar 20 '20 at 15:37
  • 1
    this is what you should see if done correctly: https://i.fluffy.cc/3LKjLq4w4LwXpkvtr4sVPlmVxv5zf7mB.html – anthony sottile Mar 20 '20 at 15:39
  • seems to have worked, very nice. I am accepting the answer. In case you have time, can you please tell me how did u reach this solution? I am unable to connect the dots. – saadi Mar 20 '20 at 21:36
  • I've seen the same symptoms many many times -- python determines the default locale via the environment, if it's not found it uses ascii -- the README contains UTF-8 encoded characters (not-ascii) – anthony sottile Mar 20 '20 at 22:22
0
  1. First of all use the below command.

    pip install -U setuptools
    

    or simply you may create new Virtual Environment.

  2. Then manually run the pre-commit to confirm the configurations.

    pre-commit run --all-files
    

    Then you may finalize the pylint configurations like

repo: https://github.com/pycqa/pylint

rev: pylint-2.4.4
hooks:
-   id: pylint
    args:
    - --max-line-length=80
    - --ignore-imports=yes
    - -d duplicate-code
General Grievance
  • 4,555
  • 31
  • 31
  • 45