Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that relative imports can be imported without requiring ./ in front of the import file name #350

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions 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 Expand Up @@ -1859,8 +1859,8 @@ def set_modified(self) -> None:
self.modifications += 1

def materialize_patterns(self) -> None:
"""Materialize schema by expanding structured patterns
into regular expressions based on composite patterns
"""Materialize schema by expanding structured patterns
into regular expressions based on composite patterns
provided in the settings dictionary.
"""
resolver = PatternResolver(self)
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 == []
Loading