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 52 53 54 55 56 57 58 59 60 61 62 63 64
|
"""
Script that creates initial astropy manifest from the schemas
in the resources directory. This file can be removed once
the format of the manifest files has been finalized.
"""
import argparse
from pathlib import Path
import yaml
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("schemas_path")
parser.add_argument("output_path")
return parser.parse_args()
class MultilineString(str):
pass
def represent_multiline_string(dumper, data):
return dumper.represent_scalar("tag:yaml.org,2002:str", data, style="|")
if __name__ == "__main__":
yaml.add_representer(MultilineString, represent_multiline_string)
args = parse_args()
manifest = {}
manifest["id"] = "http://astropy.org/asdf/extensions/astropy/manifests/astropy-1.0"
manifest["extension_uri"] = "http://astropy.org/asdf/extensions/astropy-1.0"
manifest["title"] = "Astropy extension 1.0"
manifest["description"] = MultilineString(
"A set of tags for serializing astropy objects. This does not include most\n"
"model classes, which are handled by an implementation of the ASDF\n"
"transform extension."
)
manifest["asdf_standard_requirement"] = {
"gte": "1.1.0",
}
manifest["tags"] = []
for schema_path in Path(args.schemas_path).glob("**/*.yaml"):
schema = yaml.safe_load(schema_path.read_bytes())
tag_def = {
"tag_uri": schema["id"].replace("http://astropy.org/schemas/astropy/", "tag:astropy.org:astropy/"),
"schema_uri": schema["id"],
"title": schema["title"].strip(),
}
if "tag" in schema:
assert tag_def["tag_uri"] == schema["tag"]
if "description" in schema:
tag_def["description"] = MultilineString(schema["description"].strip())
manifest["tags"].append(tag_def)
with open(args.output_path, "w") as f:
yaml.dump(manifest, f, sort_keys=False)
|