Skip to content

Commit

Permalink
Merge pull request #756 from geekygirlsarah/main
Browse files Browse the repository at this point in the history
Clear up validation error message
  • Loading branch information
geekygirlsarah authored Oct 7, 2024
2 parents 0130d2d + 3777483 commit 12151c2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 35 deletions.
56 changes: 29 additions & 27 deletions web/management/commands/validatelanginfofiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,39 +46,39 @@ def handle(self, *args, **options):

if not language:
print(
"[Error] `" + relative_path_name + "` has an empty `language` attribute and needs to be updated")
f"[Error] `{relative_path_name}` has an empty `language` attribute and needs to be updated")
error_count += 1
elif language == "language_id":
print(
"[Error] `" + relative_path_name + "` has the default `language` attribute and needs to be updated")
f"[Error] `{relative_path_name}` has the default `language` attribute and needs to be updated")
error_count += 1
elif not language == lang_dir:
print(
"[Error] `" + relative_path_name + "` has a `language` attribute that should be `" + lang_dir + "` and needs to be updated")
f"[Error] `{relative_path_name}` has a `language` attribute that should be `{lang_dir}` and needs to be updated")
error_count += 1

if not language_version:
print(
"[Error] `" + relative_path_name + "` has an empty `language_version` attribute and needs to be updated")
f"[Error] `{relative_path_name}` has an empty `language_version` attribute and needs to be updated")
error_count += 1
elif language_version == "version.number":
print(
"[Error] `" + relative_path_name + "` has the default `language_version` attribute and needs to be updated")
f"[Error] `{relative_path_name}` has the default `language_version` attribute and needs to be updated")
error_count += 1

if not language_name:
print(
"[Error] `" + relative_path_name + "` has an empty `language_name` attribute and needs to be updated")
f"[Error] `{relative_path_name}` has an empty `language_name` attribute and needs to be updated")
error_count += 1
elif language_name == "Human-Friendly Language Name" or language_name == "Human-Readable Language Name":
print(
"[Error] `" + relative_path_name + "` has the default `language_name` attribute and needs to be updated")
f"[Error] `{relative_path_name}` has the default `language_name` attribute and needs to be updated")
error_count += 1

# Ensure categories aren't in file
if "categories" in meta_structure_file_json:
print(
"[Error] `" + relative_path_name + "` has a `categories` section in it, which is now deprecated")
f"[Error] `{relative_path_name}` has a `categories` section in it, which is now deprecated")
error_count += 1

# Ensure name lines are removed
Expand All @@ -88,8 +88,8 @@ def handle(self, *args, **options):
# This generates SO many warnings that I'm commenting it out for now. Consider uncommenting
# when more errors and such have been resolved
# if "name" in structure_item_data:
# print(
# "[Warn] `" + relative_path_name + "`, ID: `" + item + "` has a `name` line that can be removed")
# print(f"[Warn] `{relative_path_name}`, ID: `{item}` has a `name` line that can be "
# f"removed")
# warning_count += 1

# Ensure there's either code or not-implemented
Expand All @@ -100,44 +100,45 @@ def handle(self, *args, **options):

# Ensure they use not-implemented (hyphen) not not_implemented (underscore)
if has_not_underscore_implemented:
print("[Error] `" + relative_path_name + "`, ID: `" + item +
"` has not_implemented (underscore) when it should use not-implemented (hyphen)")
print(f"[Error] `{relative_path_name}`, ID: `{item}` has not_implemented (underscore) "
f"when it should use not-implemented (hyphen)")
error_count += 1

if has_code and (has_not_implemented or has_not_underscore_implemented):
print(
"[Error] `" + relative_path_name + "`, ID: `" + item + "` should have `code` or `not-implemented`, not both")
f"[Error] `{relative_path_name}`, ID: `{item}` should have `code` or "
f"`not-implemented`, not both")
error_count += 1

if not has_code and not has_not_implemented and not has_not_underscore_implemented:
print(
"[Error] `" + relative_path_name + "`, ID: `" + item + "` is missing a needed `code` or `not-implemented` line")
f"[Error] `{relative_path_name}`, ID: `{item}` is missing a needed `code` or "
f"`not-implemented` line")
error_count += 1

# Ensure if not-implemented, there's no code line
if has_not_implemented and structure_item_data["not-implemented"] is True and has_code:
print("[Error] `" + relative_path_name + "`, ID: `" + item +
"` is not implemented, but has a `code` line that should be removed")
print(f"[Error] `{relative_path_name}`, ID: `{item}` is not implemented, but has a "
f"`code` line that should be removed")
error_count += 1

