Skip to content

Commit 39a5e04

Browse files
committed
Update scripts
1 parent 9b19b8a commit 39a5e04

2 files changed

Lines changed: 43 additions & 28 deletions

File tree

src/obofoundry/remove_field.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
"""A workflow for removing a field from all ontology markdown files' metadata."""
22

3+
import json
34
from io import StringIO
45
from pathlib import Path
56

67
import click
78
import yaml
89

9-
from obofoundry.constants import ONTOLOGY_DIRECTORY
10+
from obofoundry.constants import ONTOLOGY_DIRECTORY, ROOT
1011
from obofoundry.standardize_metadata import ModifiedDumper
1112

1213

@@ -15,6 +16,12 @@ def remove_field(name: str) -> None:
1516
for path in ONTOLOGY_DIRECTORY.glob("*.md"):
1617
remove_field_from_file(path, name)
1718

19+
schema_path = ROOT.joinpath("util", "schema", "registry_schema.json")
20+
schema = json.loads(schema_path.read_text())
21+
if name in schema['properties']:
22+
del schema['properties'][name]
23+
schema_path.write_text(json.dumps(schema, indent=2) + "\n")
24+
1825

1926
def remove_field_from_file(path: Path, name: str) -> None:
2027
"""Update the given markdown file."""
@@ -41,10 +48,11 @@ def remove_field_from_file(path: Path, name: str) -> None:
4148

4249

4350
@click.command()
44-
@click.argument("name")
45-
def main(name: str) -> None:
51+
@click.argument("names", nargs=-1)
52+
def main(names: list[str]) -> None:
4653
"""Remove the metadata key from all ontologies' metadata."""
47-
remove_field(name)
54+
for name in names:
55+
remove_field(name)
4856

4957

5058
if __name__ == "__main__":

util/check_schema.py

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121

2222

2323
@click.command()
24-
@click.option("--max-cutoff", type=int, default=3, show_default=True)
24+
@click.option("--max-cutoff", type=int, default=20, show_default=True)
2525
@click.option("--links", is_flag=True)
2626
def main(max_cutoff: int, links: bool):
2727
"""Check schema usage."""
2828
_check_schema(max_cutoff=max_cutoff, links=links)
2929

3030

31-
def _check_schema(max_cutoff: int = 3, links: bool = True):
31+
def _check_schema(max_cutoff: int, links: bool = True):
3232
ontologies = get_data()
3333

3434
property_usage = Counter()
@@ -44,27 +44,31 @@ def _check_schema(max_cutoff: int = 3, links: bool = True):
4444
if key in data:
4545
r[key].add(prefix)
4646

47-
print(f"Fields used at most {max_cutoff} times:")
48-
print(
49-
tabulate(
50-
[
51-
(
52-
k,
53-
", ".join(
54-
(
55-
f"[{prefix}](https://obofoundry.org/ontologies/{prefix})"
56-
if links
57-
else prefix
58-
)
59-
for prefix in prefixes
60-
),
61-
)
62-
for k, prefixes in r.items()
63-
],
64-
tablefmt="github",
65-
headers=["key", "ontologies"],
47+
if r:
48+
print(f"Fields used at most {max_cutoff} times:")
49+
print(
50+
tabulate(
51+
[
52+
(
53+
k,
54+
len(prefixes),
55+
", ".join(
56+
(
57+
f"[{prefix}](https://obofoundry.org/ontologies/{prefix})"
58+
if links
59+
else prefix
60+
)
61+
for prefix in prefixes
62+
),
63+
)
64+
for k, prefixes in r.items()
65+
],
66+
tablefmt="github",
67+
headers=["key", "count", "ontologies"],
68+
)
6669
)
67-
)
70+
else:
71+
print(f"No fields used less than {max_cutoff} times!")
6872

6973
with SCHEMA_PATH.open() as file:
7074
schema = json.load(file)
@@ -73,8 +77,11 @@ def _check_schema(max_cutoff: int = 3, links: bool = True):
7377
for prop in schema["properties"]
7478
if prop not in property_usage and prop not in SKIP_KEYS
7579
}
76-
print("Unused properties:")
77-
print(*sorted(unused), sep="\n")
80+
if unused:
81+
print("Unused properties:")
82+
print(*sorted(unused), sep="\n")
83+
else:
84+
print("No unused properties!")
7885

7986

8087
if __name__ == "__main__":

0 commit comments

Comments
 (0)