git 预提交钩子 isort 和 black 在 python 项目中一直失败

问题描述 投票:0回答:1

我有一个使用破折号来提交的项目,但是当我尝试提交以下部分时它失败了:

@app_dash.callback(
    Output("output_data_upload", "figure"),
    [Input("radioitems_x_axis", "value"), Input("checklist_y_axis", "value")],
    [State("data_store", "data")],
)
def update_figure(
    selected_signal_of_x_axis: str, selected_signal_of_y_axis: list, data: list
) -> go.Figure:
    """
    Plot the figure based on the selections of users.

    :param selected_signal_of_x_axis: a selected signal for x-ordination
    :type selected_signal_of_x_axis: str
    :param selected_signal_of_y_axis: a/several selected signal(s) for y-ordination
    :type selected_signal_of_y_axis: list
    :param data: the filtered data of the uploaded documents
    :type data: list
    :return fig: the figure which is showed on the website based on the selection of users.
    :rtype: go.Figure
    """
    fig = fig_plotting.data_plot(
        selected_signal_of_x_axis, selected_signal_of_y_axis, data
    )
    return fig

TortoiseGit的信息是这样的:

black....................................................................Failed
- hook id: black
- files were modified by this hook

reformatted ReportGeneration\subpages\measurement_chart_plot.py

All done! \u2728 \U0001f370 \u2728
1 file reformatted.

nbstripout...........................................(no files to check)Skipped
isort (python)...........................................................Failed
- hook id: isort
- files were modified by this hook

Fixing C:\Users\OneDrive - User\ReportGeneration\subpages\measurement_chart_plot.py

nbqa-black...........................................(no files to check)Skipped
nbqa-isort...........................................(no files to check)Skipped
nbqa-pylint..........................................(no files to check)Skipped
nbqa-ruff............................................(no files to check)Skipped
ruff.....................................................................Passed
[INFO] Restored changes from C:\Users\.cache\pre-commit\patch17047452450-72632.

有谁可以告诉我如何解决这个问题吗?谢谢!

python git pre-commit-hook pre-commit pre-commit.com
1个回答
0
投票

默认情况下

isort
的格式与
black

不兼容

发生的事情是 black 以一种方式格式化它,然后 isort 将其改回来

您可以通过在其配置文件中设置

profile = black
来配置isort以黑色兼容方式格式化它

或者您可以使用另一个与黑色兼容的导入分类器(例如我的

reorder-python-imports


免责声明:我写了预提交

© www.soinside.com 2019 - 2024. All rights reserved.