Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions ocrd_utils/ocrd_utils/package_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from pathlib import Path

try:
from importlib.resources import path, read_binary
from importlib.resources import as_file, files
except ImportError:
from importlib_resources import path, read_binary # type: ignore
from importlib_resources import as_file, files # type: ignore

try:
from importlib.metadata import distribution as get_distribution
Expand All @@ -29,7 +29,7 @@ def resource_filename(package: str, resource: str) -> Path:
The resource to look up
"""
parent_package = package.rsplit('.',1)[0]
return _file_manager.enter_context(path(parent_package, resource))
return _file_manager.enter_context(as_file(files(parent_package).joinpath(resource)))


def resource_string(package: str, resource: str) -> bytes:
Expand All @@ -44,7 +44,6 @@ def resource_string(package: str, resource: str) -> bytes:
The resource to look up
"""
parent_package = package.rsplit('.',1)[0]
return read_binary(parent_package, resource)

return files(parent_package).joinpath(resource).read_bytes()

__all__ = ['resource_filename', 'resource_string', 'get_distribution']