isort with precommit, toml package not installed.

Created on 12 Feb 2020  ·  5Comments  ·  Source: PyCQA/isort

I am setting up isort with pre-commit, but when I try to run it, or commit, I get this message:

git commit -m "toml plugin"gst
isort.........................................................................Failed
- hook id: isort
- files were modified by this hook

/home/shawn/.cache/pre-commit/repoivc612nw/py_env-python3.8/lib/python3.8/site-packages/isort/settings.py:358: UserWarning: Found /path/to/app/pyproject.toml with [tool.isort] section, but toml package is not installed. To configure isort with /path/to/app/pyproject.toml, install with 'isort[pyproject]'.
  warnings.warn("Found {} with [tool.isort] section, but toml package is not installed. "
Fixing apps/website/models.py

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

reformatted /path/to/app/apps/website/models.py
All done! ✨ 🍰 ✨
1 file reformatted, 2 files left unchanged.

and my relevant pyproject.toml settings:

[tool.poetry.dev-dependencies]
...
black = "=19.10b0"
isort = {extras = ["pyproject"], version = "^4.3.21"}
toml = "^0.10.0"

[tool.black]
line-length = 100
target-version = ['py38']
include = '\.pyi?$'
exclude = '''
(
  /(
      \.eggs         # exclude a few common directories in the
    | \.git          # root of the project
    | \.hg
    | \.mypy_cache
    | \.tox
    | \.venv
    | _build
    | buck-out
    | build
    | dist
    | coderedcms/project_template
    | coderedcms/tests/settings.py
    | .*/migrations
    | \.github
    | ci
    | node_modules
  )/
)
'''

[tool.isort]
line_length = 100
indent = '    '
multi_line_output = 3
import_heading_future = "Futures"
import_heading_stdlib = "Standard Library"
import_heading_thirdparty = "Third Party"
import_heading_firstparty = "Library"
import_heading_local = "Local"
include_trailing_comma = true
use_parentheses = true
force_grid_wrap = 0
question

Most helpful comment

```(yaml)
repos:

Should fix this. Pre-commit itself does not use pyproject.toml so I am not sure what would happen with a PR.

All 5 comments

I don't think this is an isort issue, but a precommit one. Either a) precommit provides a way for users to install optional dependencies (in which case you would need to do so) or precommit needs to add support for that, as it is not reasonable to require all users to include all possible combination of dependencies when isort supports so many different configuration formats. Note that the message you see, is correctly labeled a warning by isort and not an error. It will still run - just without the issue present in the toml file. So a final work around would be to put that same information into a .isort.cfg as well.

```(yaml)
repos:

Should fix this. Pre-commit itself does not use pyproject.toml so I am not sure what would happen with a PR.

@afischer-opentext-com that repo says it's deprecated and to use this repo instead.

Adding the toml dependency is basically how I fixed this. Which to me I think is the proper way to do it. However I just used a local repo to do this rather than using a git pre-commit repo.

Thanks for the hint @crypdick , using this repository now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

and-semakin picture and-semakin  ·  3Comments

lee-kagiso picture lee-kagiso  ·  4Comments

whg517 picture whg517  ·  3Comments

ghickman picture ghickman  ·  3Comments

donjar picture donjar  ·  3Comments