【问题标题】:Pylint setup with pre-commit In python 3.5在 python 3.5 中预提交的 Pylint 设置
【发布时间】:2020-06-30 08:34:55
【问题描述】:

我试图在我的项目中设置pylintpre-commit
我来到this 回答他们告诉我如何设置我的.pre-commit-config.yaml
当我去答案中提到的repository时,他们已经写了

此镜像仓库已弃用,请直接使用pylint

所以我这样设置我的.pre-commit-config.yaml 文件

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

但现在当我尝试这样做时

$ pre-commit run

它给出了以下错误:

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

我的项目和虚拟环境的python版本是3.5.2
这是pylintpre-commit 中的错误吗?还是我做错了什么?

【问题讨论】:

    标签: python python-3.x python-3.5 pylint pre-commit.com


    【解决方案1】:

    您似乎在设置了损坏/不正确的语言环境的环境中运行。

    通过运行env | grep -E '(LC|LANG)' 或者python3 -m locale 搜索您当前的区域设置

    如果配置正确,python 应该选择UTF-8 编码——通常你可以更正.bashrc / 等设置为无效的语言环境,或者你可以自己设置

    一个常见的值是:LANG=C.UTF-8LANG=en_US.UTF-8


    编辑:我也在修复 pylint here

    【讨论】:

    • 所以我做了env | grep -E '(LC|LANG)' & 我得到的输出是LC_CTYPE=C。我还运行了python3 -m locale,并在输出中得到了this。我.zshrc上的相关内容是this。请注意,我在虚拟环境中运行了这些命令。 LANG=en_US.UTF-8 已经在我的.zshrc 中了。我在这里错过了什么?
    • 除非这些变量被导出 (export LANG=...),否则您的zshrc 不会做任何事情
    • 哎呀,对不起,我在.zshrc 中做了export LANG=en_US.UTF-8,尝试在终端中回显它然后运行$ pre-commit run,问题仍然存在。同样的错误。
    • 这与您的 python -m locale 输出或您的示例 zshrc 粘贴不匹配,因此缺少某些内容。你能粘贴新鲜的那些输出和你的完整 zshrc 吗?
    • 如果操作正确,您应该看到:i.fluffy.cc/3LKjLq4w4LwXpkvtr4sVPlmVxv5zf7mB.html
    【解决方案2】:
    1. 首先使用下面的命令。

      pip install -U setuptools
      

      或者您可以创建新的虚拟环境。

    2. 然后手动运行预提交以确认配置。

      pre-commit run --all-files
      

      然后您可以完成 pylint 配置,例如

    回购:https://github.com/pycqa/pylint

    rev: pylint-2.4.4
    hooks:
    -   id: pylint
        args:
        - --max-line-length=80
        - --ignore-imports=yes
        - -d duplicate-code
    

    【讨论】:

      猜你喜欢
      • 2020-12-06
      • 2019-07-28
      • 1970-01-01
      • 1970-01-01
      • 2020-07-28
      • 1970-01-01
      • 2013-03-20
      • 2010-10-29
      • 1970-01-01
      相关资源
      最近更新 更多