Handle deprecation of importlib.resources APIs
This commit is contained in:
+32
-7
@@ -7,7 +7,7 @@ import os
|
||||
import pwd
|
||||
import sys
|
||||
from contextlib import suppress
|
||||
from typing import NamedTuple, Optional, Set, TYPE_CHECKING
|
||||
from typing import TYPE_CHECKING, Iterable, NamedTuple, Optional, Set
|
||||
|
||||
from .types import run_once
|
||||
|
||||
@@ -74,8 +74,8 @@ def _get_config_dir() -> str:
|
||||
return q
|
||||
|
||||
def make_tmp_conf() -> None:
|
||||
import tempfile
|
||||
import atexit
|
||||
import tempfile
|
||||
ans = tempfile.mkdtemp(prefix='kitty-conf-')
|
||||
|
||||
def cleanup() -> None:
|
||||
@@ -181,12 +181,37 @@ def resolve_custom_file(path: str) -> str:
|
||||
return path
|
||||
|
||||
|
||||
def read_kitty_resource(name: str) -> bytes:
|
||||
try:
|
||||
def list_kitty_resources(package: str = 'kitty') -> Iterable[str]:
|
||||
if sys.version_info >= (3, 9):
|
||||
from importlib.resources import files
|
||||
|
||||
def contents(package: str) -> Iterable[str]:
|
||||
return (path.name for path in files(package).iterdir())
|
||||
elif sys.version_info < (3, 7):
|
||||
from importlib_resources import files
|
||||
|
||||
def contents(package: str) -> Iterable[str]:
|
||||
return (path.name for path in files(package).iterdir())
|
||||
else:
|
||||
from importlib.resources import contents
|
||||
return contents(package)
|
||||
|
||||
|
||||
def read_kitty_resource(name: str, package_name: str = 'kitty') -> bytes:
|
||||
if sys.version_info >= (3, 9):
|
||||
from importlib.resources import files
|
||||
|
||||
def read_binary(package: str, resource: str) -> bytes:
|
||||
return (files(package) / resource).read_bytes()
|
||||
elif sys.version_info < (3, 7):
|
||||
from importlib_resources import files
|
||||
|
||||
def read_binary(package: str, resource: str) -> bytes:
|
||||
return (files(package) / resource).read_bytes()
|
||||
else:
|
||||
from importlib.resources import read_binary
|
||||
except ImportError:
|
||||
from importlib_resources import read_binary # type: ignore
|
||||
return read_binary('kitty', name)
|
||||
|
||||
return read_binary(package_name, name)
|
||||
|
||||
|
||||
def website_url(doc_name: str = '') -> str:
|
||||
|
||||
Reference in New Issue
Block a user