-
Notifications
You must be signed in to change notification settings - Fork 14
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
style: remove unused regex and consolidate curator tag logic #3200
Changes from all commits
008d264
1e1f5a5
0eddd3c
9ec6908
99fbba8
21d8e87
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 |
---|---|---|
|
@@ -4,23 +4,23 @@ | |
ID_REGEX = r"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}" | ||
DATASET_ID_REGEX = f"(?P<dataset_id>{ID_REGEX})" | ||
COLLECTION_ID_REGEX = f"(?P<collection_id>{ID_REGEX})" | ||
CURATOR_TAG_PREFIX_REGEX = r"(?P<tag_prefix>.*)" | ||
CONTROL_CHARS = r"[\x00-\x1f\x7f-\xa0]" | ||
CURATOR_TAG_REGEX = r"(?P<tag>.*)" | ||
CURATOR_TAG_REGEX = r"(?P<tag>.+)" | ||
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. no empty tags |
||
|
||
|
||
def validate_curator_tag(curator_tag: str) -> bool: | ||
""" | ||
Verify the correct curator tag format is obeyed. | ||
Verify the correct curator tag format is obeyed (i.e., it is not a UUID) | ||
|
||
:param curator_tag: the tag name to validate. | ||
:return: True if CURATOR_TAG_PREFIX_REGEX is matched. | ||
:return: True if CURATOR_TAG_REGEX is matched. | ||
""" | ||
regex = f"^({DATASET_ID_REGEX}|{CURATOR_TAG_REGEX})$" | ||
matched = re.match(regex, curator_tag) | ||
if matched and (tag := matched.groupdict().get("tag")): | ||
if not re.search(ID_REGEX, tag): | ||
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. removing this because we are only in the business of making sure that we know when to treat an identifier as a uuid, and that is when the identifier takes the precise form of a uuid. Otherwise, if it is not exactly the form of a uuid, we treat it as a curator tag. 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. This requirement was explicitly in the ticket when I implemented it. I updated the ticket to reflect the actual requirements. |
||
return | ||
else: | ||
raise ValueError("Curator tag cannot contain the same shape as a UUID.") | ||
raise ValueError("Invalid curator tag.") | ||
if matched: | ||
matches = matched.groupdict() | ||
if matches.get("tag"): | ||
return True | ||
elif matches.get("dataset_id"): | ||
raise ValueError("Curator tag cannot assume UUID format.") | ||
raise ValueError("Curator tag cannot be empty.") |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,7 +88,7 @@ def _test(_tag, _dataset): | |
self.assertIsNone(_dataset.curator_tag) | ||
|
||
dataset = self.generate_dataset(self.session, collection=collection) | ||
tests = [dataset.id, "prefix" + dataset.id, dataset.id + "suffix", "prefix" + dataset.id + "suffix"] | ||
tests = [dataset.id, ""] | ||
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. (following on from comments above) |
||
for tag_name in tests: | ||
with self.subTest(tag_name): | ||
_test(tag_name, dataset) | ||
|
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.
unused