-
Notifications
You must be signed in to change notification settings - Fork 2
fix(installer): Prioritize system site packages over server-libs #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mfranczel
merged 7 commits into
main
from
michal/blu-5203-server-site-packages-override-user-installed-packages-due-to
Nov 27, 2025
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c0b20f3
fix(installer): prioritize user-installed packages over server-libs
mfranczel 28a70ec
fix(installer): prioritize user-installed packages over server-libs
mfranczel cc4498a
fix(installer): ensure system site-packages has priority over server-…
mfranczel 2d369da
test(installer): add tests for import_package_bundle priority param
mfranczel 4a9e8eb
refactor(installer): improve import_package_bundle and tests
mfranczel 2021484
style(installer): make priority param keyword-only
mfranczel 0157527
Merge branch 'main' into michal/blu-5203-server-site-packages-overrid…
mfranczel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| """Tests for VirtualEnvironment class.""" | ||
|
|
||
| import os | ||
| from unittest.mock import patch | ||
|
|
||
| import pytest | ||
|
|
||
| from installer.module.virtual_environment import VirtualEnvironment | ||
|
|
||
|
|
||
| class TestImportPackageBundle: | ||
| """Tests for import_package_bundle method.""" | ||
|
|
||
| @pytest.fixture | ||
| def venv(self, tmp_path): | ||
| """Create a VirtualEnvironment with a temporary path.""" | ||
| venv_path = tmp_path / "venv" | ||
| with patch( | ||
| "installer.module.virtual_environment.get_current_python_version", | ||
| return_value="3.11", | ||
| ): | ||
| venv = VirtualEnvironment(str(venv_path)) | ||
| # Create the site-packages directory | ||
| os.makedirs(venv.site_packages_path, exist_ok=True) | ||
| return venv | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| def test_import_package_bundle_plain_path(self, venv): | ||
| """Test that plain path is appended to .pth file.""" | ||
| bundle_path = "/some/bundle/site-packages" | ||
|
|
||
| venv.import_package_bundle(bundle_path) | ||
|
|
||
| pth_file = os.path.join(venv.site_packages_path, "deepnote.pth") | ||
| with open(pth_file, "r") as f: | ||
| content = f.read() | ||
|
|
||
| assert content == f"{bundle_path}\n" | ||
|
|
||
| def test_import_package_bundle_with_condition_env(self, venv): | ||
| """Test that conditional import uses sys.path.insert(0, ...).""" | ||
| bundle_path = "/server/libs/site-packages" | ||
| condition_env = "DEEPNOTE_INCLUDE_SERVER_PACKAGES" | ||
|
|
||
| venv.import_package_bundle(bundle_path, condition_env=condition_env) | ||
|
|
||
| pth_file = os.path.join(venv.site_packages_path, "deepnote.pth") | ||
| with open(pth_file, "r") as f: | ||
| content = f.read() | ||
|
|
||
| assert "import os, sys" in content | ||
| assert f"sys.path.insert(0, '{bundle_path}')" in content | ||
| assert f"os.environ.get('{condition_env}', '').lower() == 'true'" in content | ||
|
|
||
| def test_import_package_bundle_with_priority(self, venv): | ||
| """Test that priority=True uses sys.path.insert(0, ...).""" | ||
| bundle_path = "/usr/local/lib/python3.11/site-packages" | ||
|
|
||
| venv.import_package_bundle(bundle_path, priority=True) | ||
|
|
||
| pth_file = os.path.join(venv.site_packages_path, "deepnote.pth") | ||
| with open(pth_file, "r") as f: | ||
| content = f.read() | ||
|
|
||
| assert "import sys" in content | ||
| assert f"sys.path.insert(0, '{bundle_path}')" in content | ||
| assert "os.environ.get" not in content | ||
|
|
||
| def test_import_package_bundle_ordering(self, venv): | ||
| """Test .pth file content matches expected order from __main__.py.""" | ||
| server_libs = "/tmp/python3.11/server-libs/lib/python3.11/site-packages" | ||
| system_site = "/usr/local/lib/python3.11/site-packages" | ||
| kernel_libs = "/tmp/python3.11/kernel-libs/lib/python3.11/site-packages" | ||
|
|
||
| venv.import_package_bundle( | ||
| server_libs, condition_env="DEEPNOTE_INCLUDE_SERVER_PACKAGES" | ||
| ) | ||
| venv.import_package_bundle(system_site, priority=True) | ||
| venv.import_package_bundle(kernel_libs) | ||
|
|
||
| pth_file = os.path.join(venv.site_packages_path, "deepnote.pth") | ||
| with open(pth_file, "r") as f: | ||
| lines = f.readlines() | ||
|
|
||
| assert len(lines) == 3 | ||
| # Line 1: server-libs conditional | ||
| assert "DEEPNOTE_INCLUDE_SERVER_PACKAGES" in lines[0] | ||
| assert f"sys.path.insert(0, '{server_libs}')" in lines[0] | ||
| # Line 2: system with priority | ||
| assert f"sys.path.insert(0, '{system_site}')" in lines[1] | ||
| # Line 3: kernel plain path | ||
| assert lines[2].strip() == kernel_libs | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.