Skip to content

Commit

Permalink
XML typography more homogeneous, parameter model_url of add_model made
Browse files Browse the repository at this point in the history
optional with mandatory keyword
  • Loading branch information
lmichel committed Dec 15, 2024
1 parent 3d9dec5 commit bff20a5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 38 deletions.
42 changes: 21 additions & 21 deletions pyvo/mivot/writer/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def __init__(self):
@property
def mivot_block(self):
"""
Getter for the MIVOT block.
Getter for the whole MIVOT block.
Returns
-------
Expand All @@ -89,12 +89,12 @@ def mivot_block(self):

def _get_report(self):
"""
Generates the REPORT component of the MIVOT block.
Generate the <REPORT> component of the MIVOT block.
Returns
-------
str
The REPORT block as a string, indicating the success or failure of the process.
The <REPORT> block as a string, indicating the success or failure of the process.
"""
if self._report_status:
return f'<REPORT status="OK">{self._report_message}</REPORT>'
Expand All @@ -103,12 +103,12 @@ def _get_report(self):

def _get_models(self):
"""
Generates the MODEL components of the MIVOT block.
Generate the <MODEL> components of the MIVOT block.
Returns
-------
str
The MODEL components as a formatted string.
The <MODEL> components as a formatted string.
"""
models_block = ""
for key, value in self._models.items():
Expand All @@ -121,12 +121,12 @@ def _get_models(self):

def _get_globals(self):
"""
Generates the GLOBALS component of the MIVOT block.
Generate the <GLOBALS> component of the MIVOT block.
Returns
-------
str
The GLOBALS block as a formatted string.
The <GLOBALS> block as a formatted string.
"""
globals_block = "<GLOBALS>\n"
for glob in self._globals:
Expand All @@ -137,12 +137,12 @@ def _get_globals(self):

def _get_templates(self):
"""
Generates the TEMPLATES component of the MIVOT block.
Generate the <TEMPLATES> component of the MIVOT block.
Returns
-------
str
The TEMPLATES block as a formatted string, or an empty string if no templates are defined.
The <TEMPLATES> block as a formatted string, or an empty string if no templates are defined.
"""
if not self._templates:
return ""
Expand All @@ -158,13 +158,13 @@ def _get_templates(self):

def build_mivot_block(self, *, templates_id=None):
"""
Builds a complete MIVOT block from the declared components and validates it
Build a complete MIVOT block from the declared components and validates it
against the MIVOT XML schema.
Parameters
----------
templates_id : str, optional
The ID to associate with the TEMPLATES block. Defaults to None.
The ID to associate with the <TEMPLATES> block. Defaults to None.
Raises
------
Expand All @@ -188,12 +188,12 @@ def build_mivot_block(self, *, templates_id=None):

def add_templates(self, templates_instance):
"""
Adds an <INSTANCE> block to the <TEMPLATES> block.
Add an <INSTANCE> element to the <TEMPLATES> block.
Parameters
----------
templates_instance : str or MivotInstance
The <INSTANCE> block to be added.
The <INSTANCE> element to be added.
Raises
------
Expand All @@ -211,7 +211,7 @@ def add_templates(self, templates_instance):

def add_globals(self, globals_instance):
"""
Adds an <INSTANCE> block to the <GLOBALS> block.
Add an <INSTANCE> block to the <GLOBALS> block.
Parameters
----------
Expand All @@ -232,22 +232,22 @@ def add_globals(self, globals_instance):
"Instance added to globals must be a string or MivotInstance."
)

def add_model(self, model_name, model_url):
def add_model(self, model_name, *, model_url=None):
"""
Adds a MODEL element to the MIVOT block.
Add a <MODEL> element to the MIVOT block.
Parameters
----------
model_name : str
The short name of the model.
model_url : str
model_url : str, optional
The URL of the VO-DML file associated with the model.
"""
self._models[model_name] = model_url

