You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2023/10/19 22:19:43 UTC

[airflow] branch main updated: Upgrade ruff to v0.0.292 (#35066)

This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 2f205d52ac Upgrade ruff to v0.0.292 (#35066)
2f205d52ac is described below

commit 2f205d52ace90405dce08dc2138c404cb35e1ef2
Author: Andrey Anshin <An...@taragol.is>
AuthorDate: Fri Oct 20 02:19:35 2023 +0400

    Upgrade ruff to v0.0.292 (#35066)
---
 .pre-commit-config.yaml | 14 ++++++--------
 dev/airflow-github      | 15 +++++++++++----
 pyproject.toml          | 22 +++++++++++++++-------
 3 files changed, 32 insertions(+), 19 deletions(-)

diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 8aedf5125c..42b67dbd66 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -180,16 +180,14 @@ repos:
         additional_dependencies: ['pyyaml']
         pass_filenames: false
         require_serial: true
+  - repo: https://github.com/astral-sh/ruff-pre-commit
+    rev: v0.0.292
+    hooks:
+      # Since ruff makes use of multiple cores we _purposefully_ don't run this in docker so it can use the
+      # host CPU to it's fullest
       - id: ruff
         name: ruff
-        language: python
-        require_serial: true
-        pass_filenames: true
-        # Since ruff makes use of multiple cores we _purposefully_ don't run this in docker so it can use the
-        # host CPU to it's fullest
-        entry: ruff --fix --force-exclude
-        additional_dependencies: ['ruff==0.0.282']
-        files: \.pyi?$
+        args: [ --fix ]
         exclude: ^.*/.*_vendor/|^tests/dags/test_imports.py
   - repo: https://github.com/asottile/blacken-docs
     rev: 1.16.0
diff --git a/dev/airflow-github b/dev/airflow-github
index 5a8a17cbf7..46213b411a 100755
--- a/dev/airflow-github
+++ b/dev/airflow-github
@@ -25,14 +25,17 @@ from __future__ import annotations
 import re
 import sys
 from collections import Counter, defaultdict
+from typing import TYPE_CHECKING
 
 import git
 import rich_click as click
 from github import Github
-from github.Issue import Issue
-from github.PullRequest import PullRequest
 from packaging import version
 
+if TYPE_CHECKING:
+    from github.Issue import Issue
+    from github.PullRequest import PullRequest
+
 GIT_COMMIT_FIELDS = ["id", "author_name", "author_email", "date", "subject", "body"]
 GIT_LOG_FORMAT = "%x1f".join(["%h", "%an", "%ae", "%ad", "%s", "%b"]) + "%x1e"
 pr_title_re = re.compile(r".*\((#[0-9]{1,6})\)$")
@@ -252,7 +255,10 @@ def compare(target_version, github_token, previous_version=None, show_uncherrypi
     # :<18 says left align, pad to 18, :>6 says right align, pad to 6
     # :<50.50 truncates after 50 chars
     # !s forces as string
-    formatstr = "{number:>6} | {typ!s:<5} | {changelog!s:<13} | {status!s} | {title:<83.83} | {merged:<6} | {commit:>7.7} | {url}"
+    formatstr = (
+        "{number:>6} | {typ!s:<5} | {changelog!s:<13} | {status!s} "
+        "| {title:<83.83} | {merged:<6} | {commit:>7.7} | {url}"
+    )
 
     print(
         formatstr.format(
@@ -303,7 +309,8 @@ def compare(target_version, github_token, previous_version=None, show_uncherrypi
         )
 
     print(
-        f"Commits on branch: {num_cherrypicked:d}, {sum(num_uncherrypicked.values()):d} ({dict(num_uncherrypicked)}) yet to be cherry-picked"
+        f"Commits on branch: {num_cherrypicked:d}, {sum(num_uncherrypicked.values()):d} "
+        f"({dict(num_uncherrypicked)}) yet to be cherry-picked"
     )
 
 
diff --git a/pyproject.toml b/pyproject.toml
index b3029f033c..1652c6827b 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -63,7 +63,8 @@ extend-select = [
     "D419",
     "TCH001",  # typing-only-first-party-import
     "TCH002",  # typing-only-third-party-import
-    "TID251",
+    "TID251",  # Specific modules or module members that may not be imported or accessed
+    "TID253",  # Ban certain modules from being imported at module level
 ]
 extend-ignore = [
     "D203",
@@ -128,15 +129,16 @@ combine-as-imports = true
 
 # Ignore pydoc style from these
 "*.pyi" = ["D"]
-"tests/*" = ["D"]
 "scripts/*" = ["D"]
-"dev/*" = ["D"]
 "docs/*" = ["D"]
 "provider_packages/*" = ["D"]
-"docker_tests/*" = ["D"]
-"kubernetes_tests/*" = ["D"]
 "*/example_dags/*" = ["D"]
 "chart/*" = ["D"]
+# In addition ignore top level imports, e.g. pandas, numpy in tests and dev
+"dev/*" = ["D", "TID253"]
+"tests/*" = ["D", "TID253"]
+"docker_tests/*" = ["D", "TID253"]
+"kubernetes_tests/*" = ["D", "TID253"]
 
 # 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
@@ -150,6 +152,14 @@ combine-as-imports = true
 "airflow.AirflowException".msg = "Use airflow.exceptions.AirflowException instead."
 "airflow.Dataset".msg = "Use airflow.datasets.Dataset instead."
 
+[tool.ruff.flake8-tidy-imports]
+# Ban certain modules from being imported at module level, instead requiring
+# that they're imported lazily (e.g., within a function definition).
+banned-module-level-imports = ["numpy", "pandas"]
+
+[tool.ruff.flake8-type-checking]
+exempt-modules = ["typing", "typing_extensions"]
+
 [tool.coverage.run]
 branch = true
 relative_files = true
@@ -175,5 +185,3 @@ exclude_also = [
     "@(typing(_extensions)?\\.)?overload",
     "if TYPE_CHECKING:"
 ]
-[tool.ruff.flake8-type-checking]
-exempt-modules = ["typing", "typing_extensions"]