-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically import binary extensions whose suffixes include the pyt…
…hon version (#15) <!-- TODO list --> TODO: - [ ] Write new tests or update the old ones to cover new functionality. - [x] Update doc-strings where appropriate. - [ ] Update or write new documentation in `packit/packit.dev`. <!-- notes for reviewers --> For an edge case where the current interpreter version differs from that of the rpm library, and where that library's extension suffixes are included in the `_rpm.so` filename (e.g. `_rpm.cpython-39-x86_64-linux-gnu.so` on RHEL 9.x), add a new `reload_module` method that finds the matching .so and imports it directly. The basic operation is: - gather a list of valid extension suffixes for the rpm library's interpreter, via `importlib.machinery.EXTENSION_SUFFIXES` - try the import but catch any `ModuleNotFoundError` - on `ModuleNotFoundError`, loop through the suffix list, looking for a matching `{module}.{suffix}.so` on disk - when a match is found, import it as `rpm.{module}` directly by path This is probably naive or unwise in some way, but I wanted to take a stab at it so I can use rpm-shim in on RHEL 9.x systems at my company without needing to use the `sudo ln` workaround Example from python3.11 on el9 (Oracle 9.x): ``` DEBUG:rpm-shim:Collected sitepackages and extension suffixes for /usr/libexec/platform-python: {'sitepackages': ['/usr/local/lib64/python3.9/site-packages', '/usr/local/lib/python3.9/site-packages', '/usr/lib64/python3.9/site-packages', '/usr/lib/python3.9/site-packages'], 'suffixes': ['.cpython-39-x86_64-linux-gnu.so', '.abi3.so', '.so']} DEBUG:rpm-shim:Collected sitepackages and extension suffixes for /usr/bin/python3: {'sitepackages': ['/usr/local/lib64/python3.9/site-packages', '/usr/local/lib/python3.9/site-packages', '/usr/lib64/python3.9/site-packages', '/usr/lib/python3.9/site-packages'], 'suffixes': ['.cpython-39-x86_64-linux-gnu.so', '.abi3.so', '.so']} DEBUG:rpm-shim:Collected sitepackages and extension suffixes for /usr/bin/python3.11: {'sitepackages': ['/usr/local/lib64/python3.11/site-packages', '/usr/local/lib/python3.11/site-packages', '/usr/lib64/python3.11/site-packages', '/usr/lib/python3.11/site-packages'], 'suffixes': ['.cpython-311-x86_64-linux-gnu.so', '.abi3.so', '.so']} DEBUG:rpm-shim:Trying /usr/local/lib64/python3.9/site-packages DEBUG:rpm-shim:Trying /usr/local/lib/python3.9/site-packages DEBUG:rpm-shim:Trying /usr/lib64/python3.9/site-packages DEBUG:rpm-shim:Module rpm._rpm not found in /usr/lib64/python3.9/site-packages/rpm, looking for alternative filenames trying valid extension suffixes DEBUG:rpm-shim:Trying to load rpm._rpm from /usr/lib64/python3.9/site-packages/rpm/_rpm.cpython-39-x86_64-linux-gnu.so DEBUG:rpm-shim:Loaded rpm._rpm from /usr/lib64/python3.9/site-packages/rpm/_rpm.cpython-39-x86_64-linux-gnu.so DEBUG:rpm-shim:Reloaded rpm DEBUG:rpm-shim:Import successfull ```
- Loading branch information
Showing
3 changed files
with
138 additions
and
42 deletions.
There are no files selected for viewing
This file contains 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 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 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