From 57534facc5791fe25eed591b55be6d946db3687e Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Fri, 17 Nov 2023 11:26:52 -0500 Subject: [PATCH] Python 3.8 support for importlib.resources.files --- setup.py | 3 +++ src/allmydata/web/common.py | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 97a32fa56..e093e1f95 100644 --- a/setup.py +++ b/setup.py @@ -32,6 +32,9 @@ VERSION_PY_FILENAME = 'src/allmydata/_version.py' version = read_version_py(VERSION_PY_FILENAME) install_requires = [ + # importlib.resources.files and friends are new in Python 3.9. + "importlib_resources; python_version < '3.9'", + "zfec >= 1.1.0", # zope.interface >= 3.6.0 is required for Twisted >= 12.1.0. diff --git a/src/allmydata/web/common.py b/src/allmydata/web/common.py index 982be491a..93aba55f7 100644 --- a/src/allmydata/web/common.py +++ b/src/allmydata/web/common.py @@ -4,7 +4,12 @@ Ported to Python 3. from __future__ import annotations from six import ensure_str -from importlib.resources import files as resource_files, as_file +try: + from importlib.resources import files as resource_files, as_file +except ImportError: + import sys + assert sys.version_info[:2] < (3, 9) + from importlib_resources import files as resource_files, as_file from contextlib import ExitStack import weakref from typing import Optional, Union, TypeVar, overload