Cannot import relative python paths

georgef
New Contributor III

Hello,

Some variations of this question have been asked before but there doesn't seem to be an answer for the following simple use case:

I have the following file structure on a Databricks Asset Bundles project:

 

src
--dir1
----file1.py
--dir2
----file2.py

 

There doesn't seem to be a way to import anything from file1.py to file2.py. I have tried (inside file2.py):

 

from src.dir1.file1 import something
from dir1.file1 import something
from ..dir1.file1 import something

 

None of these seem to work. I have tried appending os.abspath("..") and "../.." to sys.path, as well as passing ${workspace.file_path} to the task and appending that, to no avail.

Note that relative imports on the same level work so the following both work:

 

# src
# --file1.py
# --file2.py
# We are on file1.py
from file2 import something

# src
# --file1.py
# --dir2
# ----file2.py
# We are on file1.py
from dir2.file2 import something

 

Is something weird going on with the import paths when deploying DABs? I'd rather avoid having to deploy a full-on wheel if I can avoid it, as it adds a lot of unnecessary boilerplate.

Thank you!