Skip to content

Commit

Permalink
Improved incompatible-with-uc diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
nfx committed Mar 15, 2024
1 parent 1601c8c commit 10c92f8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ Use Databricks SDK instead: w.dbfs.copy(XXX, XXX). Migrate all usage of dbutils

### `E9789`: `incompatible-with-uc`

Incompatible with Unified Catalog. Migrate all usage to Databricks Unity Catalog. Use https://github.com/databrickslabs/ucx for more details
Incompatible with Unity Catalog: XXX. Migrate all usage to Databricks Unity Catalog. Use https://github.com/databrickslabs/ucx for more details

[[back to top](#databricks-labs-pylint-plugin)]

Expand Down
10 changes: 5 additions & 5 deletions src/databricks/labs/pylint/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class LegacyChecker(BaseChecker):
"https://databricks-sdk-py.readthedocs.io/en/latest/index.html",
),
"E9789": (
"Incompatible with Unified Catalog",
"Incompatible with Unity Catalog: %s",
"incompatible-with-uc",
"Migrate all usage to Databricks Unity Catalog. Use https://github.com/databrickslabs/ucx for more details",
),
Expand Down Expand Up @@ -72,22 +72,22 @@ def visit_import(self, node: astroid.Import):
# very coarse check for UC incompatibility
for needle in self.UC_INCOMPATIBLE_BRUTE_FORCE:
if needle in name:
self.add_message("incompatible-with-uc", node=node)
self.add_message("incompatible-with-uc", node=node, args=(node.as_string(),))

def visit_importfrom(self, node: astroid.ImportFrom):
if node.modname.startswith("databricks_cli"):
self.add_message("legacy-cli", node=node)
# very coarse check for UC incompatibility
for needle in self.UC_INCOMPATIBLE_BRUTE_FORCE:
if needle in node.modname:
self.add_message("incompatible-with-uc", node=node)
self.add_message("incompatible-with-uc", node=node, args=(node.as_string(),))

def visit_call(self, node: astroid.Call):
func_as_string = node.func.as_string()
# very coarse check for UC incompatibility
for needle in self.UC_INCOMPATIBLE_BRUTE_FORCE:
if needle in func_as_string:
self.add_message("incompatible-with-uc", node=node)
self.add_message("incompatible-with-uc", node=node, args=(node.as_string(),))

def visit_const(self, node: astroid.Const):
# very coarse check for UC incompatibility
Expand All @@ -96,7 +96,7 @@ def visit_const(self, node: astroid.Const):
return
for needle in self.UC_INCOMPATIBLE_BRUTE_FORCE:
if needle in value:
self.add_message("incompatible-with-uc", node=node)
self.add_message("incompatible-with-uc", node=node, args=(node.as_string(),))


def register(linter):
Expand Down
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Generic, TypeVar
from typing import Generic, Type, TypeVar

import astroid
import astroid.rebuilder
Expand All @@ -10,7 +10,7 @@


class TestSupport(Generic[T]):
def __init__(self, klass: type[T]):
def __init__(self, klass: Type[T]):
linter = UnittestLinter()
checker = klass(linter)
checker.open()
Expand Down Expand Up @@ -39,7 +39,7 @@ def __lshift__(self, code: str):

@pytest.fixture
def lint_with():
def factory(klass: type[T]) -> TestSupport[T]:
def factory(klass: Type[T]) -> TestSupport[T]:
return TestSupport(klass)

yield factory
2 changes: 1 addition & 1 deletion tests/test_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ def test_legacy_cli(lint_with, code):
)
def test_un_incompatible(lint_with, code):
messages = lint_with(LegacyChecker) << code
assert "[incompatible-with-uc] Incompatible with Unified Catalog" in messages
assert "[incompatible-with-uc] Incompatible with Unity Catalog" in messages.pop()

0 comments on commit 10c92f8

Please sign in to comment.