-
Notifications
You must be signed in to change notification settings - Fork 17
Fix: Addon Manager Python dependency update detection in Flatpak #308
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
base: dev
Are you sure you want to change the base?
Fix: Addon Manager Python dependency update detection in Flatpak #308
Conversation
When updating Python dependencies with pip using --target directory, old package version metadata (.dist-info directories) are not always removed. This causes FreeCAD to detect the old version instead of the newly installed version, particularly in Flatpak installations. This fix adds cleanup logic to remove old package version metadata after a successful update, keeping only the newest version of each package. Fixes #26510
for more information, see https://pre-commit.ci
|
Hi @chennes, I'm a new contributor working on fixing issue #26510 (Python dependency updates in Flatpak). Would you be able to review this PR when you have a chance? I'd really appreciate any feedback or suggestions for improvement. Thank you for your time and for maintaining this project! |
|
Hello @omkarrr2533 -- thanks for your work on this bug. I am happy to review your PR. It will probably take me a couple of days before I can get to it. Thanks for your patience! |
|
Thanks @chennes! Really appreciate you taking a look. Whenever you get to it is totally fine - no rush! Looking forward to your feedback! |
|
@omkarrr2533 can you add some tests of |
|
thanks @chennes! i'll work on adding test for _cleanup_old_package_versions() to test_python_deps.py I am planning to test like: if i get stuck with the mocks, i'll definitely reach out. thanks for offering to help! |
Added unit tests covering: - Removal of old versions while keeping newest - Single version packages (no removal) - Empty and nonexistent directories - Permission error handling - PEP 503 package name normalization - Non-.dist-info directory filtering - Invalid version format handling Tests use proper mocking to avoid filesystem operations and follow existing test patterns in the codebase. These tests verify the cleanup logic works correctly across various scenarios including edge cases like permission errors and malformed directory names. All tests use mocks to ensure fast, reliable execution without touching the actual filesystem.
for more information, see https://pre-commit.ci
chennes
left a comment
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.
Thanks for adding the tests -- overall they look good. One small comment below, and also I suspect that theses tests won't work on Windows since they are using a hardcoded path separator, but internally the code is using os.path.join -- I'd guess your strings won't match. Do you have access to a Windows system to test on?
|
|
||
| # Verify logging happened | ||
| self.assertEqual(mock_print_log.call_count, 3) |
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.
I probably wouldn't test this: we don't really want to have to update the tests just because we change the logging.
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.
thanks @chennes I've addressed both the points
- Removed the logging assertion you're right I shouldn't test implementation details
- fixed windows compatibility - replaced all hardcoded paths with 'os.path.join()'
Unfortunately I don't have access to a Windows system to test on, but the changes should now work correctly since we're using the same os.path.join() approach as the main code.
- Use os.path.join() for all path construction to ensure Windows compatibility - Remove logging count assertion as suggested in review - Tests now work across all platforms (Windows, Linux, macOS)
for more information, see https://pre-commit.ci
Problem Description
Fixes FreeCAD/FreeCAD#26510
When updating Python dependencies through the Addon Manager in Flatpak installations, the update process completes successfully but FreeCAD continues to show the old version as available for update. This occurs because:
~/.var/app/org.freecad.FreeCAD/data/FreeCAD/AdditionalPythonPackages/py312).dist-infometadata directory remains in placeThis causes users to repeatedly see the same updates available even after successful installation.
Solution
This PR adds a
_cleanup_old_package_versions()method that runs after package updates complete. The method:.dist-infodirectoriesThe cleanup only runs for non-system pip installations (like Flatpak), where the
--targetdirectory is used and multiple versions can accumulate.Changes Made
update_call_finished()inaddonmanager_python_deps.pyto call cleanup after update completes_cleanup_old_package_versions()method to handle old version removalVersionclass for accurate version comparisonTesting
The fix has been tested by:
.dist-infodirectoriesManual testing in a Flatpak environment would be appreciated to confirm the fix resolves the reported issue.
Additional Notes
This fix is specifically targeted at Flatpak and similar installations where
using_system_pip_installation_location()returnsFalse. Regular system installations and virtual environments are not affected as they already handle package updates correctly through pip's standard mechanisms.Fixes #26510