Skip to content

Commit

Permalink
Ignore E402 (import not at the top of file) in pre-commits (apache#35873
Browse files Browse the repository at this point in the history
)

Pre-commits often import some modules from elsewhere after inserting
a common folder at PYTHONPATH. Pre-commits are pretty special,
because they are supposed to be run as standalone scripts
by pre-commit framework as git hooks, and they often do
similar things, so some common code in pre-commits is good to have.

Ignoring E402 error in all pre-commits seems like best way to
avoid unnecessary individual exclusions.
  • Loading branch information
potiuk authored Nov 27, 2023
1 parent 162d0f0 commit d045a0f
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 20 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ combine-as-imports = true

# All of the modules which have an extra license header (i.e. that we copy from another project) need to
# ignore E402 -- module level import not at top level
"scripts/ci/pre_commit/*.py" = ["E402"]
"airflow/api/auth/backend/kerberos_auth.py" = ["E402"]
"airflow/security/kerberos.py" = ["E402"]
"airflow/security/utils.py" = ["E402"]
Expand Down
2 changes: 1 addition & 1 deletion scripts/ci/pre_commit/common_precommit_black_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

sys.path.insert(0, str(Path(__file__).parent.resolve())) # make sure common_precommit_utils is imported

from common_precommit_utils import AIRFLOW_BREEZE_SOURCES_PATH # isort: skip # noqa E402
from common_precommit_utils import AIRFLOW_BREEZE_SOURCES_PATH


@lru_cache(maxsize=None)
Expand Down
17 changes: 8 additions & 9 deletions scripts/ci/pre_commit/pre_commit_check_pre_commit_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,18 @@
from pathlib import Path

sys.path.insert(0, str(Path(__file__).parent.resolve())) # make sure common_precommit_utils is imported
from common_precommit_utils import ( # isort: skip # noqa: E402
from collections import defaultdict
from typing import Any

import yaml
from common_precommit_black_utils import black_format
from common_precommit_utils import (
AIRFLOW_BREEZE_SOURCES_PATH,
AIRFLOW_SOURCES_ROOT_PATH,
insert_documentation,
)
from common_precommit_black_utils import black_format # isort: skip # noqa E402

from collections import defaultdict # noqa: E402
from typing import Any # noqa: E402

import yaml # noqa: E402
from rich.console import Console # noqa: E402
from tabulate import tabulate # noqa: E402
from rich.console import Console
from tabulate import tabulate

console = Console(width=400, color_system="standard")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@

os.environ["_SKIP_PYTHON_VERSION_CHECK"] = "true"

from setup import ( # noqa # isort:skip
add_all_provider_packages,
EXTRAS_DEPRECATED_ALIASES,
from setup import (
EXTRAS_DEPENDENCIES,
PREINSTALLED_PROVIDERS,
EXTRAS_DEPRECATED_ALIASES,
EXTRAS_DEPRECATED_ALIASES_IGNORED_FROM_REF_DOCS,
PREINSTALLED_PROVIDERS,
add_all_provider_packages,
)


Expand Down
2 changes: 1 addition & 1 deletion scripts/ci/pre_commit/pre_commit_compile_www_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from pathlib import Path

sys.path.insert(0, str(Path(__file__).parent.resolve())) # make sure common_precommit_utils is imported
from common_precommit_utils import get_directory_hash # isort: skip # noqa E402
from common_precommit_utils import get_directory_hash

AIRFLOW_SOURCES_PATH = Path(__file__).parents[3].resolve()
WWW_HASH_FILE = AIRFLOW_SOURCES_PATH / ".build" / "www" / "hash.txt"
Expand Down
5 changes: 3 additions & 2 deletions scripts/ci/pre_commit/pre_commit_insert_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@

os.environ["_SKIP_PYTHON_VERSION_CHECK"] = "true"

from common_precommit_utils import insert_documentation # isort: skip # noqa: E402
from setup import EXTRAS_DEPENDENCIES # isort:skip # noqa: E402
from common_precommit_utils import insert_documentation

from setup import EXTRAS_DEPENDENCIES

sys.path.append(str(AIRFLOW_SOURCES_DIR))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@

sys.path.insert(0, str(Path(__file__).parent.resolve())) # make sure common_precommit_utils is imported

from common_precommit_utils import AIRFLOW_SOURCES_ROOT_PATH # isort: skip # noqa E402
from common_precommit_black_utils import black_format # isort: skip # noqa E402
from common_precommit_black_utils import black_format
from common_precommit_utils import AIRFLOW_SOURCES_ROOT_PATH

PROVIDERS_ROOT = AIRFLOW_SOURCES_ROOT_PATH / "providers"
COMMON_SQL_ROOT = PROVIDERS_ROOT / "common" / "sql"
Expand Down
2 changes: 1 addition & 1 deletion scripts/ci/pre_commit/pre_commit_update_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

sys.path.insert(0, str(Path(__file__).parent.resolve())) # make sure common_precommit_utils is importable

from common_precommit_utils import AIRFLOW_SOURCES_ROOT_PATH, read_airflow_version # noqa: E402
from common_precommit_utils import AIRFLOW_SOURCES_ROOT_PATH, read_airflow_version


def update_version(pattern: re.Pattern, v: str, file_path: Path):
Expand Down

0 comments on commit d045a0f

Please sign in to comment.