Skip to content

Commit

Permalink
fIx isort problems introduced by recent isort release (#28434)
Browse files Browse the repository at this point in the history
The recent isort changed their mind on sorting the imports. This
change follows the change and bumps isort to latest released
version (isort has no install_requires on its own so bumping
min version has no effect on other dependencies)

This change adds a number of isort:skip_file, isort:off, isort:skips
in order to handle a very annoying bug in isort, that no matter how
much you try, it sometimes treat "known first party" packages
differently - depending on how many files it processes at a time.

We should be able to restore it after this bug is fixed:
PyCQA/isort#2045

This change also updates the common.sql API to skip them from isort
for the very same reason (depending on how many files are modified,
the isort order might change.

(cherry picked from commit f115b20)
  • Loading branch information
potiuk authored and ephraimbuddy committed Jan 12, 2023
1 parent 8dd1497 commit d7db157
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 9 deletions.
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Expand Up @@ -146,6 +146,11 @@ repos:
- --fuzzy-match-generates-todo
files: >
\.cfg$|\.conf$|\.ini$|\.ldif$|\.properties$|\.readthedocs$|\.service$|\.tf$|Dockerfile.*$
- repo: https://github.com/PyCQA/isort
rev: 5.11.2
hooks:
- id: isort
name: Run isort to sort imports in Python files
# Keep version of black in sync wit blacken-docs and pre-commit-hook-names
- repo: https://github.com/psf/black
rev: 22.12.0
Expand Down Expand Up @@ -233,11 +238,6 @@ repos:
entry: yamllint -c yamllint-config.yml --strict
types: [yaml]
exclude: ^.*init_git_sync\.template\.yaml$|^.*airflow\.template\.yaml$|^chart/(?:templates|files)/.*\.yaml$|openapi/.*\.yaml$|^\.pre-commit-config\.yaml$|^airflow/_vendor/
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
- id: isort
name: Run isort to sort imports in Python files
- repo: https://github.com/pycqa/pydocstyle
rev: 6.1.1
hooks:
Expand Down
4 changes: 4 additions & 0 deletions docker_tests/test_docker_compose_quick_start.py
Expand Up @@ -27,10 +27,14 @@
from unittest import mock

import requests

# isort:off (needed to workaround isort bug)
from docker_tests.command_utils import run_command
from docker_tests.constants import SOURCE_ROOT
from docker_tests.docker_tests_utils import docker_image

# isort:on (needed to workaround isort bug)

AIRFLOW_WWW_USER_USERNAME = os.environ.get("_AIRFLOW_WWW_USER_USERNAME", "airflow")
AIRFLOW_WWW_USER_PASSWORD = os.environ.get("_AIRFLOW_WWW_USER_PASSWORD", "airflow")
DAG_ID = "example_bash_operator"
Expand Down
3 changes: 3 additions & 0 deletions docker_tests/test_examples_of_prod_image_building.py
Expand Up @@ -25,9 +25,12 @@
import pytest
import requests

# isort:off (needed to workaround isort bug)
from docker_tests.command_utils import run_command
from docker_tests.constants import SOURCE_ROOT

# isort:on (needed to workaround isort bug)

DOCKER_EXAMPLES_DIR = SOURCE_ROOT / "docs" / "docker-stack" / "docker-examples"


Expand Down
3 changes: 3 additions & 0 deletions docker_tests/test_prod_image.py
Expand Up @@ -24,6 +24,7 @@

import pytest

# isort:off (needed to workaround isort bug)
from docker_tests.command_utils import run_command
from docker_tests.constants import SOURCE_ROOT
from docker_tests.docker_tests_utils import (
Expand All @@ -32,6 +33,8 @@
run_bash_in_docker,
run_python_in_docker,
)

# isort:on (needed to workaround isort bug)
from setup import PREINSTALLED_PROVIDERS

INSTALLED_PROVIDER_PATH = SOURCE_ROOT / "scripts" / "ci" / "installed_providers.txt"
Expand Down
6 changes: 6 additions & 0 deletions docs/build_docs.py
Expand Up @@ -15,6 +15,11 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
"""
Builds documentation and runs spell checking
# isort:skip_file (needed to workaround isort bug)
"""
from __future__ import annotations

import argparse
Expand All @@ -33,6 +38,7 @@
from docs.exts.docs_build.github_action_utils import with_group
from docs.exts.docs_build.package_filter import process_package_filters
from docs.exts.docs_build.spelling_checks import SpellingError, display_spelling_error_summary

from rich.console import Console
from tabulate import tabulate

Expand Down
3 changes: 3 additions & 0 deletions docs/exts/docs_build/dev_index_generator.py
Expand Up @@ -23,8 +23,11 @@

import jinja2

# isort:off (needed to workaround isort bug)
from docs.exts.provider_yaml_utils import load_package_data

# isort:on (needed to workaround isort bug)

CURRENT_DIR = os.path.abspath(os.path.dirname(__file__))
DOCS_DIR = os.path.abspath(os.path.join(CURRENT_DIR, os.pardir, os.pardir))
BUILD_DIR = os.path.abspath(os.path.join(DOCS_DIR, "_build"))
Expand Down
4 changes: 3 additions & 1 deletion docs/exts/docs_build/errors.py
Expand Up @@ -23,7 +23,9 @@
from rich.console import Console

from airflow.utils.code_utils import prepare_code_snippet
from docs.exts.docs_build.code_utils import CONSOLE_WIDTH

from docs.exts.docs_build.code_utils import CONSOLE_WIDTH # isort:skip (needed to workaround isort bug)


CURRENT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__)))
DOCS_DIR = os.path.abspath(os.path.join(CURRENT_DIR, os.pardir, os.pardir))
Expand Down
3 changes: 3 additions & 0 deletions docs/publish_docs.py
Expand Up @@ -21,10 +21,13 @@
import argparse
import os

