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

Added more value inference for dbutils.notebook.run(...) #1860

Merged
merged 19 commits into from
Jun 8, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
test private API using test class
ericvergnaud committed Jun 7, 2024
commit b6f27b005d6b2e6719fce1fe1eb0a1efd2ac93a7
4 changes: 2 additions & 2 deletions src/databricks/labs/ucx/source_code/notebooks/loaders.py
Original file line number Diff line number Diff line change
@@ -55,14 +55,14 @@ def load_dependency(self, path_lookup: PathLookup, dependency: Dependency) -> So
except NotFound:
logger.warning(f"Could not read notebook from workspace: {absolute_path}")
return None
language = self.detect_language(absolute_path, content)
language = self._detect_language(absolute_path, content)
if not language:
logger.warning(f"Could not detect language for {absolute_path}")
return None
return Notebook.parse(absolute_path, content, language)

@staticmethod
def detect_language(path: Path, content: str):
def _detect_language(path: Path, content: str):
language = SUPPORTED_EXTENSION_LANGUAGES.get(path.suffix, None)
if language:
return language
1 change: 0 additions & 1 deletion tests/unit/source_code/linters/test_python_ast.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import pytest
from astroid import Attribute, Call, Const, Expr # type: ignore

17 changes: 12 additions & 5 deletions tests/unit/source_code/notebooks/test_loader.py
Original file line number Diff line number Diff line change
@@ -5,8 +5,15 @@


def test_detects_language():
assert NotebookLoader.detect_language(Path("hi.py"), "stuff") == Language.PYTHON
assert NotebookLoader.detect_language(Path("hi.sql"), "stuff") == Language.SQL
assert NotebookLoader.detect_language(Path("hi"), "# Databricks notebook source") == Language.PYTHON
assert NotebookLoader.detect_language(Path("hi"), "-- Databricks notebook source") == Language.SQL
assert not NotebookLoader.detect_language(Path("hi"), "stuff")

class NotebookLoaderForTesting(NotebookLoader):

@classmethod
def detect_language(cls, path: Path, content: str):
return cls._detect_language(path, content)

assert NotebookLoaderForTesting.detect_language(Path("hi.py"), "stuff") == Language.PYTHON
assert NotebookLoaderForTesting.detect_language(Path("hi.sql"), "stuff") == Language.SQL
assert NotebookLoaderForTesting.detect_language(Path("hi"), "# Databricks notebook source") == Language.PYTHON
assert NotebookLoaderForTesting.detect_language(Path("hi"), "-- Databricks notebook source") == Language.SQL
assert not NotebookLoaderForTesting.detect_language(Path("hi"), "stuff")