-
Notifications
You must be signed in to change notification settings - Fork 34
Fix detection of CURIES vs. absolute paths on Windows #391
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
Merged
sierra-moxon
merged 5 commits into
linkml:main
from
dalito:issue2696-curie-vs-path-on-windows
May 19, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a7a5102
Fix detection of CURIES vs. absolute paths on Windows
dalito 1a53d82
Fix type checking
dalito 02523d9
Add test for context_utils.map_import & switch to pytest
dalito fa6d966
Fix test to work cross platform
dalito cd17c76
Install all extras for upstream linkml tests (fix pandera tests)
dalito File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,12 @@ | |
import yaml | ||
from jsonasobj2 import JsonObj, loads | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from linkml_runtime.utils.namespaces import Namespaces | ||
|
||
|
||
CONTEXT_TYPE = Union[str, dict, JsonObj] | ||
CONTEXTS_PARAM_TYPE = Optional[Union[CONTEXT_TYPE, list[CONTEXT_TYPE]]] | ||
|
||
|
@@ -50,7 +56,7 @@ | |
JsonObj(**{"@context": context_list[0] if len(context_list) == 1 else context_list}) | ||
|
||
|
||
def map_import(importmap: dict[str, str], namespaces: Callable[[None], "Namespaces"], imp: Any) -> str: | ||
def map_import(importmap: dict[str, str], namespaces: Callable[[], "Namespaces"], imp: Any) -> str: | ||
""" | ||
lookup an import in an importmap. | ||
|
||
|
@@ -73,7 +79,8 @@ | |
else: | ||
sname = os.path.join(expanded_prefix, lname) | ||
sname = importmap.get(sname, sname) # Import map may use CURIE | ||
sname = str(namespaces().uri_for(sname)) if ':' in sname else sname | ||
if ':' in sname and not ":\\" in sname: # Don't interpret Windows paths as CURIEs | ||
sname = str(namespaces().uri_for(sname)) | ||
return importmap.get(sname, sname) # It may also use URI or other forms | ||
|
||
|
||
|
@@ -103,7 +110,7 @@ | |
if base: | ||
outmap = dict() | ||
for k, v in rval.items(): | ||
if ':' not in v: | ||
if ':' not in v or ":\\" in v: # Don't interpret Windows paths as CURIEs | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎉 |
||
v = os.path.join(os.path.abspath(base), v) | ||
outmap[k] = v | ||
rval = outmap | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know there's at least one other place (apart from the one below) where there's a similar check to try to determine if something is a CURIE or not. I wonder if it'd be better to extract this out into a separate function -- I know it's an extremely simple check, but maybe it would lessen the chance of similar errors occurring elsewhere. There's a bug in the SchemaViewer that stops remote schemas being imported from other remote schemas, and it's due to this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure if it is worth to move the check into a function. I still hope that one day we will use more specific types (Path, URI, CURIE) instead of string. This would make the code much cleaner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, that's the best way to fix the issue. One day...!