Skip to content

Commit

Permalink
Ensure that relative imports can be imported without requiring ./ i…
Browse files Browse the repository at this point in the history
…n front of the import file name
  • Loading branch information
ialarmedalien committed Jan 31, 2025
1 parent c0d73b1 commit adb8ed1
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 3 deletions.
2 changes: 1 addition & 1 deletion linkml_runtime/utils/schemaview.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def imports_closure(self, imports: bool = True, traverse: Optional[bool] = None,
# - subdir/types.yaml
# we should treat the two `types.yaml` as separate schemas from the POV of the
# origin schema.
if sn.startswith('.') and ':' not in i:
if '/' in sn and ':' not in i:
i = os.path.normpath(str(Path(sn).parent / i))
todo.append(i)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
id: four
name: import_four
title: Import Four
description: |
Import loaded by the StepChild class.
imports:
- linkml:types
classes:
Four:
attributes:
value:
range: string
ifabsent: "Four"
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
id: one
name: import_one
title: Import One
description: |
Import loaded by the StepChild class.
imports:
- linkml:types
- two
classes:
One:
attributes:
value:
range: string
ifabsent: "One"
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
id: stepchild
name: stepchild
title: stepchild
description: |
Child class that imports files in the same directory as itself without consistently using `./` in the link notation.
imports:
- linkml:types
- one
- two
- ./three
classes:
StepChild:
attributes:
value:
range: string
ifabsent: "StepChild"
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
id: three
name: import_three
title: Import Three
description: |
Import loaded by the StepChild class.
imports:
- linkml:types
- ./four
classes:
Three:
attributes:
value:
range: string
ifabsent: "Three"
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
id: two
name: import_two
title: Import Two
description: |
Import loaded by the StepChild class.
imports:
- linkml:types
classes:
Two:
attributes:
value:
range: string
ifabsent: "Two"
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ imports:
- ../../L0_1/cousin
- ./L2_0_0_0/child
- ./L2_0_0_1/child
- L2_0_0_2/stepchild
classes:
Main:
description: "Our intrepid main class!"
attributes:
value:
range: string
ifabsent: "Main"
ifabsent: "Main"
7 changes: 6 additions & 1 deletion tests/test_utils/test_schemaview.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,11 @@ def test_imports_relative():
'../L1_0_1/dupe',
'./L2_0_0_0/child',
'./L2_0_0_1/child',
'L2_0_0_2/two',
'L2_0_0_2/one',
'L2_0_0_2/four',
'L2_0_0_2/three',
'L2_0_0_2/stepchild',
'main'
]

Expand Down Expand Up @@ -896,4 +901,4 @@ def test_materialize_nonscalar_slot_usage():
assert cls.attributes["tempo"].annotations.expected_value.value == "a number between 0 and 200"
assert cls.attributes["tempo"].annotations.preferred_unit.value == "BPM"
assert cls.attributes["tempo"].domain_of == ["DJController"]
assert cls.slot_usage["tempo"].domain_of == []
assert cls.slot_usage["tempo"].domain_of == []

0 comments on commit adb8ed1

Please sign in to comment.