Skip to content

Commit

Permalink
dev(ingest): move modules from isort,flake8 to ruff (#12373)
Browse files Browse the repository at this point in the history
  • Loading branch information
anshbansal authored Jan 17, 2025
1 parent 4de7f61 commit 76e46b8
Show file tree
Hide file tree
Showing 50 changed files with 166 additions and 144 deletions.
6 changes: 2 additions & 4 deletions metadata-ingestion-modules/airflow-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,14 @@ task lint(type: Exec, dependsOn: installDev) {
"find ${venv_name}/lib -path *airflow/_vendor/connexion/spec.py -exec sed -i.bak -e '169,169s/ # type: List\\[str\\]//g' {} \\; && " +
"source ${venv_name}/bin/activate && set -x && " +
"black --check --diff src/ tests/ && " +
"isort --check --diff src/ tests/ && " +
"flake8 --count --statistics src/ tests/ && " +
"ruff check src/ tests/ && " +
"mypy --show-traceback --show-error-codes src/ tests/"
}
task lintFix(type: Exec, dependsOn: installDev) {
commandLine 'bash', '-c',
"source ${venv_name}/bin/activate && set -x && " +
"black src/ tests/ && " +
"isort src/ tests/ && " +
"flake8 src/ tests/ && " +
"ruff check --fix src/ tests/"
"mypy src/ tests/ "
}

Expand Down
53 changes: 46 additions & 7 deletions metadata-ingestion-modules/airflow-plugin/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,50 @@ extend-exclude = '''
'''
include = '\.pyi?$'

[tool.isort]
indent = ' '
known_future_library = ['__future__', 'datahub.utilities._markupsafe_compat', 'datahub_provider._airflow_compat']
profile = 'black'
sections = 'FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER'
[tool.ruff.lint.isort]
combine-as-imports = true
known-first-party = ["datahub"]
extra-standard-library = ["__future__", "datahub.utilities._markupsafe_compat", "datahub.sql_parsing._sqlglot_patch"]
section-order = ["future", "standard-library", "third-party", "first-party", "local-folder"]
force-sort-within-sections = false
force-wrap-aliases = false
split-on-trailing-comma = false
order-by-type = true
relative-imports-order = "closest-to-furthest"
force-single-line = false
single-line-exclusions = ["typing"]
length-sort = false
from-first = false
required-imports = []
classes = ["typing"]

[tool.pyright]
extraPaths = ['tests']
[tool.ruff.lint]
select = [
"B",
"C90",
"E",
"F",
"I", # For isort
"TID",
]
ignore = [
# Ignore line length violations (handled by Black)
"E501",
# Ignore whitespace before ':' (matches Black)
"E203",
"E203",
# Allow usages of functools.lru_cache
"B019",
# Allow function call in argument defaults
"B008",
]

[tool.ruff.lint.mccabe]
max-complexity = 15

[tool.ruff.lint.flake8-tidy-imports]
# Disallow all relative imports.
ban-relative-imports = "all"

[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401"]
21 changes: 0 additions & 21 deletions metadata-ingestion-modules/airflow-plugin/setup.cfg
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
[flake8]
max-complexity = 15
ignore =
# Ignore: line length issues, since black's formatter will take care of them.
E501,
# Ignore: 1 blank line required before class docstring.
D203,
# See https://stackoverflow.com/a/57074416.
W503,
# See https://github.com/psf/black/issues/315.
E203
exclude =
.git,
venv,
.tox,
__pycache__
per-file-ignores =
# imported but unused
__init__.py: F401
ban-relative-imports = true

[mypy]
plugins =
sqlmypy,
Expand Down
4 changes: 1 addition & 3 deletions metadata-ingestion-modules/airflow-plugin/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ def get_long_description():
*mypy_stubs,
"black==22.12.0",
"coverage>=5.1",
"flake8>=3.8.3",
"flake8-tidy-imports>=4.3.0",
"isort>=5.7.0",
"ruff==0.9.1",
"mypy==1.10.1",
# pydantic 1.8.2 is incompatible with mypy 0.910.
# See https://github.com/samuelcolvin/pydantic/pull/3175#issuecomment-995382910.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from enum import Enum
from typing import TYPE_CHECKING, Optional

import datahub.emitter.mce_builder as builder
from airflow.configuration import conf
from datahub.configuration.common import AllowDenyPattern, ConfigModel
from pydantic.fields import Field

import datahub.emitter.mce_builder as builder
from datahub.configuration.common import AllowDenyPattern, ConfigModel

if TYPE_CHECKING:
from datahub_airflow_plugin.hooks.datahub import DatahubGenericHook

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import logging

import datahub.emitter.mce_builder as builder
from openlineage.client.run import Dataset as OpenLineageDataset

import datahub.emitter.mce_builder as builder

logger = logging.getLogger(__name__)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,11 @@
import unittest.mock
from typing import TYPE_CHECKING, Optional

import datahub.emitter.mce_builder as builder
from datahub.ingestion.source.sql.sqlalchemy_uri_mapper import (
get_platform_from_sqlalchemy_uri,
)
from datahub.sql_parsing.sqlglot_lineage import (
SqlParsingResult,
create_lineage_sql_parsed_result,
from openlineage.airflow.extractors import (
BaseExtractor,
ExtractorManager as OLExtractorManager,
TaskMetadata,
)
from openlineage.airflow.extractors import BaseExtractor
from openlineage.airflow.extractors import ExtractorManager as OLExtractorManager
from openlineage.airflow.extractors import TaskMetadata
from openlineage.airflow.extractors.snowflake_extractor import SnowflakeExtractor
from openlineage.airflow.extractors.sql_extractor import SqlExtractor
from openlineage.airflow.utils import get_operator_class, try_import_from_string
Expand All @@ -23,11 +17,20 @@
SqlJobFacet,
)

import datahub.emitter.mce_builder as builder
from datahub.ingestion.source.sql.sqlalchemy_uri_mapper import (
get_platform_from_sqlalchemy_uri,
)
from datahub.sql_parsing.sqlglot_lineage import (
SqlParsingResult,
create_lineage_sql_parsed_result,
)
from datahub_airflow_plugin._airflow_shims import Operator
from datahub_airflow_plugin._datahub_ol_adapter import OL_SCHEME_TWEAKS

if TYPE_CHECKING:
from airflow.models import DagRun, TaskInstance

from datahub.ingestion.graph.client import DataHubGraph

logger = logging.getLogger(__name__)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import TYPE_CHECKING, Dict, List, Optional, Set, Tuple, Union, cast

from airflow.configuration import conf

from datahub.api.entities.datajob import DataFlow, DataJob
from datahub.api.entities.dataprocess.dataprocess_instance import (
DataProcessInstance,
Expand All @@ -11,7 +12,6 @@
from datahub.metadata.schema_classes import DataProcessTypeClass
from datahub.utilities.urns.data_flow_urn import DataFlowUrn
from datahub.utilities.urns.data_job_urn import DataJobUrn

from datahub_airflow_plugin._airflow_compat import AIRFLOW_PATCHED
from datahub_airflow_plugin._config import DatahubLineageConfig, DatajobUrl

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
from typing import TYPE_CHECKING, Callable, Dict, List, Optional, TypeVar, cast

import airflow
import datahub.emitter.mce_builder as builder
from airflow.models import Variable
from airflow.models.serialized_dag import SerializedDagModel
from openlineage.airflow.listener import TaskHolder
from openlineage.airflow.utils import redact_with_exclusions
from openlineage.client.serde import Serde

import datahub.emitter.mce_builder as builder
from datahub.api.entities.datajob import DataJob
from datahub.api.entities.dataprocess.dataprocess_instance import InstanceRunResult
from datahub.emitter.mcp import MetadataChangeProposalWrapper
Expand All @@ -30,10 +34,6 @@
)
from datahub.sql_parsing.sqlglot_lineage import SqlParsingResult
from datahub.telemetry import telemetry
from openlineage.airflow.listener import TaskHolder
from openlineage.airflow.utils import redact_with_exclusions
from openlineage.client.serde import Serde

from datahub_airflow_plugin._airflow_shims import (
HAS_AIRFLOW_DAG_LISTENER_API,
HAS_AIRFLOW_DATASET_LISTENER_API,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
logger = logging.getLogger(__name__)


_USE_AIRFLOW_LISTENER_INTERFACE = HAS_AIRFLOW_LISTENER_API and not os.getenv(
_USE_AIRFLOW_LISTENER_INTERFACE = HAS_AIRFLOW_LISTENER_API and os.getenv(
"DATAHUB_AIRFLOW_PLUGIN_USE_V1_PLUGIN", "false"
).lower() in ("true", "1")
).lower() not in ("true", "1")

if _USE_AIRFLOW_LISTENER_INTERFACE:
try:
Expand All @@ -32,7 +32,7 @@


with contextlib.suppress(Exception):
if not os.getenv("DATAHUB_AIRFLOW_PLUGIN_SKIP_FORK_PATCH", "false").lower() in (
if os.getenv("DATAHUB_AIRFLOW_PLUGIN_SKIP_FORK_PATCH", "false").lower() not in (
"true",
"1",
):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
from airflow.lineage import PIPELINE_OUTLETS
from airflow.models.baseoperator import BaseOperator
from airflow.utils.module_loading import import_string

from datahub.api.entities.dataprocess.dataprocess_instance import InstanceRunResult
from datahub.telemetry import telemetry

from datahub_airflow_plugin._airflow_shims import (
MappedOperator,
get_task_inlets,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import List, Optional

import attr

import datahub.emitter.mce_builder as builder
from datahub.utilities.urns.data_job_urn import DataJobUrn
from datahub.utilities.urns.dataset_urn import DatasetUrn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from airflow import DAG
from airflow.operators.python import PythonOperator
from airflow.utils.dates import days_ago

from datahub.configuration.config_loader import load_config_file
from datahub.ingestion.run.pipeline import Pipeline

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

import pendulum
from airflow.decorators import dag, task
from datahub.ingestion.graph.client import DataHubGraph, RemovedStatusFilter

from datahub.ingestion.graph.client import DataHubGraph, RemovedStatusFilter
from datahub_airflow_plugin.hooks.datahub import DatahubRestHook


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"""
from datetime import timedelta

import datahub.emitter.mce_builder as builder
from airflow import DAG
from airflow.operators.bash import BashOperator
from airflow.utils.dates import days_ago

import datahub.emitter.mce_builder as builder
from datahub_airflow_plugin.operators.datahub import DatahubEmitterOperator

default_args = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from airflow.exceptions import AirflowException
from airflow.hooks.base import BaseHook

from datahub.emitter.generic_emitter import Emitter
from datahub.emitter.mcp import MetadataChangeProposalWrapper
from datahub.metadata.com.linkedin.pegasus2avro.mxe import (
Expand All @@ -11,6 +12,7 @@

if TYPE_CHECKING:
from airflow.models.connection import Connection

from datahub.emitter.kafka_emitter import DatahubKafkaEmitter
from datahub.emitter.rest_emitter import DataHubRestEmitter
from datahub.emitter.synchronized_file_emitter import SynchronizedFileEmitter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from typing import TYPE_CHECKING, Dict, List

from datahub.api.entities.dataprocess.dataprocess_instance import InstanceRunResult

from datahub_airflow_plugin._config import DatahubLineageConfig
from datahub_airflow_plugin.client.airflow_generator import AirflowGenerator
from datahub_airflow_plugin.entities import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from airflow.models import BaseOperator
from airflow.utils.decorators import apply_defaults
from avrogen.dict_wrapper import DictWrapper

from datahub.emitter.mcp import MetadataChangeProposalWrapper
from datahub.metadata.com.linkedin.pegasus2avro.mxe import MetadataChangeEvent

from datahub_airflow_plugin.hooks.datahub import (
DatahubGenericHook,
DatahubKafkaHook,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
from typing import Any, List, Optional, Sequence, Union

from airflow.models import BaseOperator

from datahub.api.circuit_breaker import (
AssertionCircuitBreaker,
AssertionCircuitBreakerConfig,
)

from datahub_airflow_plugin.hooks.datahub import DatahubRestHook


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
from typing import Any, List, Optional, Sequence, Union

from airflow.sensors.base import BaseSensorOperator

from datahub.api.circuit_breaker import (
AssertionCircuitBreaker,
AssertionCircuitBreakerConfig,
)

from datahub_airflow_plugin.hooks.datahub import DatahubRestHook


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
from typing import Any, List, Optional, Sequence, Union

from airflow.sensors.base import BaseSensorOperator

from datahub.api.circuit_breaker import (
OperationCircuitBreaker,
OperationCircuitBreakerConfig,
)

from datahub_airflow_plugin.hooks.datahub import DatahubRestHook


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
from typing import Any, List, Optional, Sequence, Union

from airflow.sensors.base import BaseSensorOperator

from datahub.api.circuit_breaker import (
OperationCircuitBreaker,
OperationCircuitBreakerConfig,
)

from datahub_airflow_plugin.hooks.datahub import DatahubRestHook


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import datetime, timedelta

from airflow import DAG

from datahub.emitter.mcp import MetadataChangeProposalWrapper
from datahub.metadata.com.linkedin.pegasus2avro.mxe import MetadataChangeEvent
from datahub.metadata.schema_classes import (
Expand All @@ -9,7 +10,6 @@
DatasetPropertiesClass,
DatasetSnapshotClass,
)

from datahub_airflow_plugin.operators.datahub import DatahubEmitterOperator

default_args = {
Expand Down
Loading

0 comments on commit 76e46b8

Please sign in to comment.