Git Product home page Git Product logo

isort-action's Introduction

isort Github Action

This action runs isort on a Python repository.

It requires that the checkout action be used first.

Inputs

isort-version

Optional. Version of isort to use. Defaults to latest version of isort.

sort-paths

Optional. List of paths to sort, relative to your project root. Defaults to .

configuration

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

requirements-files

Optional. Paths to python requirements files to install before running isort. If multiple requirements files are provided, they should be separated by a space. If custom package installation is required, dependencies should be installed in a separate step before using this action.

Outputs

isort-result

Output of the isort CLI.

Example usage

name: Run isort
on:
  - push

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: isort/isort-action@v1
        with:
            requirements-files: "requirements.txt requirements-test.txt"

Developing

Before starting on a new feature, please review the contributing guide.

All PRs must pass the CI pipeline to be merged. To validate your code, you may run the test suite locally using docker-compose. The full test suite can be run via docker-compose run --rm lint, which will auto-format the code or add the --check-only flag to exit without formatting code.

isort-action's People

Contributors

alexjmohr avatar aljazkosir avatar dependabot[bot] avatar ftnext avatar gladykov avatar jamescurtin avatar jdufresne avatar peternewman avatar thetorpedodog avatar timobrembeck avatar ypcrumble avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

isort-action's Issues

Outdated docs on website

The documentation of the GitHub action on the isort website is outdated; inputs listed there don't match keywords used in this repo's README, e.g. sortPaths vs. sort-paths.

Also, the two links at the top of the page – "GitHub Action" and "Github Actions Marketplace" – need switching.

@v1

Would it be possible to add a v1 tag?
v1v1.0.0

Just like the v0 tag:
v0v0.1.0

isort

Default config does not report diffs, even though `--diff` appears to be executed

Docs: https://pycqa.github.io/isort/docs/configuration/github_action.html and https://github.com/isort/isort-action/blob/master/README.md say:

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

Expected behaviour:

Output including diffs, similar to what I get running isort --check-only --diff . at CLI, e.g.

isort --check-only --diff .
ERROR: C:\Users\[REDACTED]\code\elliot-100_Spond\tests\test_spond.py Imports are incorrectly sorted and/or formatted.
--- C:\Users\[REDACTED]\code\elliot-100_Spond\tests\test_spond.py:before        2024-05-22 10:26:37.165779
+++ C:\Users\[REDACTED]\code\elliot-100_Spond\tests\test_spond.py:after 2024-05-22 10:59:23.726940
@@ -1,7 +1,6 @@
 """Test suite for Spond class."""
 
 import pytest
-
 
 from spond.spond import Spond
 
Skipped 2 files

Actual behaviour:

Output does not include diffs. Extract from GitHub actions log. Note --diff does appear:

Running isort --check-only --diff .
Error: ERROR: /home/runner/work/Spond/Spond/tests/test_spond.py Imports are incorrectly sorted and/or formatted.
Error: Process completed with exit code 1.

i.e. similar to output I get on running without the --diff flag at CLI:

isort  --check-only .
ERROR: C:\Users\[REDACTED]\code\elliot-100_Spond\tests\test_spond.py Imports are incorrectly sorted and/or formatted.
Skipped 2 files

Please let me know if any extra information is required.

New release to quench the GitHub deprecation warning for `::set-output`

GitHub is deprecating the ::save-state ::set-output commands and GitHub Actions which are using them now emit a warning.

From https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/

We are monitoring telemetry for the usage of these commands and plan to fully disable them on 31st May 2023. Starting 1st June 2023 workflows using save-state or set-output commands via stdout will fail with an error.

The issue has already been fixed in master.

The isort-action always throws the following warning now

Warning: The set-output command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/

and a release would quench it.

Is the next release already scheduled? Are there specific pending tasks the community could help with for the next release? I'd be glad to help.

No verbosity at all for succesful checks

I tried to setup linting workflow using this action and it obviously works as intended, but it lacks any verbosity, even with --verbose option.

I'd expect successful workflow to output something similar to black formatter action, but there is none. Such example can be seen in this succesful check of mine. Verbosity for failed check exists, but I'd say it's also unsatisfying. Example in this failed check of mine.

Output of checks drastically differs from the one directly ran from isort cli.

Isort fails with isort: command not found

Not sure is it my config or isort bug...

2021-06-29_18h08_10

and this is my action.yml file:

