Better handling of resource roots. #112
Merged
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.
Previously, we handled the mapping between file and resource paths using
get_resource_roots()andget_installed_resource_roots(). This PR consolidates the mapping logic intoResourceRootobjects, each representing a directory containing either zipped or unzipped packages.file_path()andfrom_file_path()merely iterate over theResourceRootobjects and return the first result.Other tweaks:
pathlib.Path.relative_to, use a custom implementation that doesn't spend most of its CPU time formatting an error message that we don't care about.wrap_pathfunction to avoid calling the (relatively expensive)Pathconstructor onPathobjects.ResourcePathconstructor with aResourcePathobject as the first argument.These changes improved the performance of a function that calls
from_file_path()on all of the paths insys.modulesby more than a factor of three.Currently, the
ResourceRootlist isn't exposed or documented. This may be a useful primitive for packages that care where resources are located.