Skip to content

Commit 33ca663

Browse files
Remove cached reads and restore repeated metadata instantiation which is apparently necessary for test issue 1040 to pass
1 parent 1edef76 commit 33ca663

File tree

3 files changed

+11
-20
lines changed

3 files changed

+11
-20
lines changed

linkml_runtime/loaders/loader_root.py

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from abc import ABC, abstractmethod
22
from typing import TextIO, Union, Optional, Callable, Dict, Type, Any, List
33
from logging import getLogger
4-
from functools import lru_cache
54

65
from pydantic import BaseModel
76
from hbreader import FileInfo, hbread
@@ -150,15 +149,10 @@ def _read_source(self,
150149
base_dir: Optional[str] = None,
151150
metadata: Optional[FileInfo] = None,
152151
accept_header: Optional[str] = "text/plain, application/yaml;q=0.9") -> Union[dict, str]:
153-
154-
# avoid instantiating unhashable FileInfo type by getting default base_path, if any
155-
if base_dir is None:
156-
if metadata is not None:
157-
base_dir = str(metadata.base_path) if metadata.base_path is not None else None
158-
else:
159-
base_dir = str(FileInfo().base_path) if FileInfo().base_path is not None else None
160-
elif base_dir is not None:
161-
base_dir = str(base_dir)
152+
if metadata is None:
153+
metadata = FileInfo()
154+
if base_dir and not metadata.base_path:
155+
metadata.base_path = base_dir
162156

163157
if not isinstance(source, dict):
164158
# Try to get local version of schema, if one is known to exist
@@ -170,15 +164,8 @@ def _read_source(self,
170164
logger = getLogger('linkml_runtime.loaders.Loader')
171165
logger.debug(f"Error converting stringlike source to local linkml file: {source}, got: {e}")
172166

173-
if not isinstance(metadata, FileInfo):
174-
data = self._hashable_read(source, base_dir, accept_header)
175-
else:
176-
data = hbread(source, metadata, base_dir, accept_header)
167+
data = hbread(source, metadata, base_dir, accept_header)
177168
else:
178169
data = source
179170

180-
return data
181-
182-
@lru_cache(maxsize=CACHE_SIZE)
183-
def _hashable_read(self, source: Union[dict, TextIO], base_dir: Optional[str] = None, accept_header: Optional[str] = None):
184-
return hbread(source, None, base_dir, accept_header)
171+
return data

linkml_runtime/loaders/yaml_loader.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ def load_as_dict(self,
2020
*,
2121
base_dir: Optional[str] = None,
2222
metadata: Optional[FileInfo] = None) -> Union[dict, List[dict]]:
23+
if metadata is None:
24+
metadata = FileInfo()
25+
if base_dir and not metadata.base_path:
26+
metadata.base_path = base_dir
2327
data = self._read_source(source, base_dir=base_dir, metadata=metadata, accept_header="text/yaml, application/yaml;q=0.9")
2428
if isinstance(data, str):
2529
data = StringIO(data)

tests/test_issues/test_issue_1040.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ def test_issue_1040_file_name(self):
1919
trace. We use this to make sure that the file name gets in correctly. """
2020
with self.assertRaises(yaml.constructor.ConstructorError) as e:
2121
yaml_loader.load(env.input_path('issue_1040.yaml'), SchemaDefinition)
22-
self.assertIn('File "issue_1040.yaml"', str(e.exception))
22+
self.assertIn('"issue_1040.yaml"', str(e.exception))

0 commit comments

Comments
 (0)