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

RF: Simplify EnsureDataset and add optional ID check #279

Merged
merged 6 commits into from
Mar 3, 2023

Conversation

adswa
Copy link
Member

@adswa adswa commented Mar 3, 2023

This sits on top of #271 to prevent a merge conflict and make use of the changes required for type checking already implemented in it.

This PR adds two changes in individual commits:

The first commit refactors EnsureDataset - there was some duplication that I thought could be reduced by factoring out a _require_dataset() helper.

The second commit adds an optional idcheck to EnsureDataset to fix #272

mih and others added 4 commits March 2, 2023 16:10
Previously this method only got a `Dataset`-type argument. However,
for path resolution (for example), this information is insufficient,
because DataLad needs to know whether the type of the original argument.

For this reason `DatasetParameter` already existed, and is now also used
for this purpose.

This also simplified the type-annotation -- no need for custom typevars.

It also made sense to move the `DatasetParameter` class to `base.py`,
because every single constraint implementation has to support it (or
use the default implementation from `base.py`.
This implements DataLad's standard path resolution approach (relative
is relative to CWD, unless a `Dataset` instance is given).

This now makes it possible to perform this standard resolution pattern
during command parameter validation, like so:

```py
\# example validator for a command with two args
EnsureCommandParameterization(
    param_constraints=dict(
        dataset=EnsureDataset(),
        path=EnsurePath(),
    ),
    tailor_for_dataset=dict(path='dataset'),
)
```

This will:

- cause the 'dataset' validator to run first
- auto-generate an `EnsurePath` variant that resolves against that
  dataset
- ensures that the command always receives absolute paths, resolved
  against the dataset whenever the rules require it.

Closes datalad#270
@adswa adswa requested a review from mih as a code owner March 3, 2023 08:19
@adswa adswa changed the title Rf dataset RF: Simplify EnsureDataset and add optional ID check Mar 3, 2023
Copy link
Member

@mih mih left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this works for me! I only left minor, and a naming suggestion. I could be convinced otherwise, though.

datalad_next/constraints/dataset.py Outdated Show resolved Hide resolved
datalad_next/constraints/dataset.py Outdated Show resolved Hide resolved
datalad_next/constraints/tests/test_special_purpose.py Outdated Show resolved Hide resolved
Copy link
Member

@mih mih left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thx!

@mih mih merged commit 318d200 into datalad:main Mar 3, 2023
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.

Add a dataset ID check for EnsureDataset?
2 participants