{{ message }}
Add support for resources in namespace packages - #196
Merged
Conversation
Signed-off-by: Filipe Laíns <lains@archlinux.org>
That is changing, we want to add support for resources in namespace packages. Signed-off-by: Filipe Laíns <lains@archlinux.org>
Signed-off-by: Filipe Laíns <lains@archlinux.org>
Member
|
This project and |
1 task
This was referenced Jan 31, 2022
cutoffthetop
pushed a commit
to robert-koch-institut/mex-model
that referenced
this pull request
Aug 21, 2025
Fix Python 3.9 compatibility issue with importlib.resources Fixes TypeError: expected str, bytes or os.PathLike object, not NoneType when importing mex.model in Python 3.9 due to namespace package issues with importlib.resources.files(). ### Changes - Added importlib_resources fallback for Python < 3.10 compatibility - Added error handling with pkgutil fallback for namespace packages - Updated dependencies to include importlib-resources>=1.3 for Python < 3.10 ### Technical Details The issue occurred because spec.origin is None for namespace packages in Python 3.9, causing pathlib.Path() to fail. The fix: 1. Uses importlib_resources backport which has proper namespace package support 2. Provides fallback using pkgutil.iter_modules() when primary approach fails ### Files Changed - mex/model/__init__.py - Added fallback logic and refactored resource loading - pyproject.toml - Added conditional dependency on importlib-resources ### References - [Add support for resources in namespace packages](python/importlib_resources#196) - importlib_resources backport library - Python 3.9's built-in `importlib.resources` lacks namespace package support, requiring the backport library for compatibility
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.

Fixes #68