Action Plan: Fixing Editable Imports in Databricks
For the User Experiencing the Import Issue
Immediate Actions (Do This Now)
- Apply the patches:
# In your Databricks notebook:
%pip install -q dbx-patch
from dbx_patch import patch_dbx
patch_dbx(verbose=True)
- Try your import again:
from testx import function1
print(function1())
- If it works → Make it permanent:
from dbx_patch import patch_and_install
patch_and_install() # Installs sitecustomize.py, restarts kernel
- If it doesn't work → Run diagnostics:
# Enable debug mode
import os
os.environ['DBX_PATCH_DEBUG'] = '1'
# Try import again (watch for debug output)
from testx import function1
Upload and run: notebooks/diagnostic_editable_imports.ipynb
For the Developer (Repository Maintainer)
Completed Work ✅
- Deep Analysis:
- Identified all 5 layers of Databricks import hooks
- Documented how each layer blocks editable imports
-
Created technical analysis:
docs/docs/files/editable-install-analysis.md -
Missing Patches Added:
wsfs_path_finder_patch.py- Verifies WsfsPathFinder compatibilitypost_import_hook_verify.py- Verifies PostImportHook compatibility-
Updated
patch_dbx()to include verification steps -
Setup Automation:
scripts/setup_dbx_patch.py- Full-featured Python setup scriptscripts/setup_dbx_patch.sh- Simple bash setup scriptnotebooks/setup_quick_start.ipynb- Interactive setup notebook-
scripts/README.md- Complete documentation for all scripts -
Diagnostic Tools:
notebooks/diagnostic_editable_imports.ipynb- Step-by-step diagnostics- Debug mode support via
DBX_PATCH_DEBUGenvironment variable -
Comprehensive verification functions
-
Documentation:
docs/docs/files/solution-guide.md- Complete troubleshooting guidedocs/docs/files/editable-install-analysis.md- Technical deep divescripts/README.md- Script usage guide
Next Steps (Recommended)
- Test with actual user's environment:
- Get access to their Databricks workspace
- Run
diagnostic_editable_imports.ipynb - Identify which specific hook is blocking
-
Create targeted fix if needed
-
Add unit tests:
# tests/unit/test_all_patches.py
def test_wsfs_path_finder_patch():
from dbx_patch.patches.wsfs_path_finder_patch import patch_wsfs_path_finder
result = patch_wsfs_path_finder(verbose=False)
assert result.success or not result.hook_found # OK if not in Databricks
- Add integration tests:
# tests/integration/test_editable_import.py
def test_editable_package_import():
# Install test package as editable
# Apply patches
# Verify import works
- Create example package:
- Add
examples/test_package/with a simple Python package - Include in CI/CD to test editable installs
-
Document as reference implementation
-
Update main README.md:
- Add quickstart section
- Link to setup scripts
-
Add troubleshooting section
-
Version and release:
- Tag current version
- Update CHANGELOG
- Publish to PyPI if not already done
- Create GitHub release with notes
Implementation Checklist
Patches (All Implemented ✅)
-
sys_path_init_patch.py- Process .pth files -
wsfs_import_hook_patch.py- Allow editable paths -
python_path_hook_patch.py- Preserve paths -
autoreload_hook_patch.py- Register allowlist -
wsfs_path_finder_patch.py- Verify compatibility -
post_import_hook_verify.py- Verify compatibility
Scripts (All Created ✅)
-
scripts/setup_dbx_patch.py- Python setup script -
scripts/setup_dbx_patch.sh- Bash setup script -
scripts/README.md- Script documentation
Notebooks (All Created ✅)
-
notebooks/diagnostic_editable_imports.ipynb- Diagnostics -
notebooks/setup_quick_start.ipynb- Quick setup
Documentation (All Created ✅)
-
docs/docs/files/editable-install-analysis.md- Technical analysis -
docs/docs/files/solution-guide.md- Troubleshooting guide -
scripts/README.md- Script usage
Testing (To Do)
- Unit tests for each patch
- Integration test for end-to-end workflow
- CI/CD pipeline for automated testing
- Example package for testing
Distribution (To Do)
- Update main README.md
- Update CHANGELOG
- Create GitHub release
- Verify PyPI package is up to date
Priority Order
P0 (Critical - Help User Now)
- ✅ Analyze root cause
- ✅ Verify existing patches cover all layers
- ✅ Create diagnostic notebook
- ✅ Create setup scripts
- → User runs patches and reports back
P1 (Important - Complete Solution)
- Get user feedback from running patches
- Fix any remaining issues
- Add tests
- Update README
P2 (Nice to Have - Polish)
- Create example package
- Improve CI/CD
- Add more examples
- Video tutorial
Files Created/Modified
New Files
src/dbx_patch/patches/wsfs_path_finder_patch.pysrc/dbx_patch/patches/post_import_hook_verify.pyscripts/setup_dbx_patch.pyscripts/setup_dbx_patch.shscripts/README.mdnotebooks/diagnostic_editable_imports.ipynbnotebooks/setup_quick_start.ipynbdocs/docs/files/editable-install-analysis.mddocs/docs/files/solution-guide.md
Modified Files
src/dbx_patch/patch_dbx.py- Added verification steps
Quick Reference: What Each Hook Does
| Hook | Location | Purpose | Blocks Editable? | Patch Status |
|---|---|---|---|---|
sys_path_init |
Initialization | Modify sys.path | Yes (doesn't process .pth) | ✅ Patched |
WsfsImportHook |
wsfs_import_hook.py |
Block non-workspace imports | Yes | ✅ Patched |
WsfsPathFinder |
WsfsPathFinder.py |
Prevent notebook imports | No | ✅ Verified |
PythonPathHook |
pythonPathHook.py |
Manage sys.path changes | Yes (removes paths) | ✅ Patched |
AutoreloadHook |
autoreload/discoverability/ |
Wrap imports | Yes | ✅ Patched |
PostImportHook |
PostImportHook.py |
Trigger callbacks | No | ✅ Verified |
Expected Outcome
After applying patches, the following should work:
# Install package with uv
!cd /path/to/package && uv sync --active
# Apply patches
from dbx_patch import patch_dbx
patch_dbx()
# Import should now work!
from testx import function1
print(function1()) # ✅ SUCCESS
Contact Points
- User needs help: Share
scripts/setup_dbx_patch.pyornotebooks/setup_quick_start.ipynb - Still not working: Request output from
diagnostic_editable_imports.ipynb - Found a bug: File GitHub issue with diagnostics output
- Need enhancement: Submit feature request with use case
Summary
All necessary code is complete. The user should:
- Run
patch_dbx() - Try their import
- If it fails, run diagnostics
- Report back with results
The most likely outcome is that it will work because all 5 hook layers are now patched/verified. If not, the diagnostic notebook will identify the specific blocking point.