From 1e0a81488eba1ce691ac551f144874e1ebfbfd7b Mon Sep 17 00:00:00 2001 From: Liam Mulhall Date: Mon, 4 Nov 2024 15:40:12 -0700 Subject: [PATCH] Add templates --- pyproject.toml | 3 +- src/ga4gh/gks/metaschema/scripts/y2t.py | 29 ++++++++++++------- src/templates/maturity | 4 +++ tests/data/vrs/def/Adjacency.rst | 6 ++-- tests/data/vrs/def/Allele.rst | 6 ++-- tests/data/vrs/def/CopyNumberChange.rst | 6 ++-- tests/data/vrs/def/CopyNumberCount.rst | 6 ++-- tests/data/vrs/def/Expression.rst | 6 ++-- tests/data/vrs/def/Haplotype.rst | 6 ++-- tests/data/vrs/def/LengthExpression.rst | 6 ++-- .../vrs/def/LiteralSequenceExpression.rst | 6 ++-- tests/data/vrs/def/Range.rst | 6 ++-- .../vrs/def/ReferenceLengthExpression.rst | 6 ++-- tests/data/vrs/def/Residue.rst | 6 ++-- tests/data/vrs/def/SequenceLocation.rst | 6 ++-- tests/data/vrs/def/SequenceReference.rst | 6 ++-- tests/data/vrs/def/SequenceString.rst | 6 ++-- 17 files changed, 52 insertions(+), 68 deletions(-) create mode 100644 src/templates/maturity diff --git a/pyproject.toml b/pyproject.toml index 4d91e49..b95f802 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,7 +29,8 @@ keywords = [ ] requires-python = ">=3.12" dependencies = [ - "pyyaml" + "pyyaml", + "Jinja2" ] dynamic = ["version"] diff --git a/src/ga4gh/gks/metaschema/scripts/y2t.py b/src/ga4gh/gks/metaschema/scripts/y2t.py index 8f7369f..c370920 100755 --- a/src/ga4gh/gks/metaschema/scripts/y2t.py +++ b/src/ga4gh/gks/metaschema/scripts/y2t.py @@ -4,9 +4,16 @@ import os import pathlib import sys +from pathlib import Path + +from jinja2 import Environment, FileSystemLoader from ga4gh.gks.metaschema.tools.source_proc import YamlSchemaProcessor +templates_dir = Path(__file__).resolve().parents[4] / "templates" +env = Environment(loader=FileSystemLoader(templates_dir)) + + def resolve_type(class_property_definition: dict) -> str: """Resolves a class definition to a concrete type. @@ -87,22 +94,22 @@ def main(proc_schema: YamlSchemaProcessor) -> None: with open(proc_schema.def_fp / (class_name + ".rst"), "w") as f: maturity = class_definition.get("maturity", "") if maturity == "draft": + template = env.get_template("maturity") print( - """ -.. warning:: This data class is at a **draft** maturity level and may change - significantly in future releases. Maturity levels are described in - the :ref:`maturity-model`. - - """, + template.render( + info="warning", + maturity_level="draft", + modifier="significantly" + ), file=f, ) elif maturity == "trial use": print( - """ -.. note:: This data class is at a **trial use** maturity level and may change - in future releases. Maturity levels are described in the :ref:`maturity-model`. - - """, + template.render( + info="note", + maturity_level="trial use", + modifier="" + ), file=f, ) print("**Computational Definition**\n", file=f) diff --git a/src/templates/maturity b/src/templates/maturity new file mode 100644 index 0000000..fcb5f32 --- /dev/null +++ b/src/templates/maturity @@ -0,0 +1,4 @@ +.. {{ info }}:: This data class is at a **{{ maturity_level }}** maturity level and may change + {{ modifier }} in future releases. Maturity levels are described in + the :ref:`maturity-model`. + diff --git a/tests/data/vrs/def/Adjacency.rst b/tests/data/vrs/def/Adjacency.rst index ddfc877..ce2cfcc 100644 --- a/tests/data/vrs/def/Adjacency.rst +++ b/tests/data/vrs/def/Adjacency.rst @@ -1,9 +1,7 @@ - .. warning:: This data class is at a **draft** maturity level and may change - significantly in future releases. Maturity levels are described in + significantly in future releases. Maturity levels are described in the :ref:`maturity-model`. - - + **Computational Definition** The `Adjacency` class can represent either the termination of a sequence or the adjoining of the end of a sequence with the beginning of an adjacent sequence, potentially with an intervening linker sequence. diff --git a/tests/data/vrs/def/Allele.rst b/tests/data/vrs/def/Allele.rst index 3e5fd8c..cf75fdc 100644 --- a/tests/data/vrs/def/Allele.rst +++ b/tests/data/vrs/def/Allele.rst @@ -1,9 +1,7 @@ - .. warning:: This data class is at a **draft** maturity level and may change - significantly in future releases. Maturity levels are described in + significantly in future releases. Maturity levels are described in the :ref:`maturity-model`. - - + **Computational Definition** The state of a molecule at a :ref:`Location`. diff --git a/tests/data/vrs/def/CopyNumberChange.rst b/tests/data/vrs/def/CopyNumberChange.rst index 0441869..4300a35 100644 --- a/tests/data/vrs/def/CopyNumberChange.rst +++ b/tests/data/vrs/def/CopyNumberChange.rst @@ -1,9 +1,7 @@ - .. warning:: This data class is at a **draft** maturity level and may change - significantly in future releases. Maturity levels are described in + significantly in future releases. Maturity levels are described in the :ref:`maturity-model`. - - + **Computational Definition** An assessment of the copy number of a :ref:`Location` or a :ref:`Gene` within a system (e.g. genome, cell, etc.) relative to a baseline ploidy. diff --git a/tests/data/vrs/def/CopyNumberCount.rst b/tests/data/vrs/def/CopyNumberCount.rst index 869598e..dea79bd 100644 --- a/tests/data/vrs/def/CopyNumberCount.rst +++ b/tests/data/vrs/def/CopyNumberCount.rst @@ -1,9 +1,7 @@ - .. warning:: This data class is at a **draft** maturity level and may change - significantly in future releases. Maturity levels are described in + significantly in future releases. Maturity levels are described in the :ref:`maturity-model`. - - + **Computational Definition** The absolute count of discrete copies of a :ref:`Location` or :ref:`Gene`, within a system (e.g. genome, cell, etc.). diff --git a/tests/data/vrs/def/Expression.rst b/tests/data/vrs/def/Expression.rst index 3add21a..ed3736b 100644 --- a/tests/data/vrs/def/Expression.rst +++ b/tests/data/vrs/def/Expression.rst @@ -1,9 +1,7 @@ - .. warning:: This data class is at a **draft** maturity level and may change - significantly in future releases. Maturity levels are described in + significantly in future releases. Maturity levels are described in the :ref:`maturity-model`. - - + **Computational Definition** Representation of a variation by a specified nomenclature or syntax for a Variation object. Common examples of expressions for the description of molecular variation include the HGVS and ISCN nomenclatures. diff --git a/tests/data/vrs/def/Haplotype.rst b/tests/data/vrs/def/Haplotype.rst index 523880a..784cad5 100644 --- a/tests/data/vrs/def/Haplotype.rst +++ b/tests/data/vrs/def/Haplotype.rst @@ -1,9 +1,7 @@ - .. warning:: This data class is at a **draft** maturity level and may change - significantly in future releases. Maturity levels are described in + significantly in future releases. Maturity levels are described in the :ref:`maturity-model`. - - + **Computational Definition** An ordered set of co-occurring :ref:`variants ` on the same molecule. diff --git a/tests/data/vrs/def/LengthExpression.rst b/tests/data/vrs/def/LengthExpression.rst index 8a4c5d2..7cc17c3 100644 --- a/tests/data/vrs/def/LengthExpression.rst +++ b/tests/data/vrs/def/LengthExpression.rst @@ -1,9 +1,7 @@ - .. warning:: This data class is at a **draft** maturity level and may change - significantly in future releases. Maturity levels are described in + significantly in future releases. Maturity levels are described in the :ref:`maturity-model`. - - + **Computational Definition** A sequence expressed only by its length. diff --git a/tests/data/vrs/def/LiteralSequenceExpression.rst b/tests/data/vrs/def/LiteralSequenceExpression.rst index 34acf08..bab2e8c 100644 --- a/tests/data/vrs/def/LiteralSequenceExpression.rst +++ b/tests/data/vrs/def/LiteralSequenceExpression.rst @@ -1,9 +1,7 @@ - .. warning:: This data class is at a **draft** maturity level and may change - significantly in future releases. Maturity levels are described in + significantly in future releases. Maturity levels are described in the :ref:`maturity-model`. - - + **Computational Definition** An explicit expression of a Sequence. diff --git a/tests/data/vrs/def/Range.rst b/tests/data/vrs/def/Range.rst index c2f1077..ef9a1e4 100644 --- a/tests/data/vrs/def/Range.rst +++ b/tests/data/vrs/def/Range.rst @@ -1,9 +1,7 @@ - .. warning:: This data class is at a **draft** maturity level and may change - significantly in future releases. Maturity levels are described in + significantly in future releases. Maturity levels are described in the :ref:`maturity-model`. - - + **Computational Definition** An inclusive range of values bounded by one or more integers. diff --git a/tests/data/vrs/def/ReferenceLengthExpression.rst b/tests/data/vrs/def/ReferenceLengthExpression.rst index dbcf89d..9ee644c 100644 --- a/tests/data/vrs/def/ReferenceLengthExpression.rst +++ b/tests/data/vrs/def/ReferenceLengthExpression.rst @@ -1,9 +1,7 @@ - .. warning:: This data class is at a **draft** maturity level and may change - significantly in future releases. Maturity levels are described in + significantly in future releases. Maturity levels are described in the :ref:`maturity-model`. - - + **Computational Definition** An expression of a length of a sequence from a repeating reference. diff --git a/tests/data/vrs/def/Residue.rst b/tests/data/vrs/def/Residue.rst index 1311832..e65a777 100644 --- a/tests/data/vrs/def/Residue.rst +++ b/tests/data/vrs/def/Residue.rst @@ -1,9 +1,7 @@ - .. warning:: This data class is at a **draft** maturity level and may change - significantly in future releases. Maturity levels are described in + significantly in future releases. Maturity levels are described in the :ref:`maturity-model`. - - + **Computational Definition** A character representing a specific residue (i.e., molecular species) or groupings of these ("ambiguity codes"), using `one-letter IUPAC abbreviations `_ for nucleic acids and amino acids. diff --git a/tests/data/vrs/def/SequenceLocation.rst b/tests/data/vrs/def/SequenceLocation.rst index 82501a7..9722b72 100644 --- a/tests/data/vrs/def/SequenceLocation.rst +++ b/tests/data/vrs/def/SequenceLocation.rst @@ -1,9 +1,7 @@ - .. warning:: This data class is at a **draft** maturity level and may change - significantly in future releases. Maturity levels are described in + significantly in future releases. Maturity levels are described in the :ref:`maturity-model`. - - + **Computational Definition** A :ref:`Location` defined by an interval on a referenced :ref:`Sequence`. diff --git a/tests/data/vrs/def/SequenceReference.rst b/tests/data/vrs/def/SequenceReference.rst index 8dd2e2d..b0f8fcb 100644 --- a/tests/data/vrs/def/SequenceReference.rst +++ b/tests/data/vrs/def/SequenceReference.rst @@ -1,9 +1,7 @@ - .. warning:: This data class is at a **draft** maturity level and may change - significantly in future releases. Maturity levels are described in + significantly in future releases. Maturity levels are described in the :ref:`maturity-model`. - - + **Computational Definition** A sequence of nucleic or amino acid character codes. diff --git a/tests/data/vrs/def/SequenceString.rst b/tests/data/vrs/def/SequenceString.rst index 00e4356..c4e0a9f 100644 --- a/tests/data/vrs/def/SequenceString.rst +++ b/tests/data/vrs/def/SequenceString.rst @@ -1,9 +1,7 @@ - .. warning:: This data class is at a **draft** maturity level and may change - significantly in future releases. Maturity levels are described in + significantly in future releases. Maturity levels are described in the :ref:`maturity-model`. - - + **Computational Definition** A character string of :ref:`Residues ` that represents a biological sequence using the conventional sequence order (5’-to-3’ for nucleic acid sequences, and amino-to-carboxyl for amino acid sequences). IUPAC ambiguity codes are permitted in Sequence Strings.