Skip to content

Commit

Permalink
Updates for pydantic v2 (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
dougiesquire authored Jul 7, 2023
1 parent 7b25379 commit e1f97a2
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 26 deletions.
5 changes: 2 additions & 3 deletions ci/environment-docs.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: ecgtools-dev
name: ecgtools-doc
channels:
- conda-forge
- nodefaults
Expand All @@ -12,14 +12,13 @@ dependencies:
- myst-nb
- netcdf4
- pip
- pydantic<2.0 # Will remove in upcoming PR
- pydantic>=2.0
- s3fs
- sphinx-copybutton
- sphinx-inline-tabs
- xarray
- pip:
- sphinxext-opengraph
- autodoc_pydantic
- -r ../requirements.txt
- git+https://github.com/intake/intake-esm
- -e ..
2 changes: 1 addition & 1 deletion ci/environment-upstream-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies:
- numpydoc
- pip
- pre-commit
- pydantic<2.0 # Will remove in upcoming PR
- pydantic>=2.0
- pytest
- pytest-cov
- pytest-sugar
Expand Down
2 changes: 1 addition & 1 deletion ci/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies:
- netcdf4
- pip
- pre-commit
- pydantic<2.0 # Will remove in upcoming PR
- pydantic>=2.0
- pytest
- pytest-cov
- pytest-sugar
Expand Down
5 changes: 0 additions & 5 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
'myst_nb',
'sphinxext.opengraph',
'sphinx_copybutton',
'sphinxcontrib.autodoc_pydantic',
'sphinx_inline_tabs',
]

Expand All @@ -31,10 +30,6 @@
copybutton_prompt_text = r'>>> |\.\.\. |\$ |In \[\d*\]: | {2,5}\.\.\.: | {5,8}: '
copybutton_prompt_is_regexp = True


autodoc_pydantic_model_show_json = True
autodoc_pydantic_settings_show_json = False

jupyter_execute_notebooks = 'off'
execution_timeout = 600
execution_allow_errors = True
Expand Down
32 changes: 17 additions & 15 deletions ecgtools/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ class Builder:
"""

paths: typing.List[str]
storage_options: typing.Dict[typing.Any, typing.Any] = None
storage_options: typing.Optional[typing.Dict[typing.Any, typing.Any]] = None
depth: int = 0
exclude_patterns: typing.List[str] = None
include_patterns: typing.List[str] = None
joblib_parallel_kwargs: typing.Dict[str, typing.Any] = None
exclude_patterns: typing.Optional[typing.List[str]] = None
include_patterns: typing.Optional[typing.List[str]] = None
joblib_parallel_kwargs: typing.Optional[typing.Dict[str, typing.Any]] = None

def __post_init_post_parse__(self):
def __post_init__(self):
self.storage_options = self.storage_options or {}
self.joblib_parallel_kwargs = self.joblib_parallel_kwargs or {}
self.exclude_patterns = self.exclude_patterns or []
Expand Down Expand Up @@ -146,7 +146,9 @@ def get_assets(self):
return self

@pydantic.validate_arguments
def parse(self, *, parsing_func: typing.Callable, parsing_func_kwargs: dict = None):
def parse(
self, *, parsing_func: typing.Callable, parsing_func_kwargs: typing.Optional[dict] = None
):
if not self.assets:
raise ValueError('asset list provided is None. Please run `.get_assets()` first')

Expand Down Expand Up @@ -177,9 +179,9 @@ def build(
self,
*,
parsing_func: typing.Callable,
parsing_func_kwargs: dict = None,
postprocess_func: typing.Callable = None,
postprocess_func_kwargs: dict = None,
parsing_func_kwargs: typing.Optional[dict] = None,
postprocess_func: typing.Optional[typing.Callable] = None,
postprocess_func_kwargs: typing.Optional[dict] = None,
):
"""Builds a catalog from a list of netCDF files or zarr stores.
Expand Down Expand Up @@ -218,14 +220,14 @@ def save(
path_column_name: str,
variable_column_name: str,
data_format: DataFormat,
groupby_attrs: typing.List[str] = None,
aggregations: typing.List[Aggregation] = None,
groupby_attrs: typing.Optional[typing.List[str]] = None,
aggregations: typing.Optional[typing.List[Aggregation]] = None,
esmcat_version: str = '0.0.1',
description: str = None,
directory: str = None,
description: typing.Optional[str] = None,
directory: typing.Optional[str] = None,
catalog_type: str = 'file',
to_csv_kwargs: dict = None,
json_dump_kwargs: dict = None,
to_csv_kwargs: typing.Optional[dict] = None,
json_dump_kwargs: typing.Optional[dict] = None,
):
"""Persist catalog contents to files.
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ joblib
netCDF4
xarray
pyyaml
pydantic
pydantic>=2.0
pandas
fsspec
intake-esm

0 comments on commit e1f97a2

Please sign in to comment.