Port colcon-python-project wheel installation & uninstallation utilities to colcon-core - #741
Port colcon-python-project wheel installation & uninstallation utilities to colcon-core#741KmoM88 wants to merge 7 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #741 +/- ##
==========================================
+ Coverage 87.66% 87.69% +0.03%
==========================================
Files 74 75 +1
Lines 4442 4567 +125
Branches 771 795 +24
==========================================
+ Hits 3894 4005 +111
- Misses 433 441 +8
- Partials 115 121 +6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
cottsay
left a comment
There was a problem hiding this comment.
I'll probably have more feedback but I've been sitting on these two comments for a while so I thought I'd get them posted so they can be discussed now.
Hoping I'll have time to finish the review soon 🤞
| # Explicitly track and clean up residual egg-links in case the | ||
| # distribution files list did not fully cover them. | ||
| for libdir in libdirs: | ||
| for n in (name, name.replace('_', '-')): | ||
| egg_link = libdir / f'{n}.egg-link' | ||
| if egg_link.is_file(): | ||
| logger.debug(f'Removing egg-link {egg_link}') | ||
| try: | ||
| egg_link.unlink() | ||
| deleted_files.append(egg_link) | ||
| except OSError as e: | ||
| logger.warning( | ||
| f"Could not remove egg-link '{egg_link}': {e}" | ||
| ) | ||
|
|
There was a problem hiding this comment.
This should be handled already by colcon_core.python_project.distribution.InstalledDistribution
| # Explicitly track and clean up residual egg-links in case the | |
| # distribution files list did not fully cover them. | |
| for libdir in libdirs: | |
| for n in (name, name.replace('_', '-')): | |
| egg_link = libdir / f'{n}.egg-link' | |
| if egg_link.is_file(): | |
| logger.debug(f'Removing egg-link {egg_link}') | |
| try: | |
| egg_link.unlink() | |
| deleted_files.append(egg_link) | |
| except OSError as e: | |
| logger.warning( | |
| f"Could not remove egg-link '{egg_link}': {e}" | |
| ) |
There was a problem hiding this comment.
Done. Removed the redundant .egg-link deletion block since the link path is already tracked and uninstalled by InstalledDistribution.
| yield base.joinpath(*rel.parts[:i]) | ||
|
|
||
|
|
||
| def _get_script_maker(script_dir, dry_run=False): |
There was a problem hiding this comment.
Like the counterpart in colcon_core.python_project.distribution, we should cache these. (needs from functools import lru_cache as well)
| def _get_script_maker(script_dir, dry_run=False): | |
| @lru_cache(maxsize=32) | |
| def _get_script_maker(script_dir, dry_run=False): |
There was a problem hiding this comment.
Imported lru_cache and decorated _get_script_maker with @lru_cache(maxsize=32).
Overview
This PR ports the core Python wheel installation and uninstallation engine from the prototype extension
colcon-python-projectintocolcon-core.Previously,
colcon-coreonly supported legacy setuptools-centric installations that required spawningsetup.pyscripts. As Python platforms move away from directsetup.pyinvocations in favor of standard PEP 517/518 packaging structures, this PR introduces the native utilities required to install PEP 427 wheel archives (.whl) and safely clean up existing package distributions from the installation prefix.By implementing this metadata-driven layout manager directly inside
colcon-core, we establish the foundation for native PEP 517 build task execution and modern dependency resolution.Key Features
1. Metadata-Driven Uninstallation (
remove_distributions)install.logor.egg-infosymlinks in the build folder), the uninstallation utility queries the targetinstall_baseprefix usingInstalledDistribution.discover..egg-linkfiles and recursively removes any empty parent directories up to theinstall_base.2. Wheel Layout Extraction & Mapping (
install_wheel)Root-Is-Purelibmetadata inside the wheel'sWHEELfile..data/directory segments (e.g.package-1.0.data/data/...) inside the wheel ZIP, translating them to their platform-agnostic target locations dynamically via_get_install_path.entry_points.txtand usesdistlib.scripts.ScriptMakerto generate executable script wrappers under the scripts folder.INSTALLER: Marked as installed bycolcon-core.RECORD: Finalizes and writes the cryptographic hash signatures (sha256) and sizes of all extracted and generated files.Verification & Testing
This PR introduces comprehensive unit tests under the test suite:
typical-dist-info,typical-egg-info,typical-egg-link).remove_distributionssuccessfully uninstalls standard, legacy, and egg-linked packages, deletes all associated files, and cleans up empty parent directories while leaving non-empty folders untouched.install_wheelextracts files into correct library paths, builds CLI scripts, maps data files toshare/, and writes validINSTALLERandRECORDfiles.Automated Tests
Run the newly added test suites locally: