|
37 | 37 | from airflow.utils.log.logging_mixin import LoggingMixin
|
38 | 38 | from airflow.utils.module_loading import import_string
|
39 | 39 |
|
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 |
| - |
46 | 40 | log = logging.getLogger(__name__)
|
47 | 41 |
|
48 | 42 | if sys.version_info >= (3, 9):
|
49 |
| - from functools import cache |
| 43 | + from importlib.resources import files as resource_files |
50 | 44 | else:
|
51 |
| - from functools import lru_cache |
52 |
| - |
53 |
| - cache = lru_cache(maxsize=None) |
| 45 | + from importlib_resources import files as resource_files |
54 | 46 |
|
55 | 47 | MIN_PROVIDER_VERSIONS = {
|
56 | 48 | "apache-airflow-providers-celery": "2.1.0",
|
@@ -102,17 +94,17 @@ def __contains__(self, key):
|
102 | 94 |
|
103 | 95 | def _create_provider_info_schema_validator():
|
104 | 96 | """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) |
106 | 99 | cls = jsonschema.validators.validator_for(schema)
|
107 | 100 | validator = cls(schema)
|
108 | 101 | return validator
|
109 | 102 |
|
110 | 103 |
|
111 | 104 | def _create_customized_form_field_behaviours_schema_validator():
|
112 | 105 | """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) |
116 | 108 | cls = jsonschema.validators.validator_for(schema)
|
117 | 109 | validator = cls(schema)
|
118 | 110 | return validator
|
|
0 commit comments