constraints.py 837 B

123456789101112131415161718192021
  1. from datalad.support.constraints import EnsureStr
  2. class EnsureDatasetSiblingName(EnsureStr):
  3. # we cannot really test this, because we have no access to a repo
  4. # TODO think about expanding the __call__ API to take a positional
  5. # a the key value (status quo), but also take a range of kwargs
  6. # such that a constraint could be validated more than once
  7. # (i.e. not just by argparse at the CLI, but also inside an
  8. # implementation, maybe once a dataset context is known).
  9. # Could also be implemented by a dedicated `valid_for(value, dataset)`
  10. def __init__(self):
  11. # basic protection against an empty label
  12. super().__init__(min_len=1)
  13. def long_description(self):
  14. return 'value must be the name of a dataset sibling'
  15. def short_description(self):
  16. return 'sibling name'