---
on:
  push:
    branches: [dev, master]
  pull_request:
    branches: [dev, master]
name: Run unit tests, check code style, and upload coverage
jobs:
  test-check-code-style-and-upload-coverage:
    name: Test
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
      with:
        ref: ${{ github.head_ref }}
    - name: Prepare isort
      uses: actions/setup-python@v2
      with:
        python-version: 3.8
    - name: Execute isort
      uses: jamescurtin/isort-action@master
      with:
        requirementsFiles: "requirements.txt"

Configuration parameters not parsed correctly

The current implementation of /bin/run_isort does not parse the configuration parameters correctly.
In case more than one parameter is given, the second one is mistakenly interpreted as sortPaths and all subsequent parameters are ignored. This leads to the following error:

$ ./bin/run_isort --check-only --diff .
Running isort --check-only --diff
Error: arguments passed in without any paths or content.
::set-output name=isort-output::

                 _                 _
                (_) ___  ___  _ __| |_
                | |/ _/ / _ \/ '__  _/
                | |\__ \/\_\/| |  | |_
                |_|\___/\___/\_/   \_/

      isort your imports, so you don't have to.

                    VERSION 5.6.4


Nothing to do: no files or paths have have been passed in!

Try one of the following:

    `isort .` - sort all Python files, starting from the current directory, recursively.
    `isort . --interactive` - Do the same, but ask before making any changes.
    `isort . --check --diff` - Check to see if imports are correctly sorted within this project.
    `isort --help` - In-depth information about isort's available command-line options.

Visit https://pycqa.github.io/isort/ for complete information about how to use isort.

add action input to configure working dir

I have a project with a couple sub-packages that have their own requirement.txts, i.e.:

my-proj/
    sub-proj-foo/
        requirements.txt
    sub-proj-bar/
        requirements.txt

running the isort action doesn't pick up the third party deps, since isort is always run from the top-level root.

I'd like to be able to configure two separate isort invocations into my workflow, where I can call isort inside of sub-proj-foo and then separately inside of sub-proj-bar. Is this something you'd consider supporting?

Action fails due to missing dependency on `colorama`

I'm using this action in my project and it's failing because it doesn't find this colorama package.

