-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix crashes on python <3.12 after convert to uv
basically remove all the legacy importlib hacks Signed-off-by: Grant Ramsay <[email protected]>
- Loading branch information
Showing
4 changed files
with
64 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,7 @@ | ||
"""Package initialisation.""" | ||
|
||
from importlib import resources | ||
from pathlib import Path | ||
from typing import IO | ||
|
||
from single_source import get_version | ||
|
||
try: | ||
from pkg_resources import resource_listdir, resource_stream # type: ignore | ||
except ImportError: | ||
|
||
def resource_stream( | ||
package_or_requirement: resources.Package, resource_name: str | ||
) -> IO[bytes]: | ||
"""Emulate the 'resource_stream' method.""" | ||
ref = resources.files(package_or_requirement).joinpath(resource_name) | ||
return ref.open("rb") | ||
|
||
def resource_listdir( | ||
package_or_requirement: resources.Package, resource_name: str | ||
) -> list[str]: | ||
"""Emulate the 'resource_listdir' method.""" | ||
resource_qualname = f"{package_or_requirement}".rstrip(".") | ||
return [ | ||
r.name | ||
for r in resources.files(resource_qualname) | ||
.joinpath(resource_name) | ||
.iterdir() | ||
] | ||
|
||
|
||
__version__ = get_version(__name__, Path(__file__).parent.parent) | ||
|
||
__all__ = ["resource_listdir", "resource_stream"] |
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