1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
class InvalidClassifier(Exception):
pass
def trove_tester(classifiers, deprecated_classifiers):
# Check the classifiers
for classifier in classifiers:
split = classifier.split(" :: ")
# Check if this is an invalid top-level classifier
if len(split) == 1:
raise InvalidClassifier(f"Top-level classifier {classifier!r} is invalid")
# Check if all parent classifiers are specified
for i in range(2, len(split)):
parent = " :: ".join(split[:i])
if parent not in classifiers:
raise InvalidClassifier(f"Classifier {parent!r} is missing")
# Check the sub-classifiers
for sub in split:
# Check for whitespace
if sub.strip().rstrip() != sub:
raise InvalidClassifier(
"Classifiers starting or ending with whitespace are invalid"
)
# Check for private classifiers
if sub.lower().startswith("private"):
raise InvalidClassifier(
"Classifiers starting with 'Private' are invalid"
)
# Check for stray colons
if ":" in sub:
raise InvalidClassifier("Classifiers containing ':' are invalid")
# Check the deprecated classifiers
for deprecated_classifier, deprecated_by in deprecated_classifiers.items():
# Check if the classifier is in both lists
if deprecated_classifier in classifiers:
raise InvalidClassifier(
f"Classifier {deprecated_classifier!r} in both valid and deprecated classifiers"
)
# Check if all deprecated_by classifiers exist
for new_classifier in deprecated_by:
if new_classifier not in classifiers:
raise InvalidClassifier(f"Classifier {new_classifier!r} does not exist")
print("All classifiers passed :)")
|