fix(qgis): validate Python interpreters before venv creation#86
Merged
Conversation
The official macOS QGIS app bundle ships a python3.x binary whose embedded prefix points at the build machine, so it fails before startup with "No module named 'encodings'". Probe candidates with a short subprocess and fall back to letting uv resolve the matching Python version when no startable interpreter is found.
|
🚀 Deployed on https://69fe43a9afd56273cdc2b27a--opengeos.netlify.app |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves QGIS plugin virtual-environment creation reliability (especially on macOS QGIS.app bundles) by validating Python interpreter candidates before using them, and by allowing uv to resolve a matching Python version when the bundled interpreter cannot start.
Changes:
- Add a “probe” check to verify Python interpreter candidates can start and match the current QGIS Python major/minor.
- Update interpreter selection to skip unstartable candidates and include rejected-candidate reasons in failure messages.
- Adjust
create_venv()to fall back touv venv --python <major.minor>when no startable interpreter path is available, and add tests for these scenarios.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
qgis_geoagent/open_geoagent/deps_manager.py |
Adds interpreter usability probing, improves candidate selection diagnostics, and updates create_venv() to let uv resolve a Python version when needed. |
qgis_geoagent/tests/test_settings_diagnostics.py |
Updates/extends tests to cover skipping broken macOS bundle Python and uv version-resolution fallback behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Reword the no-Python-found RuntimeError to say "sys.executable is not a usable Python interpreter" since the branch is now reachable when sys.executable is Python but unstartable or the wrong major.minor. - Stub _python_executable_usable in the macOS bundle tests to return an empty reason on success, matching the real implementation contract.
- Updated `venv_exists` to accept an optional `venv_dir` argument for improved flexibility. - Introduced `venv_python_usable` to validate the usability of the Python executable in the virtual environment. - Added `_ensure_usable_venv` to recreate stale or broken virtual environments. - Enhanced `create_venv` to handle errors more gracefully and provide clearer feedback on failures. - Updated `install_packages` to retry with pip if uv installation fails. - Added tests to ensure proper handling of broken virtual environments and fallback mechanisms during package installation.
- Introduced `_is_macos_qgis_app_bundle_python` to identify Python binaries within QGIS macOS app bundles. - Updated `_python_executable_usable` to reject app bundle Python for virtual environment creation, ensuring safer environment management. - Added a test to verify that QGIS app bundle Python is correctly identified and rejected for venv usage.
for more information, see https://pre-commit.ci
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Test plan