Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pydantic compatibility warning #348

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# cloudpathlib Changelog

## v0.15.1 (2023-06-16)
- Warn if Pydantic >= 2.0.0 since we are not yet compatible.


## v0.15.0 (2023-06-16)

- Changed return type for `CloudPathMeta.__call__` to fix problems with pyright/pylance ([PR #330](https://github.com/drivendataorg/cloudpathlib/pull/330))
Expand Down
20 changes: 20 additions & 0 deletions cloudpathlib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
from warnings import warn

from .anypath import AnyPath
from .azure.azblobclient import AzureBlobClient
Expand Down Expand Up @@ -30,3 +31,22 @@
"S3Client",
"S3Path",
]


class PydanticVersionWarning(UserWarning):
message = (
"This version of cloudpathlib is only compatible with pydantic<2.0.0. "
"You can ignore this warning if none of your pydantic models are "
"annotated with cloudpathlib types."
)


try:
import pydantic
from packaging.version import parse

if parse(pydantic.__version__) >= parse("2.0.0"):
warn(PydanticVersionWarning(PydanticVersionWarning.message))

Check warning on line 49 in cloudpathlib/__init__.py

View check run for this annotation

Codecov / codecov/patch

cloudpathlib/__init__.py#L49

Added line #L49 was not covered by tests

except ImportError:
pass

Check warning on line 52 in cloudpathlib/__init__.py

View check run for this annotation

Codecov / codecov/patch

cloudpathlib/__init__.py#L51-L52

Added lines #L51 - L52 were not covered by tests
7 changes: 7 additions & 0 deletions docs/docs/integrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## Pydantic

!!! warning

As of version `0.15.1`, `cloudpathlib` is not compatible with
version `2.0.0` or greater of Pydantic. If you want to annotate
your pydantic models with cloudpathlib types, you need to use
`pydantic<2`.

`cloudpathlib` integrates with [Pydantic](https://pydantic-docs.helpmanual.io/)'s data validation. You can declare fields with cloud path classes, and Pydantic's validation mechanisms will run inputs through the cloud path's constructor.

```python
Expand Down
1 change: 1 addition & 0 deletions docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ nav:
- cloudpathlib.local: "api-reference/local.md"

markdown_extensions:
- admonition
- pymdownx.highlight
- pymdownx.superfences
- toc:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "flit_core.buildapi"

[project]
name = "cloudpathlib"
version = "0.15.0"
version = "0.15.1"
description = "pathlib-style classes for cloud storage services."
readme = "README.md"
authors = [{ name = "DrivenData", email = "info@drivendata.org" }]
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ nbautoexport
pandas
pillow
psutil
pydantic
pydantic<2
pytest
pytest-cases
pytest-cov
Expand Down
3 changes: 3 additions & 0 deletions tests/mock_clients/mock_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ def copy_from(self, CopySource=None, Metadata=None, MetadataDirective=None):

def download_file(self, to_path, Config=None, ExtraArgs=None):
to_path = Path(to_path)

to_path.parent.mkdir(parents=True, exist_ok=True)

to_path.write_bytes(self.path.read_bytes())
# track config to make sure it's used in tests
self.resource.download_config = Config
Expand Down