Fallback to importlib_resources on python 3.6

This commit is contained in:
Kovid Goyal 2021-02-19 18:02:15 +05:30
parent c2a924a5ea
commit dbc1ade5a9
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 16 additions and 4 deletions

View File

@ -123,7 +123,10 @@ def run_kitten(kitten: str, run_name: str = '__main__') -> None:
@run_once @run_once
def all_kitten_names() -> FrozenSet[str]: def all_kitten_names() -> FrozenSet[str]:
try:
from importlib.resources import contents from importlib.resources import contents
except ImportError:
from importlib_resources import contents # type: ignore
ans = [] ans = []
for name in contents('kittens'): for name in contents('kittens'):
if '__' not in name and '.' not in name and name != 'tui': if '__' not in name and '.' not in name and name != 'tui':

View File

@ -197,5 +197,8 @@ def resolve_custom_file(path: str) -> str:
def read_kitty_resource(name: str) -> bytes: def read_kitty_resource(name: str) -> bytes:
try:
from importlib.resources import read_binary from importlib.resources import read_binary
except ImportError:
from importlib_resources import read_binary # type: ignore
return read_binary('kitty', name) return read_binary('kitty', name)

View File

@ -8,7 +8,10 @@ import sys
import tempfile import tempfile
import unittest import unittest
from functools import partial from functools import partial
try:
from importlib.resources import read_binary from importlib.resources import read_binary
except ImportError:
from importlib_resources import read_binary
from kitty.constants import is_macos from kitty.constants import is_macos
from kitty.fast_data_types import ( from kitty.fast_data_types import (

View File

@ -6,7 +6,10 @@ import importlib
import os import os
import sys import sys
import unittest import unittest
try:
from importlib.resources import contents from importlib.resources import contents
except Exception:
from importlib_resources import contents
from typing import Callable, Generator, NoReturn, Sequence, Set from typing import Callable, Generator, NoReturn, Sequence, Set