# isort:off (needed to workaround isort bug)
from exts.docs_build.docs_builder import AirflowDocsBuilder
from exts.docs_build.package_filter import process_package_filters
from exts.provider_yaml_utils import load_package_data

# isort:on (needed to workaround isort bug)

AIRFLOW_SITE_DIR = os.environ.get("AIRFLOW_SITE_DIRECTORY")


Expand Down
2 changes: 1 addition & 1 deletion kubernetes_tests/test_kubernetes_executor.py
Expand Up @@ -20,7 +20,7 @@

import pytest

from kubernetes_tests.test_base import EXECUTOR, TestBase
from kubernetes_tests.test_base import EXECUTOR, TestBase # isort:skip (needed to workaround isort bug)


@pytest.mark.skipif(EXECUTOR != "KubernetesExecutor", reason="Only runs on KubernetesExecutor")
Expand Down
2 changes: 1 addition & 1 deletion kubernetes_tests/test_other_executors.py
Expand Up @@ -20,7 +20,7 @@

import pytest

from kubernetes_tests.test_base import EXECUTOR, TestBase
from kubernetes_tests.test_base import EXECUTOR, TestBase # isort:skip (needed to workaround isort bug)


# These tests are here because only KubernetesExecutor can run the tests in
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Expand Up @@ -35,5 +35,6 @@ known_first_party = ["airflow", "airflow_breeze", "docker_tests", "docs", "kuber
# The test_python.py is needed because adding __future__.annotations breaks runtime checks that are
# needed for the test to work
skip = ["build", ".tox", "venv", "tests/decorators/test_python.py"]
lines_between_types = 0
skip_glob = ["*.pyi"]
profile = "black"
5 changes: 4 additions & 1 deletion setup.py
Expand Up @@ -377,7 +377,10 @@ def write_version(filename: str = str(AIRFLOW_SOURCES_ROOT / "airflow" / "git_ve
"freezegun",
"gitpython",
"ipdb",
"isort",
# make sure that we are using stable sorting order from 5.* version (some changes were introduced
# in 5.11.3. Black is not compatible yet, so we need to limit isort
# we can remove the limit when black and isort agree on the order
"isort==5.11.2",
"jira",
"jsondiff",
"mongomock",
Expand Down

0 comments on commit d7db157

Please sign in to comment.