From dbc1ade5a9e2bcaaa07717fdea43e414427f2fda Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 19 Feb 2021 18:02:15 +0530 Subject: [PATCH] Fallback to importlib_resources on python 3.6 --- kittens/runner.py | 5 ++++- kitty/constants.py | 5 ++++- kitty_tests/fonts.py | 5 ++++- kitty_tests/main.py | 5 ++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/kittens/runner.py b/kittens/runner.py index 410383532..5de091763 100644 --- a/kittens/runner.py +++ b/kittens/runner.py @@ -123,7 +123,10 @@ def run_kitten(kitten: str, run_name: str = '__main__') -> None: @run_once def all_kitten_names() -> FrozenSet[str]: - from importlib.resources import contents + try: + from importlib.resources import contents + except ImportError: + from importlib_resources import contents # type: ignore ans = [] for name in contents('kittens'): if '__' not in name and '.' not in name and name != 'tui': diff --git a/kitty/constants.py b/kitty/constants.py index 5160e363f..6bb420044 100644 --- a/kitty/constants.py +++ b/kitty/constants.py @@ -197,5 +197,8 @@ def resolve_custom_file(path: str) -> str: def read_kitty_resource(name: str) -> bytes: - from importlib.resources import read_binary + try: + from importlib.resources import read_binary + except ImportError: + from importlib_resources import read_binary # type: ignore return read_binary('kitty', name) diff --git a/kitty_tests/fonts.py b/kitty_tests/fonts.py index 63703eecb..b565e53e2 100644 --- a/kitty_tests/fonts.py +++ b/kitty_tests/fonts.py @@ -8,7 +8,10 @@ import sys import tempfile import unittest from functools import partial -from importlib.resources import read_binary +try: + from importlib.resources import read_binary +except ImportError: + from importlib_resources import read_binary from kitty.constants import is_macos from kitty.fast_data_types import ( diff --git a/kitty_tests/main.py b/kitty_tests/main.py index 176abab62..6998ffa6b 100644 --- a/kitty_tests/main.py +++ b/kitty_tests/main.py @@ -6,7 +6,10 @@ import importlib import os import sys import unittest -from importlib.resources import contents +try: + from importlib.resources import contents +except Exception: + from importlib_resources import contents from typing import Callable, Generator, NoReturn, Sequence, Set