diff --git a/src/databricks/labs/ucx/source_code/notebooks/loaders.py b/src/databricks/labs/ucx/source_code/notebooks/loaders.py index d90a2fd8ae..5f4a494c7c 100644 --- a/src/databricks/labs/ucx/source_code/notebooks/loaders.py +++ b/src/databricks/labs/ucx/source_code/notebooks/loaders.py @@ -41,6 +41,7 @@ def resolve(self, path_lookup: PathLookup, path: Path) -> Path | None: return None.""" # check current working directory first absolute_path = path_lookup.cwd / path + absolute_path = absolute_path.resolve() if is_a_notebook(absolute_path): return absolute_path # When exported through Git, notebooks are saved with a .py extension. So check with and without extension diff --git a/tests/integration/source_code/test_cells.py b/tests/integration/source_code/test_cells.py index a1621ad94a..b35306b228 100644 --- a/tests/integration/source_code/test_cells.py +++ b/tests/integration/source_code/test_cells.py @@ -5,6 +5,7 @@ from databricks.labs.ucx.source_code.base import CurrentSessionState from databricks.labs.ucx.source_code.graph import Dependency, DependencyGraph from databricks.labs.ucx.source_code.linters.files import FileLoader +from databricks.labs.ucx.source_code.notebooks.loaders import NotebookLoader from databricks.labs.ucx.source_code.notebooks.sources import Notebook @@ -25,3 +26,25 @@ def test_malformed_pip_cell_is_supported(simple_ctx): ) problems = notebook.build_dependency_graph(parent) assert not problems + + +def test_relative_grand_parent_path_is_supported( + simple_ctx, make_notebook, make_directory, make_random, watchdog_purge_suffix +): + grand_parent = make_notebook() + top_dir = make_directory() + child_dir = make_directory(path=f"~/{top_dir.name}/dummy-{make_random(4)}-{watchdog_purge_suffix}") + source = f""" +%run ../../{grand_parent.name} + +""" + notebook_path = make_notebook( + path=f"{child_dir.as_posix()}/dummy-{make_random(4)}-{watchdog_purge_suffix}", content=source.encode("utf-8") + ) + dependency = Dependency(NotebookLoader(), notebook_path) + root = DependencyGraph( + dependency, None, simple_ctx.dependency_resolver, simple_ctx.path_lookup, CurrentSessionState() + ) + container = dependency.load(simple_ctx.path_lookup) + problems = container.build_dependency_graph(root) + assert not problems