Skip to content

Commit

Permalink
still overwriting, and lacking yamlfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
turbomam committed Oct 14, 2024
1 parent e10411b commit dad7c25
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ examples/output: src/mixs/schema/mixs.yaml

.PHONY: standardize-schema

# |\
# yamlfmt -in -conf .yamlfmt >

standardize-schema:
$(RUN) python src/scripts/describe_enums_by_slots_using.py \
--schema_file src/mixs/schema/mixs.yaml \
Expand All @@ -172,11 +175,14 @@ standardize-schema:
yq eval 'del(.slots.[].domain)' |\
yq eval 'del(.slots.[].name)' |\
yq eval 'del(.source_file)' |\
yq eval 'del(.subsets.[].name)' |\
yamlfmt -in -conf .yamlfmt > src/mixs/schema/mixs_standardized.yaml
yq eval 'del(.subsets.[].name)' | cat > src/mixs/schema/mixs_standardized.yaml
mv src/mixs/schema/mixs_standardized.yaml src/mixs/schema/mixs.yaml
rm -rf src/mixs/schema/mixs_standardized.yaml src/mixs/schema/mixs_with_enum_descriptions.yaml

test1:
echo $$PATH
yamlfmt -conf .yamlfmt src/mixs/schema/mixs.yaml > src/mixs/schema/mixs_standardized.yam

# Test documentation locally
serve: mkd-serve

Expand Down
21 changes: 15 additions & 6 deletions src/scripts/describe_enums_by_slots_using.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ def update_enum_descriptions(schema_file: str, output_file: str) -> None:
by other terms (slots). The descriptions will indicate whether an enum is used by any term, and if so,
by how many terms and which ones.
Does not overwrite existing descriptions
:param schema_file: Path to the input schema file.
:param output_file: Path to the output schema file where the updated schema will be saved.
"""
Expand All @@ -26,12 +28,19 @@ def update_enum_descriptions(schema_file: str, output_file: str) -> None:
user_names = [u.name for u in users]
user_names.sort()

if len(user_names) == 0:
ev.description = "Permissible values, not used by any term"
elif len(user_names) == 1:
ev.description = f"Permissible values, used by term {user_names[0]}"
else: # len(user_names) > 1
ev.description = f"Permissible values, used by {len(user_names)} terms: {', '.join(user_names)}"
new_desc = ""

if ev.description is None or ev.description != "":
if len(user_names) == 0:
new_desc = "Permissible values, not used by any term"
elif len(user_names) == 1:
new_desc = f"Permissible values, used by term {user_names[0]}"
else: # len(user_names) > 1
new_desc = f"Permissible values, used by {len(user_names)} terms: {', '.join(user_names)}"
ev.description = new_desc
else:
click.echo(
f"Permissible value {ek} already has description '{ev.description}'. Refusing to overwrite with {new_desc}.")

yaml_dumper.dump(schema_view.schema, output_file)
click.echo(f"Enum descriptions updated and saved to {output_file}")
Expand Down

0 comments on commit dad7c25

Please sign in to comment.