今天,预提交突然开始无法在我们的构建中安装isort钩子,并出现以下错误
[INFO] Installing environment for https://github.com/pycqa/isort.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('/builds/.../.cache/pre-commit/repo0_h0f938/py_env-python3.8/bin/python', '-mpip', 'install', '.')
return code: 1
expected return code: 0
[...]
stderr:
ERROR: Command errored out with exit status 1:
[...]
File "/tmp/pip-build-env-_3j1398p/overlay/lib/python3.8/site-packages/poetry/core/masonry/api.py", line 40, in prepare_metadata_for_build_wheel
poetry = Factory().create_poetry(Path(".").resolve(), with_groups=False)
File "/tmp/pip-build-env-_3j1398p/overlay/lib/python3.8/site-packages/poetry/core/factory.py", line 57, in create_poetry
raise RuntimeError("The Poetry configuration is invalid:\n" + message)
RuntimeError: The Poetry …Run Code Online (Sandbox Code Playgroud) 将问题镜像至:
我想配置 VSCode 如何调用isort,这样我就可以在调用Organize imports.py 文件时进行自定义。
特别是,VSCode 已开始删除两个 isort-section 之间的空行,不知道为什么。
from django...
from myproject... # removing blanck line between 2 sections
Run Code Online (Sandbox Code Playgroud) [INFO] Installing environment for https://github.com/pycqa/isort.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('/builds/.../.cache/pre-commit/repo0_h0f938/py_env-python3.8/bin/python', '-mpip', 'install', '.')
return code: 1
expected return code: 0
[...]
stderr:
ERROR: Command errored out with exit status 1:
[...]
File "/tmp/pip-build-env-_3j1398p/overlay/lib/python3.8/site-packages/poetry/core/masonry/api.py", line 40, in prepare_metadata_for_build_wheel
poetry = Factory().create_poetry(Path(".").resolve(), with_groups=False)
File "/tmp/pip-build-env-_3j1398p/overlay/lib/python3.8/site-packages/poetry/core/factory.py", line 57, in create_poetry
raise RuntimeError("The Poetry configuration is invalid:\n" + message)
RuntimeError: The Poetry configuration is invalid:
- …Run Code Online (Sandbox Code Playgroud) 我可能弄乱了一些环境路径变量。
我一边学习 Django 和虚拟环境,一边修改 VS Code,并更改了 Python 安装的目录路径。在弄清楚如何指向 VS Code 的默认 Python 路径时,我删除了一些用户路径变量。
然后,伊索开始拒绝跑步。
我尝试卸载扩展、删除 ms-python、卸载 VS Code 本身、清除 Python 工作区解释器设置,然后重新启动计算机。
即使这不是我的路径变量,任何人都知道“用户”路径变量中应该包含的默认值吗?
当使用多个检查或格式化 python 文件的工具时,有没有办法一次性设置行长度?
目前我有:
.flake8文件:
max-line-length = 120
Run Code Online (Sandbox Code Playgroud)
.isort.cfg文件:
line-length = 120
Run Code Online (Sandbox Code Playgroud)
.black文件:
line-length = 120
Run Code Online (Sandbox Code Playgroud)
.pylintrc文件:
max-line-length = 120
Run Code Online (Sandbox Code Playgroud) 我目前 isort --profile=black --line-length=79在我的项目中用作 python 文件的 linter。
这会产生垂直悬挂缩进(isort 文档类型输出中的模式 3:
from third_party import (
lib1,
lib2,
lib3,
lib4,
)
Run Code Online (Sandbox Code Playgroud)
不过,此多行模式仅适用于行长度超过 79 个字符的情况。是否有一种模式,只要同一行上有两个或多个导入,无论行有多长,都会导致多行输出?
我尝试用 破解它 isort -m=3 --trailing-comma --line-length=1,但较短的行长度会导致多行输出,即使有一个导入,这是我不想要的:
from third_party import (
lib1,
)
Run Code Online (Sandbox Code Playgroud) 我正在开发一个包含许多不同 Django 应用程序的项目。
我想在这个项目上使用isort,但是从 Django 应用程序 ( from myapp1.mymodule import myfunction) 导入的内容可以通过isort第三方导入。
我怎样才能将isort它们识别为第一方进口?
我可以添加isort配置(在.cfg):known_first_party=myapp1,myapp2...但我必须维护这个列表。
有没有更好的办法?
在project代码库中,标题为 的文件夹中有多个独立包plugins,每个包都在自己的文件夹中,setup.py其中有一个文件,项目本身是一个带有自己setup.py文件的 python 包。
我有两个文件夹project/project和plugins/myplugin_one/project_plugins/myplugin_one,我需要在适当的时候考虑first_party它们third_party。例如,在 里面plugins/myplugin_one/project_plugins/myplugin_one,有一个config.py包含以下代码的文件:
from dataclasses import dataclass, field
from typing import Any, Dict, List, Optional
# First Party
from project.core.config_store import ConfigStore
Run Code Online (Sandbox Code Playgroud)
该导入from project.core.config_store import ConfigStore被视为first_party导入,但应将其视为third_party导入,因为该文件驻留在plugins/myplugin_one/project_plugins/myplugin_one并且myplugin_one是一个独立包 ( first_party),而project在third_party此上下文中。
同样,对于驻留在 内的文件中的任何导入project/project,project/project应考虑, 并应考虑first_party从 导入。plugins/myplugin_one/project_plugins/myplugin_onethird_party
该项目的顺序sections …
Pycharm排序(我的意思是优化导入)和isort有什么区别?我找不到相关信息
从现在开始,我将在所有 Python 项目中改用 Black。到目前为止,我一直使用 autopep8 作为我的自动格式化程序和 isort 来对我的导入进行排序。但在使用 Black 时,我发现 Black 单独完成了排序工作以及格式化我的代码。虽然我不介意 Black 对导入进行排序的方式,但我仍然想使用 isort 来处理我的导入,并且我希望 Black 只处理我的代码,而不是导入。那么,有没有办法将 Black 配置为仅格式化我的代码而不触及导入?顺便说一句,我正在使用 VS Code,因此有关如何在 VS Code 中应用配置的一些帮助也会有所帮助。谢谢!
isort ×10
python ×10
pre-commit ×3
autopep8 ×1
django ×1
flake8 ×1
import ×1
pylintrc ×1
python-black ×1
sorting ×1