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

Constraints demo #362

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft

Constraints demo #362

wants to merge 3 commits into from

Conversation

adswa
Copy link
Member

@adswa adswa commented Mar 2, 2023

This is a small demonstration of using datalad-next constraints for metalad commands using meta-extract and meta-dump. Its a draft PR because it depends on changes from today that haven't even been merged, and there is still one remaining check/constraint to implement to ensure Datasets have a valid dataset ID (so one test will fail no matter what).

I see the following advantages:

  • metalad drives development in datalad-next: Giving the constraints some real world exposure helps identify and fix shortcomings and can lead to new constraints.
  • useful sanity checks for metalad commands that can replace custom existing ones, or add entirely new ones
  • Steps towards more consistent reporting

@adswa
Copy link
Member Author

adswa commented Mar 2, 2023

Exploration of the test failures:


FAILED ../datalad_metalad/extractors/tests/test_base.py::test_plainest - TypeError: one of the hex, bytes, bytes_le, fields, or int arguments must be given
  • fails because the test expects a check for an invalid dataset ID, and there isn't one yet

FAILED ../datalad_metalad/tests/test_extract.py::test_extra_parameter_recognition - ValueError: /home/appveyor/DLTMP/datalad_temp_tree_test_extra_parameter_recognition71uthq8_/k1 does not exist

and

FAILED ../datalad_metalad/tests/test_extract.py::test_extractor_parameter_handling - ValueError: /home/appveyor/DLTMP/datalad_temp_tree_test_extractor_parameter_handling4rnierxm/k0 does not exist
  • the failures seem legit - the test attempts to extract from a path that doesn't exist in the tree. Probably worth adjusting the test.

…lidation

This is a demonstration how one existing command could adopt datalad-next's
parameter constraint validation. It changes the baseclass to next's
ValidatedInterface, and defines a validator with relevant parameter constraints:

Specifically, the constraints are:
- The provided datasets exists, or a dataset can be derived from the curdir
- The path points to an existing file (ref datalad#354)
- The extractorname is a string
- The extractorargs is a mapping of key-value pairs

This makes a dedicated check whether a file exists obsolete, and it could replace
the checks that check_dataset() does (provided an additional constraint option
in EnsureDataset() that allows to check for valid dataset IDs - I've created an
issue about this in datalad/datalad-next#272).

This change would introduce a dependency to datalad-next, and as parts of
this PR were only tested with yet unreleased branches of datalad-next,
it will not work right now unless you're on the right development version
of datalad-next.
This adds an 'EnsureDataset()' parameter validation, and an 'EnsureStr()'
parameter validation for the path argument.
The immediate advantage is that there are now distinct errors for
NoMetaDataStoreFound and NoDatasetFound, which were prior both resulting
in a NoMetaDataStoreFound exception.
@adswa
Copy link
Member Author

adswa commented Mar 2, 2023

Note to self: meta-add has its own validity checks, one is check_dataset_ids, which checks that the dataset ID provided in the metadata record matches the dataset ID the metadata is added to; and process_parameters, which validates the presence or absence of metadata keys. I wonder whether some of their function could be done by a parameter constraint. At the moment, all of these checks run whenever a given metadata item is processed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant