Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev(ingest): move from isort to ruff #12364

Merged
merged 2 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions metadata-ingestion/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ task lint(type: Exec, dependsOn: installDev) {
commandLine 'bash', '-c',
"source ${venv_name}/bin/activate && set -x && " +
"black --check --diff src/ tests/ examples/ && " +
"isort --check --diff src/ tests/ examples/ && " +
"ruff check src/ tests/ examples/ && " +
"mypy --show-traceback --show-error-codes src/ tests/ examples/"
}
Expand All @@ -118,7 +117,6 @@ task lintFix(type: Exec, dependsOn: installDev) {
commandLine 'bash', '-c',
"source ${venv_name}/bin/activate && set -x && " +
"black src/ tests/ examples/ && " +
"isort src/ tests/ examples/ && " +
"ruff check --fix src/ tests/ examples/"
}

Expand Down
3 changes: 1 addition & 2 deletions metadata-ingestion/developing.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,11 @@ The architecture of this metadata ingestion framework is heavily inspired by [Ap

## Code style

We use black, isort, flake8, and mypy to ensure consistent code style and quality.
We use black, ruff, and mypy to ensure consistent code style and quality.

```shell
# Assumes: pip install -e '.[dev]' and venv is activated
black src/ tests/
isort src/ tests/
ruff check src/ tests/
mypy src/ tests/
```
Expand Down
24 changes: 17 additions & 7 deletions metadata-ingestion/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,22 @@ extend-exclude = '''
include = '\.pyi?$'
target-version = ['py38', 'py39', 'py310', 'py311']

[tool.isort]
combine_as_imports = true
indent = ' '
known_future_library = ['__future__', 'datahub.utilities._markupsafe_compat', 'datahub.sql_parsing._sqlglot_patch']
profile = 'black'
sections = 'FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER'
skip_glob = 'src/datahub/metadata'
[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']
Expand Down Expand Up @@ -47,6 +56,7 @@ select = [
"C90",
"E",
"F",
"I", # For isort
"TID",
]
ignore = [
Expand Down
1 change: 0 additions & 1 deletion metadata-ingestion/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,6 @@
# We should make an effort to keep it up to date.
"black==23.3.0",
"ruff==0.9.1",
"isort>=5.7.0",
"mypy==1.10.1",
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from datahub.utilities._markupsafe_compat import MARKUPSAFE_PATCHED

import collections
import concurrent.futures
import contextlib
Expand All @@ -12,6 +10,7 @@
import traceback
import unittest.mock
import uuid
from datahub.utilities._markupsafe_compat import MARKUPSAFE_PATCHED
from functools import lru_cache
Copy link
Collaborator

@hsheth2 hsheth2 Jan 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is actually a pretty dangerous change - we're applying patches to third-party libraries, so we need to make sure that those patches get applied first. so moving the import down is not actually safe.

we'll need to use custom isort sections for this https://docs.astral.sh/ruff/settings/#lint_isort_sections

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also note that this is only required for metadata-ingestion - this specific config does not need to be copied across to every module

from typing import (
TYPE_CHECKING,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from datahub.sql_parsing._sqlglot_patch import SQLGLOT_PATCHED

import dataclasses
import functools
import logging
import traceback
from collections import defaultdict
from datahub.sql_parsing._sqlglot_patch import SQLGLOT_PATCHED
from typing import Any, Dict, List, Optional, Set, Tuple, TypeVar, Union

import pydantic.dataclasses
Expand Down
3 changes: 1 addition & 2 deletions metadata-ingestion/src/datahub/sql_parsing/sqlglot_utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from datahub.sql_parsing._sqlglot_patch import SQLGLOT_PATCHED

import functools
import hashlib
import logging
import re
from datahub.sql_parsing._sqlglot_patch import SQLGLOT_PATCHED
from typing import Dict, Iterable, Optional, Tuple, Union

import sqlglot
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from datahub.sql_parsing._sqlglot_patch import SQLGLOT_PATCHED

import time
from datahub.sql_parsing._sqlglot_patch import SQLGLOT_PATCHED

import pytest
import sqlglot
Expand Down
Loading