@@ -108,25 +108,6 @@ def is_absolute_path(path: str) -> bool:
108
108
drive , tail = os .path .splitdrive (norm_path )
109
109
return bool (drive and tail )
110
110
111
- def _resolve_import (source_sch : str , imported_sch : str ) -> str :
112
- if os .path .isabs (imported_sch ):
113
- # Absolute import paths are not modified
114
- return imported_sch
115
- if urlparse (imported_sch ).scheme :
116
- # File with URL schemes are not modified
117
- return imported_sch
118
-
119
- if WINDOWS :
120
- path = PurePath (os .path .normpath (PurePath (source_sch ).parent / imported_sch )).as_posix ()
121
- else :
122
- path = os .path .normpath (str (Path (source_sch ).parent / imported_sch ))
123
-
124
- if imported_sch .startswith ("." ) and not path .startswith ("." ):
125
- # Above condition handles cases where both source schema and imported schema are relative paths: these should remain relative
126
- return f"./{ path } "
127
-
128
- return path
129
-
130
111
131
112
@dataclass
132
113
class SchemaUsage :
@@ -319,14 +300,24 @@ def imports_closure(self, imports: bool = True, traverse: Optional[bool] = None,
319
300
# path, and the target import doesn't have : (as in a curie or a URI)
320
301
# we prepend the relative path. This WILL make the key in the `schema_map` not
321
302
# equal to the literal text specified in the importing schema, but this is
322
- # essential to sensible deduplication: eg . for
303
+ # essential to sensible deduplication: e.g . for
323
304
# - main.yaml (imports ./types.yaml, ./subdir/subschema.yaml)
324
305
# - types.yaml
325
306
# - subdir/subschema.yaml (imports ./types.yaml)
326
307
# - subdir/types.yaml
327
308
# we should treat the two `types.yaml` as separate schemas from the POV of the
328
309
# origin schema.
329
- i = _resolve_import (sn , i )
310
+
311
+ # if i is not a CURIE and sn looks like a path with at least one parent folder,
312
+ # normalise i with respect to sn
313
+ if "/" in sn and ":" not in i :
314
+ if WINDOWS :
315
+ # This cannot be simplified. os.path.normpath() must be called before .as_posix()
316
+ i = PurePath (
317
+ os .path .normpath (PurePath (sn ).parent / i )
318
+ ).as_posix ()
319
+ else :
320
+ i = os .path .normpath (str (Path (sn ).parent / i ))
330
321
todo .append (i )
331
322
332
323
# add item to closure
0 commit comments