Skip to content

isort pre-commit hook can't read pyproject.toml #2397

@mpounsett

Description

@mpounsett

I have the following hook set up for use with pre-commit:

repos:
  - repo: https://github.com/PyCQA/isort
    rev: 6.0.1
    hooks:
      - id: isort
        args:
          - app
          - tests

And the following lines at the bottom of my pyproject.toml file:

[tool.isort]
line_length = 100

And this directory structure:

.
├── app
│   ├── __init__.py
│   └── ...
├── pyproject.toml
└── ...

When I run isort by hand it's seeing and honouring the line length setting in the pyproject.toml file, but when run inside the pre-commit hook it uses the default value.

I tried to explicitly set the config file in the pre-commit hook, but that gives me an error.

  - repo: https://github.com/PyCQA/isort
    rev: 6.0.1
    hooks:
      - id: isort
        args:
          - --settings-path=pyproject.toml
          - app
          - tests
% pre-commit run isort
[WARNING] Unstaged files detected.
[INFO] Stashing unstaged files to /Users/matt/.cache/pre-commit/patch1748106524-66535.
isort....................................................................Failed
- hook id: isort
- files were modified by this hook

/Users/matt/.cache/pre-commit/repo4x7ic_j_/py_env-python3.12/lib/python3.12/site-packages/isort/main.py:1124: UserWarning: A custom settings file was specified: /Users/matt/devel/my_project/pyproject.toml but no configuration was found inside. This can happen when [settings] is used as the config header instead of [isort]. See: https://pycqa.github.io/isort/docs/configuration/config_files#custom-config-files for more information.
  config = Config(**config_dict)
Fixing /Users/matt/devel/my_project/app/models.py

[INFO] Restored changes from /Users/matt/.cache/pre-commit/patch1748106524-66535.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions