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

imports does not respect local directory #2422

Open
ialarmedalien opened this issue Nov 21, 2024 · 1 comment · May be fixed by linkml/linkml-runtime#350
Open

imports does not respect local directory #2422

ialarmedalien opened this issue Nov 21, 2024 · 1 comment · May be fixed by linkml/linkml-runtime#350
Labels
bug Something that should work but isn't, with an example and a test case. community-generated devops poetry, setuptools, actions, etc. related changes

Comments

@ialarmedalien
Copy link
Collaborator

When importing from a local file which references another local file, the file path of the local file is not taken into account.

Example:

|- schema.yaml
|- parts/
|      A.yaml
|      B.yaml

parts/A.yaml file:

imports:
  - B

schema.yaml file:

imports:
  - parts/A

parts/A.yaml can be imported fine using the relative path, but the file it references, parts/B.yaml cannot be found as the SV is looking for it in the same directory as schema.yaml, rather than in parts/.

@ialarmedalien ialarmedalien added the bug Something that should work but isn't, with an example and a test case. label Nov 21, 2024
@ialarmedalien
Copy link
Collaborator Author

Looks like there's a condition missing when assessing whether an import is a relative link in SchemaView.imports_closure:

            if sn not in visited:
                for i in self.schema_map[sn].imports:
                    # no self imports ;)
                    if i == sn:
                        continue

                    # resolve relative imports relative to the importing schema, rather than the
                    # origin schema. Imports can be a URI or Curie, and imports from the same
                    # directory don't require a ./, so if the current (sn) import is a relative
                    # path, and the target import doesn't have : (as in a curie or a URI)
                    # we prepend the relative path. This WILL make the key in the `schema_map` not
                    # equal to the literal text specified in the importing schema, but this is
                    # essential to sensible deduplication:
                    # [...]
                    if sn.startswith(".") and ":" not in i:
                        i = os.path.normpath(str(Path(sn).parent / i))
                    todo.append(i)

Code assumes that relative links will be written as ./file_name -- need to add in a check for / to catch relative links that don't refer to .. It would probably make more sense to check for / instead of ..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that should work but isn't, with an example and a test case. community-generated devops poetry, setuptools, actions, etc. related changes
Projects
None yet
2 participants