Skip to content
2 changes: 1 addition & 1 deletion installer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def bootstrap():
venv.import_package_bundle(
server_site_packages_path, condition_env="DEEPNOTE_INCLUDE_SERVER_PACKAGES"
)
venv.import_package_bundle(system_site_packages_path)
venv.import_package_bundle(system_site_packages_path, priority=True)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What kind of paths are in front here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue was with server site packages. Since they're dynamically inserted into sys path, they would always be prioritized.

venv.import_package_bundle(kernel_site_package_path)

# Phase 7.2: Symlink notebook to jupyter_server for compatibility with
Expand Down
14 changes: 12 additions & 2 deletions installer/module/virtual_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,17 @@ def start_server(self, command: str, cwd: Optional[str] = None) -> ServerProcess
return server_proc

def import_package_bundle(
self, bundle_site_package_path: str, condition_env: Optional[str] = None
self, bundle_site_package_path: str,
condition_env: Optional[str] = None,
priority: bool = False,
) -> None:
"""
Import a package bundle to the virtual environment.

:param bundle_site_package_path: Absolute path to the package bundle.
:param condition_env: Optional environment variable name. If provided, the bundle
will only be loaded when this env var is set to 'true'.
will only be loaded when this env var is set to 'true'.
:param priority: If True, insert at front of sys.path to override other bundles.
"""
pth_file_path = os.path.join(self._site_packages_path, "deepnote.pth")

Expand All @@ -105,6 +108,13 @@ def import_package_bundle(
"Bundle was conditionally imported to the virtual environment "
f"(loads when {condition_env}=true)."
)
elif priority:
# Insert at front of sys.path for higher priority (overrides other bundles)
pth_content = f"import sys; sys.path.insert(0, '{bundle_site_package_path}')"
pth_file.write(pth_content + "\n")
logger.info(
"Bundle was imported with priority to the virtual environment."
)
else:
pth_file.write(bundle_site_package_path + "\n")
logger.info(
Expand Down
Loading