-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Changes Add a pip resolver for later use by the `ImportResolver`. The resolver makes a library available to the path look up by i) installing the library and ii) augmenting the path lookup. ### Linked issues Part of #1642 Follow up on #1694 ### Functionality - [ ] added relevant user documentation - [ ] added new CLI command - [ ] modified existing command: `databricks labs ucx ...` - [ ] added a new workflow - [x] modified existing workflow: `...` - [ ] added a new table - [ ] modified existing table: `...` ### Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> - [ ] manually tested - [x] added unit tests - [ ] added integration tests - [ ] verified on staging environment (screenshot attached)
- Loading branch information
1 parent
fa722f2
commit 08aed28
Showing
17 changed files
with
377 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import pytest | ||
|
||
from databricks.labs.ucx.contexts.application import GlobalContext | ||
|
||
|
||
@pytest.mark.parametrize("attribute", ["dependency_resolver", "pip_resolver", "site_packages", "site_packages_path"]) | ||
def test_global_context_attributes_not_none(attribute: str): | ||
"""Attributes should be not None""" | ||
# Goal is to improve test coverage | ||
ctx = GlobalContext() | ||
assert hasattr(ctx, attribute) | ||
assert getattr(ctx, attribute) is not None |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
from pathlib import Path | ||
from unittest.mock import create_autospec | ||
|
||
from databricks.labs.ucx.source_code.graph import Dependency, DependencyGraph, DependencyResolver | ||
from databricks.labs.ucx.source_code.files import FileLoader | ||
from databricks.labs.ucx.source_code.notebooks.cells import CellLanguage, PipCell | ||
from databricks.labs.ucx.source_code.notebooks.loaders import ( | ||
NotebookResolver, | ||
NotebookLoader, | ||
) | ||
from databricks.labs.ucx.source_code.site_packages import PipResolver | ||
|
||
|
||
def test_pip_cell_language_is_pip(): | ||
assert PipCell("code").language == CellLanguage.PIP | ||
|
||
|
||
def test_pip_cell_build_dependency_graph_invokes_register_library(): | ||
graph = create_autospec(DependencyGraph) | ||
|
||
code = "%pip install databricks" | ||
cell = PipCell(code) | ||
|
||
problems = cell.build_dependency_graph(graph) | ||
|
||
assert len(problems) == 0 | ||
graph.register_library.assert_called_once_with("databricks") | ||
|
||
|
||
def test_pip_cell_build_dependency_graph_pip_registers_missing_library(): | ||
graph = create_autospec(DependencyGraph) | ||
|
||
code = "%pip install" | ||
cell = PipCell(code) | ||
|
||
problems = cell.build_dependency_graph(graph) | ||
|
||
assert len(problems) == 1 | ||
assert problems[0].code == "library-install-failed" | ||
assert problems[0].message == "Missing arguments in '%pip install'" | ||
graph.register_library.assert_not_called() | ||
|
||
|
||
def test_pip_cell_build_dependency_graph_reports_incorrect_syntax(): | ||
graph = create_autospec(DependencyGraph) | ||
|
||
code = "%pip installl pytest" # typo on purpose | ||
cell = PipCell(code) | ||
|
||
problems = cell.build_dependency_graph(graph) | ||
|
||
assert len(problems) == 1 | ||
assert problems[0].code == "library-install-failed" | ||
assert problems[0].message == "Unsupported %pip command: installl" | ||
graph.register_library.assert_not_called() | ||
|
||
|
||
def test_pip_cell_build_dependency_graph_reports_unknown_library(mock_path_lookup): | ||
dependency = Dependency(FileLoader(), Path("test")) | ||
notebook_loader = NotebookLoader() | ||
notebook_resolver = NotebookResolver(notebook_loader) | ||
dependency_resolver = DependencyResolver([PipResolver()], notebook_resolver, [], mock_path_lookup) | ||
graph = DependencyGraph(dependency, None, dependency_resolver, mock_path_lookup) | ||
|
||
code = "%pip install unknown-library-name" | ||
cell = PipCell(code) | ||
|
||
problems = cell.build_dependency_graph(graph) | ||
|
||
assert len(problems) == 1 | ||
assert problems[0].code == "library-install-failed" | ||
assert problems[0].message.startswith("Failed to install unknown-library-name") | ||
|
||
|
||
def test_pip_cell_build_dependency_graph_resolves_installed_library(mock_path_lookup): | ||
dependency = Dependency(FileLoader(), Path("test")) | ||
notebook_loader = NotebookLoader() | ||
notebook_resolver = NotebookResolver(notebook_loader) | ||
dependency_resolver = DependencyResolver([PipResolver()], notebook_resolver, [], mock_path_lookup) | ||
graph = DependencyGraph(dependency, None, dependency_resolver, mock_path_lookup) | ||
|
||
code = "%pip install pytest" | ||
cell = PipCell(code) | ||
|
||
problems = cell.build_dependency_graph(graph) | ||
|
||
assert len(problems) == 0 | ||
assert graph.path_lookup.resolve(Path("pytest")).exists() |
Oops, something went wrong.