def set_report(self, status, message):
"""
Sets the REPORT element of the MIVOT block.
Set the <REPORT> element of the MIVOT block.
Parameters
----------
Expand All @@ -269,7 +269,7 @@ def set_report(self, status, message):

def check_xml(self):
"""
Validates the MIVOT block against the MIVOT XML schema v1.0.
Validate the MIVOT block against the MIVOT XML schema v1.0.
Raises
------
Expand All @@ -278,7 +278,7 @@ def check_xml(self):
Notes
-----
The schema is loaded from a local file to avoid dependency on a remote service.
The schema (mivot 1.0) is loaded from a local file to avoid dependency on a remote service.
"""
# put here just to improve the test coverage
root = etree.fromstring(self._mivot_block)
Expand All @@ -299,7 +299,7 @@ def check_xml(self):

def insert_into_votable(self, votable_file, override=False):
"""
Inserts the MIVOT block into a VOTable.
Insert the MIVOT block into a VOTable.
Parameters
----------
Expand Down
34 changes: 17 additions & 17 deletions pyvo/mivot/writer/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ def __init__(self, dmtype=None, *, dmrole=None, dmid=None):
Parameters
----------
dmtype : str
The dmtype of the INSTANCE (mandatory).
dmtype of the INSTANCE (mandatory)
dmrole : str, optional
The dmrole of the INSTANCE.
dmrole of the INSTANCE
dmid : str, optional
The dmid of the INSTANCE.
dmid of the INSTANCE
Raises
------
MappingError
If ``dmtype`` is not provided.
If ``dmtype`` is not provided
"""
if not dmtype:
raise MappingError("Cannot build an instance without dmtype")
Expand All @@ -65,20 +65,20 @@ def add_attribute(self, dmtype=None, dmrole=None, *, ref=None, value=None, unit=
Parameters
----------
dmtype : str
The dmtype of the ATTRIBUTE (mandatory).
dmtype of the ATTRIBUTE (mandatory)
dmrole : str
The dmrole of the ATTRIBUTE (mandatory).
dmrole of the ATTRIBUTE (mandatory)
ref : str, optional
ID of the column to set the attribute value.
ID of the column to set the attribute value
value : str, optional
Default value of the attribute.
Default value of the attribute
unit : str, optional
Unit of the attribute.
Unit of the attribute
Raises
------
MappingError
If ``dmtype`` or ``dmrole`` is not provided, or if both ``ref`` and ``value`` are not defined.
If ``dmtype`` or ``dmrole`` is not provided, or if both ``ref`` and ``value`` are not defined
"""
if not dmtype:
raise MappingError("Cannot add an attribute without dmtype")
Expand All @@ -104,14 +104,14 @@ def add_reference(self, dmrole=None, dmref=None):
Parameters
----------
dmrole : str
The dmrole of the REFERENCE (mandatory).
dmrole of the REFERENCE (mandatory)
dmref : str
The dmref of the REFERENCE (mandatory).
dmref of the REFERENCE (mandatory)
Raises
------
MappingError
If ``dmrole`` or ``dmref`` is not provided.
If ``dmrole`` or ``dmref`` is not provided
"""
if not dmref:
raise MappingError("Cannot add a reference without dmref")
Expand All @@ -128,25 +128,25 @@ def add_instance(self, mivot_instance):
Parameters
----------
mivot_instance : MivotInstance
The INSTANCE to be added.
INSTANCE to be added
Raises
------
MappingError
If ``mivot_instance`` is not of type ``MivotInstance``.
If ``mivot_instance`` is not of type ``MivotInstance``
"""
if not isinstance(mivot_instance, MivotInstance):
raise MappingError("Instance added must be of type MivotInstance")
self._content.append(mivot_instance.xml_string())

def xml_string(self):
"""
Build and serialize the INSTANCE element to a string.
Build and serialize the <INSTANCE> element as a string.
Returns
-------
str
The string representation of the INSTANCE element.
The string representation of the <INSTANCE> element
"""
xml_string = f'<INSTANCE dmtype="{self._dmtype}" '
if self._dmrole:
Expand Down

0 comments on commit bff20a5

Please sign in to comment.