PyCQA / isort

A Python utility / library to sort imports.
https://pycqa.github.io/isort/
MIT License
6.49k stars 580 forks source link

Docs: GitHub action and Pre-commit need better configuration/args examples #2266

Open elliot-100 opened 5 months ago

elliot-100 commented 5 months ago

I ran into the 'how do you make isort compatible with black' problem, and while I think I've resolved my issue via https://github.com/PyCQA/isort/issues/1518, I think part of the problem is that the documentation doesn't tell you how to set most configuration flags when using Github actions or pre-commit.

GitHub actions

From https://pycqa.github.io/isort/docs/configuration/github_action.html:

configuration Optional. isort configuration options to pass to the isort CLI. Defaults to --check-only --diff. ... Example usage

name: Run isort
on:
  - push

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-python@v2
        with:
          python-version: 3.8
      - uses: isort/isort-action@master
        with:
            requirementsFiles: "requirements.txt requirements-test.txt"

This seems to need an example of setting a few configuration flags. I suggest in the interests of DRY, one should be how to get config from pyproject.toml.

This part of https://github.com/isort/isort-action/blob/master/README.md seems to be identical.

pre-commit

https://pycqa.github.io/isort/docs/configuration/pre-commit.html doesn't seem to have any configuration examples in the code at all. Again perhaps one should be how to get config from pyproject.toml.

Although https://pycqa.github.io/isort/docs/configuration/black_compatibility.html does have this (doesn't have a corresponding example for GitHub actions though, I think it should):

- repo: https://github.com/pycqa/isort
    rev: 5.6.4
    hooks:
      - id: isort
        args: ["--profile", "black", "--filter-files"]

I am happy to submit a PR even if it is a strawman.

keikoro commented 5 months ago

@elliot-100 I saw your issue + comments in the other repo, only just found my way here.

Dropping the link to my issue over there as it's related: https://github.com/isort/isort-action/issues/91 (lacking/mismatched docs on the website) No clue why they created a separate org for just the action, with zero backlinks to here...