Run isort/[email protected]
  with:
    configuration: --check-only --diff --profile black
    isortVersion: latest
    sortPaths: .
  env:
    pythonLocation: /opt/hostedtoolcache/Python/3.9.15/x64
    PKG_CONFIG_PATH: /opt/hostedtoolcache/Python/3.9.15/x64/lib/pkgconfig
    Python_ROOT_DIR: /opt/hostedtoolcache/Python/3.9.15/x64
    Python[2](https://github.com/getathelas/errands/actions/runs/3679172842/jobs/6223372652#step:8:2)_ROOT_DIR: /opt/hostedtoolcache/Python/[3](https://github.com/getathelas/errands/actions/runs/3679172842/jobs/6223372652#step:8:3).9.15/x6[4](https://github.com/getathelas/errands/actions/runs/3679172842/jobs/6223372652#step:8:4)
    Python3_ROOT_DIR: /opt/hostedtoolcache/Python/3.9.1[5](https://github.com/getathelas/errands/actions/runs/3679172842/jobs/6223372652#step:8:5)/x[6](https://github.com/getathelas/errands/actions/runs/3679172842/jobs/6223372652#step:8:6)4
    LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.9.15/x64/lib
Run /home/runner/work/_actions/isort/isort-action/v1.1.0/bin/ensure_python
Run /home/runner/work/_actions/isort/isort-action/v1.1.0/bin/install_packages latest 
  /home/runner/work/_actions/isort/isort-action/v1.1.0/bin/install_packages latest 
  shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
  env:
    pythonLocation: /opt/hostedtoolcache/Python/3.9.15/x64
    PKG_CONFIG_PATH: /opt/hostedtoolcache/Python/3.9.15/x64/lib/pkgconfig
    Python_ROOT_DIR: /opt/hostedtoolcache/Python/3.9.15/x64
    Python2_ROOT_DIR: /opt/hostedtoolcache/Python/3.9.15/x64
    Python3_ROOT_DIR: /opt/hostedtoolcache/Python/3.9.15/x64
    LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.9.15/x64/lib
Install isort
  Installing latest version of isort
  Collecting isort[pipfile_deprecated_finder,requirements_deprecated_finder]
    Downloading isort-5.11.0-py3-none-any.whl (118 kB)
       ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 118.5/118.5 kB 2.2 MB/s eta 0:00:00
  WARNING: isort 5.11.0 does not provide the extra 'pipfile_deprecated_finder'
  WARNING: isort 5.11.0 does not provide the extra 'requirements_deprecated_finder'
  Installing collected packages: isort
  Successfully installed isort-5.11.0
Run /home/runner/work/_actions/isort/isort-action/v1.1.0/bin/run_isort --check-only --diff --profile black .
  /home/runner/work/_actions/isort/isort-action/v1.1.0/bin/run_isort --check-only --diff --profile black .
  shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
  env:
    pythonLocation: /opt/hostedtoolcache/Python/3.9.15/x64
    PKG_CONFIG_PATH: /opt/hostedtoolcache/Python/3.9.15/x64/lib/pkgconfig
    Python_ROOT_DIR: /opt/hostedtoolcache/Python/3.9.15/x64
    Python2_ROOT_DIR: /opt/hostedtoolcache/Python/3.9.15/x64
    Python3_ROOT_DIR: /opt/hostedtoolcache/Python/3.9.15/x64
    LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.9.15/x64/lib
Running isort --check-only --diff --profile black .
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.9.15/x64/lib/python3.9/site-packages/isort/main.py", line 8[7](https://github.com/getathelas/errands/actions/runs/3679172842/jobs/6223372652#step:8:7), in sort_imports
    incorrectly_sorted = not api.check_file(file_name, config=config, **kwargs)
  File "/opt/hostedtoolcache/Python/3.9.15/x64/lib/python3.9/site-packages/isort/api.py", line 33[8](https://github.com/getathelas/errands/actions/runs/3679172842/jobs/6223372652#step:8:8), in check_file
    return check_stream(
  File "/opt/hostedtoolcache/Python/3.[9](https://github.com/getathelas/errands/actions/runs/3679172842/jobs/6223372652#step:8:9).15/x64/lib/python3.9/site-packages/isort/api.py", line 272, in check_stream
    printer = create_terminal_printer(
  File "/opt/hostedtoolcache/Python/3.9.15/x64/lib/python3.9/site-packages/isort/format.py", line 153, in create_terminal_printer
    colorama.init(strip=False)
NameError: name 'colorama' is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.9.15/x64/bin/isort", line 8, in <module>
    sys.exit(main())
  File "/opt/hostedtoolcache/Python/3.9.15/x64/lib/python3.9/site-packages/isort/main.py", line 1225, in main
    for sort_attempt in attempt_iterator:
  File "/opt/hostedtoolcache/Python/3.9.15/x64/lib/python3.9/site-packages/isort/main.py", line 1209, in <genexpr>
    sort_imports(  # type: ignore
  File "/opt/hostedtoolcache/Python/3.9.15/x64/lib/python3.9/site-packages/isort/main.py", line [11](https://github.com/getathelas/errands/actions/runs/3679172842/jobs/6223372652#step:8:11)4, in sort_imports
    _print_hard_fail(config, offending_file=file_name)
  File "/opt/hostedtoolcache/Python/3.9.15/x64/lib/python3.9/site-packages/isort/main.py", line [12](https://github.com/getathelas/errands/actions/runs/3679172842/jobs/6223372652#step:8:12)7, in _print_hard_fail
    printer = create_terminal_printer(
  File "/opt/hostedtoolcache/Python/3.9.15/x64/lib/python3.9/site-packages/isort/format.py", line 1[53](https://github.com/getathelas/errands/actions/runs/3679172842/jobs/6223372652#step:8:58), in create_terminal_printer
    colorama.init(strip=False)
NameError: name 'colorama' is not defined
Error: Process completed with exit code 1.

Error: Unable to process file command 'output' successfully

Hey, using this action in our codebase and as of yesterday it has been failing to run with Error: Unable to process file command 'output' successfully. This is our set-up:

  isort:
    runs-on: ubuntu-latest
    name: isort
    steps:
      - uses: actions/checkout@v2
      - uses: isort/isort-action@master
        with:
          configuration: "black"

Running isort with the same configuration on our codebase locally works and returns no errors and when we reverted to -uses: isort/[email protected] it ran successfully.
The issue appears to have appeared with this commit

Isort version is not optional if setting `requirementsFiles`

Thank you so much for building this! As so many people are migrating from TravisCI to GH Actions right now this is a huge help.

Here's a small bug I identified in the bash script inputs. I could see making a PR forcing named input flags instead of simple positional parameters, but I'm not sure the most elegant solution in bash. Please let me know if I could be helpful in solving this!

If requirementsFiles is set but isortVersion is unset, this code in /bin/install-packages thinks that the requirements file input is actually the isort version:

#!/usr/bin/env bash

isort_version=$1
requirements_files=$2

MacOS action + `md5sum` with 1.1.0

I don't have time to look closer until the weekend, but I noticed that 1.1.0 has an issue with MacOS

Example PR: https://github.com/kislyuk/argcomplete/pull/386/files
Workflow file: https://github.com/kislyuk/argcomplete/actions/runs/3455658420/workflow
Job: https://github.com/kislyuk/argcomplete/actions/runs/3455658420/jobs/5767837861#step:7:129

Run /Users/runner/work/_actions/isort/isort-action/v1.1.0/bin/run_isort --check-only --diff .
Running isort --check-only --diff .
/Users/runner/work/_actions/isort/isort-action/v1.1.0/bin/run_isort: line 11: md5sum: command not found
Error: Unable to process file command 'output' successfully.
Error: Invalid format 'isort-output<<'. Name must not be empty and delimiter must not be empty

On macOS machines, md5sum is provided by brew w/ md5sha1sum

Example logs

macos 11 3.7: 7_Run [email protected]

macos 11 3.10: 7_Run [email protected]

macos 12 3.10: 7_Run [email protected]

Add test cases for problem matcher logic

    > This looks great!

Thanks.

Do you think it would be possible to add a job to the test workflow that asserts the regex in isort-matcher.json matches against an expected file?

Could we compromise on merging this as is and creating an issue in the project assigned to me, then I'll try and do a more general helper action to test problem matchers, as the point you raise is valid for the others I use elsewhere too?

If isort's error message ever changed, this should be sufficient to let us know an additional pattern would need to be added.

If it was ever going to be changed, it would be beneficial to encourage them to add a separator between the filename and the error message, especially if they started to add additional error messages in future...

Originally posted by @peternewman in #66 (comment)

How to run isort-action so that it auto-fixes the code?

I am trying to run isort in a gitub-workflow in a way that it fixes the code rather than ends the workflow if the imports are unsorted:

This is my workflow setup:

name: Lint

on:
  push:
    branches:
      - testlint
  pull_request_target:
    types: [opened, synchronize, reopened]
    branches:
      - testlint

jobs:
  run-linters:
    name: Run linters
    runs-on: ubuntu-latest

    steps:
      - name: Check out git repository
        uses: actions/checkout@v3
      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: "3.11"
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install wheel
          pip install black isort
      - name: Run Black
        uses: wearerequired/[email protected]
        with:
          auto_fix: true
          black: true
          black_auto_fix: true
      - name: Run isort
        uses: isort/[email protected]
        with:
          configuration: ""

Output log of the github action:

  Successfully installed attrs-22.1.0 cached-property-1.5.2 cerberus-1.3.4 certifi-2022.9.24 charset-normalizer-2.1.1 colorama-0.4.6 distlib-0.3.6 docopt-0.6.2 idna-3.4 pep517-0.13.0 pip-api-0.0.30 pipreqs-0.4.11 plette-0.4.2 requests-2.28.1 requirementslib-2.1.0 tomlkit-0.11.6 urllib3-1.26.12 vistir-0.6.1 yarg-0.1.9
Run /home/runner/work/_actions/isort/isort-action/v1.1.0/bin/run_isort  .
  /home/runner/work/_actions/isort/isort-action/v1.1.0/bin/run_isort  .
  shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
  env:
    pythonLocation: /opt/hostedtoolcache/Python/3.11.0/x64
    PKG_CONFIG_PATH: /opt/hostedtoolcache/Python/3.11.0/x64/lib/pkgconfig
    Python_ROOT_DIR: /opt/hostedtoolcache/Python/3.11.0/x64
    Python2_ROOT_DIR: /opt/hostedtoolcache/Python/3.11.0/x64
    Python3_ROOT_DIR: /opt/hostedtoolcache/Python/3.11.0/x64
    LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.11.0/x64/lib
Running isort .

And that's it isort does not output anything anymore, the code is unsorted and stays unsorted.

I tried to run it with the default configuration (i.e. --check-only --diff). Then it runs, detects that the imports are wrongly sorted, throws the error, and the workflow ends.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.