From 04839bbce0ff9ff4e2586257edb2865fa7614db6 Mon Sep 17 00:00:00 2001 From: Maja Massarini Date: Tue, 12 Nov 2024 11:06:39 +0100 Subject: [PATCH] Allow building specfile in CentOS Stream without EPEL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When building CentOS Stream in CBS Koji, EPEL packages are not available. There is no package typing-extensions. Co-authored-by: Nikola Forró --- setup.cfg | 2 +- specfile/types.py | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/setup.cfg b/setup.cfg index 3e07aaf..8b13093 100644 --- a/setup.cfg +++ b/setup.cfg @@ -39,7 +39,7 @@ install_requires = importlib-metadata;python_version<"3.8" dataclasses;python_version<"3.7" rpm - typing-extensions + typing-extensions;python_version<"3.8" python_requires = >=3.6 include_package_data = True diff --git a/specfile/types.py b/specfile/types.py index b2fada2..c265891 100644 --- a/specfile/types.py +++ b/specfile/types.py @@ -3,10 +3,12 @@ import abc -from typing_extensions import Protocol - - -# define our own SupportsIndex type for older version of typing_extensions (EL 8) -class SupportsIndex(Protocol, metaclass=abc.ABCMeta): - @abc.abstractmethod - def __index__(self) -> int: ... +try: + from typing import SupportsIndex +except ImportError: + # define our own SupportsIndex type for older version of typing (Python 3.7 and older) + from typing_extensions import Protocol + + class SupportsIndex(Protocol, metaclass=abc.ABCMeta): # type: ignore [no-redef] + @abc.abstractmethod + def __index__(self) -> int: ...