… load a convention from a local YAML file?

… load a convention from a local YAML file?#

Yes you can. To demonstrate this, let’s take a convention file, which comes with the h5RDMtoolbox

import h5rdmtoolbox as h5tbx
from h5rdmtoolbox import tutorial
yaml_filename = tutorial.get_convention_yaml_filename()

cv = h5tbx.convention.Convention.from_yaml(yaml_filename)
h5tbx.use(cv)
using("h5rdmtoolbox-tutorial-convention")
with h5tbx.File(data_type='experimental', contact=h5tbx.__author_orcid__) as h5:
    h5.dump()
---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
Cell In[3], line 1
----> 1 with h5tbx.File(data_type='experimental', contact=h5tbx.__author_orcid__) as h5:
      2     h5.dump()

File ~/checkouts/readthedocs.org/user_builds/h5rdmtoolbox/envs/v2.6.2/lib/python3.10/site-packages/forge/_revision.py:328, in Revision.__call__.<locals>.inner(*args, **kwargs)
    324 @functools.wraps(callable)  # type: ignore
    325 def inner(*args, **kwargs):
    326     # pylint: disable=E1102, not-callable
    327     mapped = inner.__mapper__(*args, **kwargs)
--> 328     return callable(*mapped.args, **mapped.kwargs)

File ~/checkouts/readthedocs.org/user_builds/h5rdmtoolbox/envs/v2.6.2/lib/python3.10/site-packages/h5rdmtoolbox/wrapper/core.py:2280, in File.__init__(self, name, mode, attrs, **kwargs)
   2278         utils.create_h5tbx_version_grp(self)
   2279 for k, v in attrs.items():
-> 2280     self.attrs[k] = v

File h5py/_objects.pyx:54, in h5py._objects.with_phil.wrapper()

File h5py/_objects.pyx:55, in h5py._objects.with_phil.wrapper()

File ~/checkouts/readthedocs.org/user_builds/h5rdmtoolbox/envs/v2.6.2/lib/python3.10/site-packages/h5rdmtoolbox/wrapper/h5attr.py:387, in WrapperAttributeManager.__setitem__(self, name, value, attrs)
    385         if isinstance(value, consts.DefaultValue):
    386             value = value.value
--> 387         return sattr.set(
    388             parent=parent,
    389             value=value,
    390             attrs=attrs
    391         )
    393 utils.create_special_attribute(self, name, value)

File ~/checkouts/readthedocs.org/user_builds/h5rdmtoolbox/envs/v2.6.2/lib/python3.10/site-packages/h5rdmtoolbox/convention/standard_attributes.py:236, in StandardAttribute.set(self, parent, value, attrs)
    234 key0 = model_fields[0]  # ==self.name!
    235 try:
--> 236     _validated_value = self.validator.model_validate({key0: value},
    237                                                      context={'parent': parent, 'attrs': attrs})
    238 except pydantic.ValidationError as err:
    239     raise errors.StandardAttributeError(
    240         f'Validation of "{value}" for standard attribute "{self.name}" failed.\n'
    241         f'Expected fields: {self.validator.model_fields}\nPydantic error: {err}')

    [... skipping hidden 1 frame]

File ~/.local/share/h5rdmtoolbox/2.6.2/convention/h5rdmtoolbox_tutorial_convention/h5rdmtoolbox_tutorial_convention.py:27, in __validate_standard_name_table(value, handler, info)
     24 def __snt_h5attr_repr__(self):
     25     return str(HttpUrl(value))
---> 27 _snt_filename = dcat.Distribution(downloadURL=HttpUrl(value)).download()
     28 _snt = parse_table(source=_snt_filename)
     29 _snt.__h5attr_repr__ = types.MethodType(__snt_h5attr_repr__, _snt)

File ~/checkouts/readthedocs.org/user_builds/h5rdmtoolbox/envs/v2.6.2/lib/python3.10/site-packages/ontolutils/ex/dcat/resource.py:342, in Distribution.download(self, dest_filename, target_folder, overwrite_existing, **kwargs)
    339 if dest_filename.exists():
    340     return dest_filename
--> 342 return download_file(self.download_URL,
    343                      dest_filename,
    344                      exist_ok=overwrite_existing,
    345                      **kwargs)

File ~/checkouts/readthedocs.org/user_builds/h5rdmtoolbox/envs/v2.6.2/lib/python3.10/site-packages/ontolutils/classes/utils.py:148, in download_file(url, dest_filename, known_hash, exist_ok, **kwargs)
    146 # response = requests.get(url, stream=True, **kwargs)
    147 if not response.ok:
--> 148     response.raise_for_status()
    150 content = response.content
    152 # Calculate the hash of the downloaded content

File ~/checkouts/readthedocs.org/user_builds/h5rdmtoolbox/envs/v2.6.2/lib/python3.10/site-packages/requests/models.py:1026, in Response.raise_for_status(self)
   1021     http_error_msg = (
   1022         f"{self.status_code} Server Error: {reason} for url: {self.url}"
   1023     )
   1025 if http_error_msg:
-> 1026     raise HTTPError(http_error_msg, response=self)

HTTPError: 403 Client Error: Forbidden for url: https://zenodo.org/records/17331305/files/fan_standard_name_table.jsonld