-
Notifications
You must be signed in to change notification settings - Fork 0
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
Set DataLad-next 1.0.0b2 dependency, adjust accordingly #23
Changes from 4 commits
cfa6eb4
7e98666
a1cf937
060861c
e8e9cda
0ba3987
dea0e03
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,6 @@ | |
|
||
from redcap.methods.project_info import ProjectInfo | ||
|
||
from datalad.distribution.dataset import ( | ||
require_dataset, | ||
resolve_path, | ||
) | ||
from datalad.interface.common_opts import ( | ||
nosave_opt, | ||
save_message_opt, | ||
|
@@ -142,13 +138,15 @@ class ExportProjectXML(ValidatedInterface): | |
dict( | ||
url=EnsureURL(required=["scheme", "netloc", "path"]), | ||
outfile=EnsurePath(), | ||
dataset=EnsureDataset(installed=True, purpose="export redcap report"), | ||
dataset=EnsureDataset(installed=True, purpose="export REDCap project XML"), | ||
credential=EnsureStr(), | ||
metadata_only=EnsureBool(), | ||
survey_fields=EnsureBool(), | ||
message=EnsureStr(), | ||
save=EnsureBool(), | ||
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. Same remark as above. I believe this is a non-feature. |
||
), | ||
validate_defaults=("dataset",), | ||
tailor_for_dataset=({"outfile": "dataset"}), | ||
) | ||
|
||
@staticmethod | ||
|
@@ -165,22 +163,14 @@ def __call__( | |
save: bool = True, | ||
): | ||
|
||
# work with a dataset object | ||
if dataset is None: | ||
# https://github.com/datalad/datalad-next/issues/225 | ||
ds = require_dataset(None) | ||
else: | ||
ds = dataset.ds | ||
|
||
# sort out the path in context of the dataset | ||
res_outfile = resolve_path(outfile, ds=ds) | ||
ds = dataset.ds | ||
|
||
# refuse to operate if target file is outside the dataset or not clean | ||
ok_to_edit, unlock = check_ok_to_edit(res_outfile, ds) | ||
ok_to_edit, unlock = check_ok_to_edit(outfile, ds) | ||
if not ok_to_edit: | ||
yield get_status_dict( | ||
action="export_redcap_report", | ||
path=res_outfile, | ||
path=outfile, | ||
status="error", | ||
message=( | ||
"Output file status is not clean or the file does not " | ||
|
@@ -217,8 +207,8 @@ def __call__( | |
|
||
# unlock the file if needed, and write contents | ||
if unlock: | ||
ds.unlock(res_outfile) | ||
with open(res_outfile, "wt") as f: | ||
ds.unlock(outfile) | ||
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. See comment above. |
||
with open(outfile, "wt") as f: | ||
f.write(response) | ||
|
||
# save changes in the dataset | ||
|
@@ -231,13 +221,13 @@ def __call__( | |
metadata_only=metadata_only, | ||
survey_fields=survey_fields, | ||
), | ||
path=res_outfile, | ||
path=outfile, | ||
) | ||
|
||
# yield successful result if we made it to here | ||
yield get_status_dict( | ||
action="export_redcap_project_xml", | ||
path=res_outfile, | ||
path=outfile, | ||
status="ok", | ||
) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,6 @@ | |
|
||
from redcap.methods.reports import Reports | ||
|
||
from datalad.distribution.dataset import ( | ||
require_dataset, | ||
resolve_path, | ||
) | ||
from datalad.interface.common_opts import ( | ||
nosave_opt, | ||
save_message_opt, | ||
|
@@ -92,11 +88,13 @@ class ExportReport(ValidatedInterface): | |
url=EnsureURL(required=["scheme", "netloc", "path"]), | ||
report=EnsureStr(), | ||
outfile=EnsurePath(), | ||
dataset=EnsureDataset(installed=True, purpose="export redcap report"), | ||
dataset=EnsureDataset(installed=True, purpose="export REDCap report"), | ||
credential=EnsureStr(), | ||
message=EnsureStr(), | ||
save=EnsureBool(), | ||
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. See comment above. |
||
) | ||
), | ||
validate_defaults=("dataset",), | ||
tailor_for_dataset=({"outfile": "dataset"}), | ||
) | ||
|
||
@staticmethod | ||
|
@@ -112,22 +110,14 @@ def __call__( | |
save: bool = True, | ||
): | ||
|
||
# work with a dataset object | ||
if dataset is None: | ||
# https://github.com/datalad/datalad-next/issues/225 | ||
ds = require_dataset(None) | ||
else: | ||
ds = dataset.ds | ||
|
||
# sort out the path in context of the dataset | ||
res_outfile = resolve_path(outfile, ds=ds) | ||
ds = dataset.ds | ||
|
||
# refuse to operate if target file is outside the dataset or not clean | ||
ok_to_edit, unlock = check_ok_to_edit(res_outfile, ds) | ||
ok_to_edit, unlock = check_ok_to_edit(outfile, ds) | ||
if not ok_to_edit: | ||
yield get_status_dict( | ||
action="export_redcap_report", | ||
path=res_outfile, | ||
path=outfile, | ||
status="error", | ||
message=( | ||
"Output file status is not clean or the file does not " | ||
|
@@ -163,20 +153,20 @@ def __call__( | |
|
||
# unlock the file if needed, and write contents | ||
if unlock: | ||
ds.unlock(res_outfile) | ||
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. See comment above. |
||
with open(res_outfile, "wt") as f: | ||
ds.unlock(outfile) | ||
with open(outfile, "wt") as f: | ||
f.write(response) | ||
|
||
# save changes in the dataset | ||
if save: | ||
ds.save( | ||
message=message if message is not None else "Export REDCap report", | ||
path=res_outfile, | ||
path=outfile, | ||
) | ||
|
||
# yield successful result if we made it to here | ||
yield get_status_dict( | ||
action="export_redcap_report", | ||
path=res_outfile, | ||
path=outfile, | ||
status="ok", | ||
) |
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.
No related to this PR, but I want to challenge the need for this feature.
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.
The need for importing the parameters from
common_opts
? Or the need for having--message
and--nosave
?My idea for
--nosave
was that currently the form (and also report) export can write one or multiple forms into one file.--nosave
was supposed to allow repeating the command to write several forms into several files, and capturing them in a single, manual, save afterwards. But we could later add a many-forms-to-separate-files variant of the export command, and make the problem go away. Or we could do away with--nosave
right now (should--message
stay?) - is that what you suggest?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.
Without deeply thinking about it again, I'd say this command should either
If it always saves, it should support setting a message (see datalad/datalad#3316)
However, this creates complications. See datalad/datalad#3896 for an entrypoint to some. Few more keywords are: recursive saving of superdatasets, etc.
Just saving also does not necessarily provide an indication of the origin of the save information.
Without wanting to propse a full concept: It may just be better to never save for this command.
for_each_dataset
, and safe at then end or individually as they desireddatalad run
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.
Interesting - I'll probably take it to a separate issue to think of it a bit more. FTR, the current behavior when saving is to use the provided message or craft one based on the form names. And the command would refuse operation if a file is in a subdataset, if that matters.
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.
It matters in that an operation in a hierarchical dataset tree already requires more saving than the command can provide.