question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Local and CI/CD isort with different behaviour

See original GitHub issue

Hello,

have these lines in my .pre-commit.yaml:

- repo: https://github.com/timothycrosley/isort
    rev: 5.9.3 # should be the same as in dev.in
    hooks:
      - id: isort

and locally I have version 5.9.3 of isort. When I run pre-commit run --all-files locally, the isort is passed succesfully, but when the pre-commit is performed in git, there are some differences:

$ pre-commit run --all-files
Check hooks apply to the repository......................................Passed
Check for useless excludes...............................................Passed
Check Yaml...............................................................Passed
Check for merge conflicts................................................Passed
Fix End of Files.........................................................Passed
Trim Trailing Whitespace.................................................Passed
prettier.................................................................Passed
isort....................................................................Failed
- hook id: isort
- files were modified by this hook

Locally I am in a venv, while remotely this is performed inside a docker image:

Running with gitlab-runner 14.6.0 (5316d4ac)
  on gitlab_runner_2 UfyZYyEg
Resolving secrets
00:00
Preparing the "docker" executor
00:03
Using Docker executor with image python:3.9 ...
Pulling docker image python:3.9 ...
Using docker image sha256:f88f0508dc467046a760e8ea0bb5c5861ff4e0ade96226ca4700abd1bd28b696 for python:3.9 with digest python@sha256:bf6f8b201ffac79a1b9fded783e7f0547ad2c2e3e48e96a7a23855c3de14df4b ...

Any idea why this inconsistency? Thank you.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:5
  • Comments:19 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
kashiwachencommented, Sep 26, 2022

I got something similar. isort behaves differently at local with isort --check--profile black .. In addition, it behaves differently at project root and project sub-directory. Here is my project structure:

.
├── Dockerfile
├── README.md
├── airflow
│   ├── airflow.cfg
│   ├── dags
│   │   ├── data_dag.py

If I run isort --check --profile black ./ at root. It returns:

> Skipped 1 files

If I run isort --check --profile black ./ at dags folder. It returns:

> ERROR: ./airflow/dags/data_dag.py Imports are incorrectly sorted and/or formatted.

And the changes from isort --check --diff --profile black ./:

 from datetime import datetime, timedelta

 import pendulum
-from utils.bash_util import gen_bash_command
-from utils.convert_util import A2B
-from utils.path_util import gen_path
-
 from airflow import models
 from airflow.operators.bash import BashOperator
 from airflow.operators.python import PythonOperator
 from airflow.providers.amazon.aws.hooks.s3 import S3Hook
+
+from utils.bash_util import gen_bash_command
+from utils.convert_util import A2B
+from utils.path_util import gen_path
1reaction
danielgafnicommented, Jan 30, 2022

I have the same problem. isort suddenly started failing in my CI (in docker), while running it locally doesn’t do anything. isort version is 5.10.1, python 3.8.12.

Read more comments on GitHub >

github_iconTop Results From Across the Web

isort sorting things differently when running locally than in CI ...
When running isort locally (e.g. python -m isort . or poetry run isort . , isort seems to sort things different than in...
Read more >
Using isort with pre-commit
Older versions of isort used a lot of magic to determine import placement, that could easily break when running on CI/CD. To fix...
Read more >
How to Make your Code Shine with GitLab CI Pipelines
isort. isort is a tool that sorts imports alphabetically and automatically separated into three main sections: built-ins, third-party and local ...
Read more >
Nine simple steps for better-looking python code
When we force behavior, we save precious energy. ... Besides, I have seen how my colleagues use different folders for code ... black...
Read more >
README.rst · af012ef18e4680f2b3780d36bca9e3f25fa19a60 ...
If you find the default isort settings do not work well for your project, isort provides several ways to adjust the behavior. To...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found