-
Notifications
You must be signed in to change notification settings - Fork 51
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
refactoring load() to allow caller to override file-reading logic #205
Conversation
@dinvlad WDYT of this? I hope making the |
Pull Request Test Coverage Report for Build 910
💛 - Coveralls |
WDL/Tree.py
Outdated
if not os.path.isabs(importer_dir): | ||
morepaths = [os.path.join(p, importer_dir) for p in path] | ||
path.extend(morepaths) | ||
path.append(importer_dir) |
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.
@dinvlad I want to highlight the above logic related to handling nested relative imports, which might become tricky for the LSP get_document()
use case. For example suppose we have a directory tree,
A
├── a.wdl
└── B
├── b.wdl
└── C
└── c.wdl
and A/a.wdl does import B/b.wdl
, b.wdl does import C/c.wdl
. When asked to read_source("C/C.wdl")
one has to figure out that's relative to B/
not A/
.
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.
Hmm, so the uri
parameter to read_source
is verbatim from import
, not a fully resolved absolute path? I thought we could just the uri
to LSP if it was a full file://A/B/C/c.wdl
.
But if it's relative, we'll have to essentially use everything from read_source_default()
until with open(fn, "r") as infile:
, to fully resolve the uri
but not to read it (as reading will be done from memory in LSP, or from file system if the uri
is not in memory).
So given that we have to essentially reuse all but the last couple lines in read_source_default()
, would it perhaps make sense to move the "full URI resolution" functionality into a separate function, and then to provide a read_source_uri(uri)
method to actually implement loading from a fully-resolved URI?
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.
And for a network URI, we don't have to resolve it so it will be just short-cut by read_source_default()
. So making the code in read_source_default()
run always first, before calling read_source_uri()
, could be a general solution :)
Agreed on this point! |
@dinvlad thanks for the feedback! I did more work on it to additionally store the absolute path after resolution of relative loads/imports. The diff is getting pretty unwieldy now but the key docstring: https://github.com/chanzuckerberg/miniwdl/pull/205/files#diff-c7ebedebf9b171179223458e04e073dcR91 and upshot:
|
Hi @mlin, I'm not sure if this addresses our use case directly, if I understood the signature of |
In addition, which function can we call to fully resolve the URI first (that is, to make it absolute To re-iterate, what I was asking for is:
Would it make sense to split functionality in this way, or did I misunderstand the intent of the current |
""" | ||
|
||
|
||
async def resolve_file_import(uri: str, path: List[str], importer: Optional[Document]) -> str: |
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.
@dinvlad ok, sold :) I made read_source_default
call this, rather than taking its result as an argument, in order to avoid having to make them both overridable load()
arguments
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.
Perfect, thanks!!
Hi @mlin, I just realized this is still not working as expected. E.g. when it parses Thanks |
Ok, I was able to achieve this functionality using uri = await WDL.Tree.resolve_file_import(uri, path, importer) I forgot that this is how we decided to do it :-) I guess that'd still be nice to do automatically instead, but not critical. |
Btw, I also noticed that |
as planned in #177 discussion