# Ensure if code, it's not empty and there's no not-implemented
if has_code and not structure_item_data["code"] and not has_not_implemented:
print("[Error] `" + relative_path_name + "`, ID: `" + item +
"` is confusing: `code` is empty but there's no `not-implemented` either")
print(f"[Error] `{relative_path_name}`, ID: `{item}` is confusing: `code` is empty "
f"but there's no `not-implemented` either")
error_count += 1

# Ensure it's comment, not comments
if has_comments_plural:
print("[Error] `" + relative_path_name + "`, ID: `" + item +
"` has `comments` (plural) that should be `comment` (singular) instead")
print(f"[Error] `{relative_path_name}`, ID: `{item}` has `comments` (plural) that "
f"should be `comment` (singular) instead")
error_count += 1

# Code can be string or array (maybe warn if string)
# if has_code and isinstance(structure_item_data["code"], str):
# print("[Warning] `" +
# relative_path_name + "`, ID: `" + item +
# "` has a `code` line that's a string and could optionally be an array")
# warning_count += 1
# print(f"[Warning] `{relative_path_name}`, ID: `{item}` has a `code` line that's a "
# f"string and could optionally be an array")
# warning_count += 1

# There shouldn't be any other fields
for key in structure_item_data:
Expand All @@ -147,9 +148,10 @@ def handle(self, *args, **options):
or key == "not-implemented"
or key == "not_implemented"
or key == "name"):
# Why "not_implemented"/"name"/"comments"? Because we check for them above, this checks for other exceptions
print("[Warning] `" + relative_path_name + "`, ID: `" + item +
"` has a line `" + key + "` that's unknown")
# Why "not_implemented"/"name"/"comments"? Because we check for them above,
# this checks for other exceptions
print(f"[Warning] `{relative_path_name}`, ID: `{item}` has a line `{key}` that's "
f"unknown")
warning_count += 1

if warning_count + error_count > 0:
Expand Down
15 changes: 7 additions & 8 deletions web/management/commands/validatemetainfofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,47 +26,46 @@ def handle(self, *args, **options):
if os.path.isdir(path):

if not lang in list(metainfo.languages):
print("[Error] `" + path + "` exists but " + lang + " is not listed as a language in `meta_info.json`")
print(f"[Error] `{path}` exists but {lang} is not listed as a language in `meta_info.json`")
error_count += 1

versions = os.listdir(path)
for version in versions:
if os.path.isfile(path + "/" + version):
print("[Error] `" + path + "/" + version + "` is a file but a directory for a version was expected")
print(f"[Error] `{path}/{version}` is a file but a directory for a version was expected")
error_count += 1
continue

structures = os.listdir(path + "/" + version)
for structure in structures:
# concept_path = "web/thesauruses/" + lang + "/" + version + concept
if structure not in meta_files:
print("[Error] `" + path + "` is not a valid concept filename")
print(f"[Error] `{path}/{version}/{structure}` is not a valid concept filename")
error_count += 1

# Check all language directories exist
for meta_lang in metainfo.languages:
path = "web/thesauruses/" + meta_lang
if not os.path.isdir(path):
print(
"[Error] " + metainfo.languages[meta_lang]
+ " is listed as a language in `meta_info.json` but the directory doesn't exist")
f"[Error] {metainfo.languages[meta_lang]} is listed as a language in `meta_info.json` but the "
f"directory doesn't exist")
error_count += 1

# Check structures are in MetaInfo
for meta_file in meta_files:
structure_name = meta_file[:-5]
if structure_name not in list(metainfo.structures): # .data_structures.values()):
print(
"[Error] " + "`web/thesauruses/_meta/" + meta_file + "` is not listed as a structure in `meta_info.json`")
f"[Error] `web/thesauruses/_meta/{meta_file}` is not listed as a structure in `meta_info.json`")
error_count += 1

# Check all concept files exist in _meta
for structure in metainfo.structures:
path = "web/thesauruses/_meta/" + structure + ".json"
if not os.path.isfile(path):
print(
"[Error] " + structure
+ " is listed as a structure in `meta_info.json` but the `web/thesauruses/_meta/" + structure + ".json` file doesn't exist")
f"[Error] {structure} is listed as a structure in `meta_info.json` but the `web/thesauruses/_meta/{structure}.json` file doesn't exist")
error_count += 1


Expand Down

0 comments on commit 12151c2

Please sign in to comment.