a.t*_*.t. 2 pre-commit pre-commit-hook conda pre-commit.com
在尝试使用预提交挂钩时,我遇到了一些困难,包括Intel在 Conda 环境中以格式包形式发布的最新 Lava-nc 。.tar.gz pip
environment.yaml使用以下 Conda文件:
# This file is to automatically configure your environment. It allows you to
# run the code with a single command without having to install anything
# (extra).
# First run:: conda env create --file environment.yml
# If you change this file, run: conda env update --file environment.yml
# Instructions for this networkx-to-lava-nc repository only. First time usage
# On Ubuntu (this is needed for lava-nc):
# sudo apt upgrade
# sudo apt full-upgrade
# yes | sudo apt install gcc
# Conda configuration settings. (Specify which modules/packages are installed.)
name: networkx-to-lava
channels:
- conda-forge
- conda
dependencies:
- anaconda
- conda:
# Run python tests.
- pytest-cov
- pip
- pip:
# Run pip install on .tar.gz file in GitHub repository (For lava-nc only).
- https://github.com/lava-nc/lava/releases/download/v0.3.0/lava-nc-0.3.0.tar.gz
# Auto check static typing.
- mypy
# Auto check programming style aspects.
- pylint
Run Code Online (Sandbox Code Playgroud)
如果我包括以下 MWE .pre-commit-config.yaml:
repos:
# Test if the variable typing is correct
# - repo: https://github.com/python/mypy
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.950
hooks:
- id: mypy
Run Code Online (Sandbox Code Playgroud)
和都git commit "something"返回pre-commit run --all-files:
[INFO] Installing environment for https://github.com/pre-commit/mirrors-mypy.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('/home/name/anaconda3/envs/networkx-to-lava/bin/python3.1', '-mvirtualenv', '/home/name/.cache/pre-commit/repolk_aet_q/py_env-python3.1', '-p', 'python3.1')
return code: 1
expected return code: 0
stdout:
RuntimeError: failed to find interpreter for Builtin discover of python_spec='python3.1'
stderr: (none)
Check the log at /home/name/.cache/pre-commit/pre-commit.log
Run Code Online (Sandbox Code Playgroud)
的输出pre-commit.log是:
### version information
pre-commit version: 2.19.0
git --version: git version 2.30.2
sys.version:
3.10.4 | packaged by conda-forge | (main, Mar 24 2022, 17:39:04) [GCC 10.3.0]
sys.executable: /home/name/anaconda3/envs/networkx-to-lava/bin/python3.1
os.name: posix
sys.platform: linux
### error information
An unexpected error has occurred: CalledProcessError: command: ('/home/name/anaconda3/envs/networkx-to-lava/bin/python3.1', '-mvirtualenv', '/home/name/.cache/pre-commit/repolk_aet_q/py_env-python3.1', '-p', 'python3.1')
return code: 1
expected return code: 0
stdout:
RuntimeError: failed to find interpreter for Builtin discover of python_spec='python3.1'
stderr: (none)
Traceback (most recent call last):
File "/home/name/anaconda3/envs/networkx-to-lava/lib/python3.10/site-packages/pre_commit/error_handler.py", line 73, in error_handler
yield
File "/home/name/anaconda3/envs/networkx-to-lava/lib/python3.10/site-packages/pre_commit/main.py", line 361, in main
return hook_impl(
File "/home/name/anaconda3/envs/networkx-to-lava/lib/python3.10/site-packages/pre_commit/commands/hook_impl.py", line 238, in hook_impl
return retv | run(config, store, ns)
File "/home/name/anaconda3/envs/networkx-to-lava/lib/python3.10/site-packages/pre_commit/commands/run.py", line 414, in run
install_hook_envs(to_install, store)
File "/home/name/anaconda3/envs/networkx-to-lava/lib/python3.10/site-packages/pre_commit/repository.py", line 223, in install_hook_envs
_hook_install(hook)
File "/home/name/anaconda3/envs/networkx-to-lava/lib/python3.10/site-packages/pre_commit/repository.py", line 79, in _hook_install
lang.install_environment(
File "/home/name/anaconda3/envs/networkx-to-lava/lib/python3.10/site-packages/pre_commit/languages/python.py", line 219, in install_environment
cmd_output_b(*venv_cmd, cwd='/')
File "/home/name/anaconda3/envs/networkx-to-lava/lib/python3.10/site-packages/pre_commit/util.py", line 146, in cmd_output_b
raise CalledProcessError(returncode, cmd, retcode, stdout_b, stderr_b)
pre_commit.util.CalledProcessError: command: ('/home/name/anaconda3/envs/networkx-to-lava/bin/python3.1', '-mvirtualenv', '/home/name/.cache/pre-commit/repolk_aet_q/py_env-python3.1', '-p', 'python3.1')
return code: 1
expected return code: 0
stdout:
RuntimeError: failed to find interpreter for Builtin discover of python_spec='python3.1'
stderr: (none)
Run Code Online (Sandbox Code Playgroud)
如果我删除该文件,就会避免此错误/home/name/anaconda3/envs/networkx-to-lava/bin/python3.1。然而,这破坏了自动化,并且似乎是一个不恰当的解决方法。
如何确保创建和激活 Conda 环境允许直接运行预提交挂钩而不会出现错误(无需删除文件python3.1)?
不幸的是,这是一个已知的错误conda——尽管我不熟悉它的状态。他们错误地发送了一个python3.1二进制文件作为默认可执行文件(应该调用它python3.10——他们有一个2020 年的问题,可能是某个sys.version[:3]地方的问题)
幸运的是,您可以指示预提交忽略其“默认”版本检测(正在检测您的python3.1可执行文件)并为其提供有关使用哪个 python 版本的特定指令
有两种方法:
default_language_version:作为“默认”,language_version未设置时适用default_language_version:
python: python3.10 # or python3
# ...
Run Code Online (Sandbox Code Playgroud)
language_version在特定的钩子上(覆盖钩子提供者设置的任何默认值)# ...
- id: black
language_version: python3.10
Run Code Online (Sandbox Code Playgroud)
免责声明:我创建了预提交
| 归档时间: |
|
| 查看次数: |
9166 次 |
| 最近记录: |