Skip to content

Commit 19dc518

Browse files
committed
Move away from legacy importlib.resources API
importlib.resources deprecated the top-level read_binary() and similar functions in favor of the new files() API. This is only available in Python 3.9 and later, so the importlib-resources backport has been bumped to be also installed on 3.7 and 3.8.
1 parent 2179964 commit 19dc518

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

airflow/providers_manager.py

+6-14
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,12 @@
3737
from airflow.utils.log.logging_mixin import LoggingMixin
3838
from airflow.utils.module_loading import import_string
3939

40-
try:
41-
import importlib.resources as importlib_resources
42-
except ImportError:
43-
# Try back-ported to PY<37 `importlib_resources`.
44-
import importlib_resources
45-
4640
log = logging.getLogger(__name__)
4741

4842
if sys.version_info >= (3, 9):
49-
from functools import cache
43+
from importlib.resources import files as resource_files
5044
else:
51-
from functools import lru_cache
52-
53-
cache = lru_cache(maxsize=None)
45+
from importlib_resources import files as resource_files
5446

5547
MIN_PROVIDER_VERSIONS = {
5648
"apache-airflow-providers-celery": "2.1.0",
@@ -102,17 +94,17 @@ def __contains__(self, key):
10294

10395
def _create_provider_info_schema_validator():
10496
"""Creates JSON schema validator from the provider_info.schema.json"""
105-
schema = json.loads(importlib_resources.read_text('airflow', 'provider_info.schema.json'))
97+
with resource_files("airflow").joinpath("provider_info.schema.json").open("rb") as f:
98+
schema = json.load(f)
10699
cls = jsonschema.validators.validator_for(schema)
107100
validator = cls(schema)
108101
return validator
109102

110103

111104
def _create_customized_form_field_behaviours_schema_validator():
112105
"""Creates JSON schema validator from the customized_form_field_behaviours.schema.json"""
113-
schema = json.loads(
114-
importlib_resources.read_text('airflow', 'customized_form_field_behaviours.schema.json')
115-
)
106+
with resource_files("airflow").joinpath("customized_form_field_behaviours.schema.json").open("rb") as f:
107+
schema = json.load(f)
116108
cls = jsonschema.validators.validator_for(schema)
117109
validator = cls(schema)
118110
return validator

setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ install_requires =
111111
gunicorn>=20.1.0
112112
httpx
113113
importlib_metadata>=1.7;python_version<"3.9"
114-
importlib_resources~=5.2;python_version<"3.7"
114+
importlib_resources~=5.2;python_version<"3.9"
115115
# Required by vendored-in connexion
116116
inflection>=0.3.1
117117
iso8601>=0.1.12

0 commit comments

Comments
 (0)