Run a notebook from another notebook in a Repo Databricks
I have a notebook with functions in a repo folder that I am trying to run in another notebook.
Normally I can run it as such: %run /Users/name/project/file_name
So I cloned the two files (function_notebook, processed_notebook) into a Repo in Databricks.
When I try to copy the path where I just cloned it, onlt this option appears: Copy File Path relative to Root
However in the Workspace user folder the option is Copy File Path
Evidently I dont quite grasp the difference between the relative path and the workspace path.
How can I run the notebook that has been cloned in the repo ?
Hierarchy:
RepoName (has 2 folders):
-
Folder1
Notebook1
-
Folder2
Notebook2
I'm in Notebook1
wanting to run Notebook2
%run ../Folder2/Notebook2
Solution 1:
It's an UI problem that was already reported to development team. Until that time you need to create the path yourself. The difference is that it's starts with /Repos
not with /Users
. I have a small demo that shows how to use Repos to perform testing, etc. - if you interested in details.
But if the files are inside the same repository, then you don't need to use full paths, it's making them less portable - you can use relative paths, like, ./file_name
to include notebook in the current folder, or ../file_name
to include file in the level up folder, or ./folder/file_name
to include file from the subfolder - but don’t specify file extension. In this case your code is portable, and could be used in different checkouts.
Example:
Notebook2:
Notebook1:
The name difference between workspace path & relative path is that former gives you full path inside the Workspace, while later gives you path relative to the root of the Repo