Skip to content

Commit

Permalink
Merge branch 'dev-hotfix-version-issue' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasprobst committed Oct 28, 2024
2 parents a72496c + 5b74fba commit 5932862
Show file tree
Hide file tree
Showing 13 changed files with 138 additions and 107 deletions.
106 changes: 55 additions & 51 deletions docs/colab/quickstart.ipynb

Large diffs are not rendered by default.

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
17 changes: 9 additions & 8 deletions h5rdmtoolbox/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,15 @@ def clear_cache(self, delta_days: int, utime: bool = False):
return
if self.user_dirs['cache'].exists():
for f in self.user_dirs['cache'].iterdir():
# get the file creation time
if utime:
fct = f.stat().st_atime
else:
fct = f.stat().st_ctime
dt = _now - fct
if dt > delta_days * 86400:
f.unlink()
if f.is_file():
# get the file creation time
if utime:
fct = f.stat().st_atime
else:
fct = f.stat().st_ctime
dt = _now - fct
if dt > delta_days * 86400:
f.unlink()

def reset(self):
"""Deletes all user data"""
Expand Down
8 changes: 4 additions & 4 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-image>=0.21.0
scikit-learn
scipy
scipy>=1.10.1
18 changes: 9 additions & 9 deletions requirements-doc.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
-e .
-r requirements.txt
jupyterlab
sphinx >= 4.5.0
sphinx_book_theme
sphinx-copybutton
sphinx-design
myst-nb
sphinxcontrib-bibtex
kglab
scikit-image
Sphinx==4.5.0
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

scikit-image==0.24.0
scikit-learn
12 changes: 6 additions & 6 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
ontolutils >= 0.5.0
43 changes: 21 additions & 22 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ install_requires =
IPython >= 7.34.0 # colab wants 7.34.0
pyyaml > 6.0 # 5.4 does not work with python 3.11!
xarray >= 2022.3.0
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==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
python-forge == 18.6.0
requests
pydantic >= 2.3.0, < 2.8.0
rdflib<=7.0.0
packaging>=24.1
ontolutils>=0.5.0
python-forge==18.6.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 All @@ -56,32 +56,31 @@ snt =
gui =
PyQt5==5.15.10
test =
pytest >= 7.1.2
pytest-cov
pytest>=8.3.3
pytest-cov>=5.0.0
pylint
mongomock == 4.1.2
mongomock==4.1.2
xmltodict<=0.13.0
scipy # provides netcdf4
scipy>=1.10.1 # provides netcdf4
%(csv)s
%(snt)s
%(database)s
docs =
; kglab
%(csv)s
%(snt)s
%(database)s
%(test)s
jupyterlab
Sphinx >= 3,<5
sphinx_book_theme == 0.3.3
sphinx-copybutton
scikit-image
; jupyterlab>4.0.0
Sphinx==4.5.0
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
scikit-image>=0.21.0
scikit-learn
; nbsphinx
sphinx-design
simplejson
myst-nb
sphinxcontrib-bibtex
; simplejson

complete =
%(layout_validation)s
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 @@ -509,7 +509,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 5932862

Please sign in to comment.