Skip to content

Commit

Permalink
fixing the version issue with pydantic
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasprobst committed Oct 28, 2024
1 parent a278614 commit 52483e5
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 35 deletions.
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"license": "https://spdx.org/licenses/MIT",
"codeRepository": "git+https://github.com/matthiasprobst/h5RDMtoolbox.git",
"name": "h5RDMtoolbox",
"version": "1.4.1",
"version": "1.5.0",
"description": "Supporting a FAIR Research Data lifecycle using Python and HDF5.",
"applicationCategory": "Engineering",
"programmingLanguage": [
Expand Down
2 changes: 1 addition & 1 deletion docs/colab/quickstart.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"outputs": [],
"source": [
"# !pip install h5rdmtoolbox==1.4.1"
"# !pip install h5rdmtoolbox==1.5.0"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion h5rdmtoolbox/convention/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def get_dict(self):
def write_lines(self, file):
"""Write validator lines to file"""
file.writelines(f'\n\nimport re\n\n')
file.writelines(f'\ndef {self.name}(value, parent=None, attrs=None):')
file.writelines(f'\ndef {self.name}(value, handler):')
file.writelines(f"\n pattern = re.compile(r'{self.re_pattern}')")
file.writelines("\n if not pattern.match(value):")
file.writelines("\n raise ValueError('Invalid format for pattern')")
Expand Down
2 changes: 1 addition & 1 deletion h5rdmtoolbox/data/tutorial_convention.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ long_name:
target_method: create_dataset
validator: $regex(^[a-zA-Z].*$)
alternative_standard_attribute: standard_name
description: An comprehensive description of the dataset. If not set, the standard_name attribute must be given.
description: A comprehensive description of the dataset. If not set, the standard_name attribute must be given.

comment-file:
target_method: __init__
Expand Down
10 changes: 10 additions & 0 deletions h5rdmtoolbox/database/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ def rdf_find(source, *,
----------
source: Union[str, pathlib.Path, h5tbx.Group]
Filename or hdf group
rdf_subject: Optional[str]
The RDF subject to search for if provided
rdf_type: Optional[str]
The RDF type to search for if provided
rdf_predicate: Optional[str]
The RDF predicate to search for if provided
rdf_object: Optional[str]
The RDF object to search for if provided
recursive: bool=True
If True, search recursively. If False, only search the current group
"""
if isinstance(source, (str, pathlib.Path)):
return FileDB(source).rdf_find(rdf_subject=rdf_subject,
Expand Down
6 changes: 3 additions & 3 deletions h5rdmtoolbox/database/hdfdb/filedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, filename: Union[str, pathlib.Path]):
self.rdf_find = self._instance_rdf_find

@staticmethod
def find_one(filename: Union[str, pathlib.Path], *args, **kwargs) -> lazy.LHDFObject:
def find_one(filename: Union[str, pathlib.Path], *args, **kwargs) -> lazy.LazyObject:
"""Please refer to the docstring of the find_one method of the ObjDB class"""
with h5py.File(str(filename), 'r') as h5:
return ObjDB(h5).find_one(*args, **kwargs)
Expand All @@ -45,7 +45,7 @@ def _instance_find_one(self, *args, **kwargs):
return ObjDB(h5).find_one(*args, **kwargs)

@staticmethod
def find(file_or_filename, *args, **kwargs) -> Generator[lazy.LHDFObject, None, None]:
def find(file_or_filename, *args, **kwargs) -> List[lazy.LazyObject]:
"""Please refer to the docstring of the find method of the ObjDB class"""
if isinstance(file_or_filename, (h5py.Group, h5py.Dataset)):
return list(ObjDB(file_or_filename).find(*args, **kwargs))
Expand Down Expand Up @@ -104,7 +104,7 @@ def insert_filename(self, filename: Union[str, pathlib.Path]):
self.filenames.append(pathlib.Path(filename))
self.filenames = list(set(self.filenames))

def find_one(self, *args, **kwargs) -> lazy.LHDFObject:
def find_one(self, *args, **kwargs) -> lazy.LazyObject:
"""Call find_one on all the files registered. If more than one file
contains the object, the first one is returned. If you want to find one per file,
call find_one_per_file instead."""
Expand Down
10 changes: 5 additions & 5 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
-e .
-r requirements.txt
pytest>=7.1.2
pytest-cov
pytest>=8.3.3
pytest-cov>=5.0.0
mongomock == 4.1.2
scikit-image
scikit-learn
scipy
scikit-image>=1.3.2
scikit-learn>=0.21.0
scipy>=1.10.1
15 changes: 7 additions & 8 deletions requirements-doc.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
-e .
-r requirements.txt
jupyterlab
sphinx >= 4.5.0
sphinx_book_theme
sphinx-copybutton
sphinx-design
myst-nb
sphinxcontrib-bibtex
kglab
scikit-image
sphinx_book_theme>=0.3.3
sphinx-copybutton>=0.5.2
sphinx-design>=0.4.1
myst-nb>=0.17.2
sphinxcontrib-bibtex>=2.6.3
kglab>=2.6.3
scikit-image>=1.3.2
10 changes: 5 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ xarray>=2022.3.0
pint==0.21.1
pint_xarray>=0.2.1
regex>=2020.7.9
packaging
packaging>=24.1
python-forge==18.6.0
requests
rdflib<=7.0.0
requests>=2.32.3
rdflib>=7.0.0
# database:
pymongo>=4.2.0
pymongo>=4.2.0,<4.9.0
# csv
pandas>=1.4.3
# snt
xmltodict<=0.13.0
tabulate>=0.8.10,<=0.9.0
python-gitlab
pypandoc>=1.11
pydantic >= 2.3.0, < 2.8.0
pydantic>=2.8.2
# other:
ontolutils >= 0.2.23
16 changes: 8 additions & 8 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = h5rdmtoolbox
version = 1.4.1
version = 1.5.0
author = Matthias Probst
author_email = matthias.probst@kit.edu
description = Supporting a FAIR Research Data lifecycle using Python and HDF5.
Expand Down Expand Up @@ -34,16 +34,16 @@ install_requires =
pint == 0.21.1 # pint >= 0.19.2<0.22.0 Note: 0.22.0 shows bad str-output for quantities with format Lx~
pint_xarray >= 0.2.1
regex>=2020.7.9
packaging
ontolutils>=0.2.20
packaging>=24.1
ontolutils>=0.5.0
python-forge == 18.6.0
requests
pydantic >= 2.3.0, < 2.8.0
rdflib<=7.0.0
requests>=2.32.3
pydantic>=2.8.2
rdflib>=7.0.0

[options.extras_require]
database=
pymongo>=4.2.0
pymongo>=4.2.0,<4.9.0
layout_validation=
tabulate>=0.8.10,<=0.9.0
csv =
Expand Down Expand Up @@ -71,7 +71,7 @@ docs =
%(snt)s
%(database)s
%(test)s
jupyterlab
; jupyterlab>4.0.0
Sphinx >= 3,<5
sphinx_book_theme == 0.3.3
sphinx-copybutton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def test_to_html(self):

def test_from_zenodo(self):
if self.connected:
snt = StandardNameTable.from_zenodo(siurce=TutorialSNTZenodoRecordID)
snt = StandardNameTable.from_zenodo(source=TutorialSNTZenodoRecordID)
self.assertIsInstance(snt, StandardNameTable)
filename = h5tbx.UserDir['standard_name_tables'] / f'{TutorialSNTZenodoRecordID}.yaml'
self.assertTrue(filename.exists())
Expand Down
2 changes: 1 addition & 1 deletion tests/conventions/test_conventions.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ def test_from_zenodo(self):
_ddir = h5tbx.UserDir['convention'] / 'h5rdmtoolbox_tutorial_convention'
if _ddir.exists():
shutil.rmtree(_ddir)
h5tbx.convention.from_zenodo(doi_or_recid=TutorialConventionZenodoRecordID)
h5tbx.convention.from_zenodo(doi_or_recid=TutorialConventionZenodoRecordID, force_download=True)
# h5tbx.convention.from_yaml('test_convention.yaml')
h5tbx.use('h5rdmtoolbox-tutorial-convention')

Expand Down
17 changes: 17 additions & 0 deletions tests/wrapper/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,23 @@ def test_reopen_file(self):
self.assertTrue('data_type' in h5.attrs.raw)
self.assertTrue('contact' in h5.attrs.raw)

def test_grrrr(self):
from pydantic.functional_validators import WrapValidator
from typing_extensions import Annotated
from pydantic import BaseModel
import re
def regex_0(value, handler):
pattern = re.compile(r'^[a-zA-Z].*$')
if not pattern.match(value):
raise ValueError('Invalid format for pattern')
return value

regex_0 = Annotated[str, WrapValidator(regex_0)]

class long_name(BaseModel):
"""A comprehensive description of the dataset. If not set, the standard_name attribute must be given."""
long_name: regex_0

def test_dumps(self):
with h5tbx.File() as h5:
h5.dumps()
Expand Down

0 comments on commit 52483e5

Please sign in to comment.