Skip to content

Commit

Permalink
Add warning for cloudpathlib in python 3.12 (#58)
Browse files Browse the repository at this point in the history
Add warning with note to use Python 3.11 or earlier for remote storage
support given the current release of `cloudpathlib`.
  • Loading branch information
adrianeboyd authored Sep 11, 2023
1 parent dcff513 commit 2a571fe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 4 additions & 0 deletions weasel/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ def __getattribute__(self, code):
class Warnings(metaclass=ErrorsWithCodes):
# File system
W801 = "Could not clean/remove the temp directory at {dir}: {msg}."
W802 = (
"Remote storage is not yet supported for Python 3.12 with "
"cloudpathlib. Please use Python 3.11 or earlier for remote storage."
)


class Errors(metaclass=ErrorsWithCodes):
Expand Down
14 changes: 11 additions & 3 deletions weasel/util/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,17 @@ def ensure_path(path: Any) -> Any:


def ensure_pathy(path):
"""Temporary helper to prevent importing Pathy globally (which can cause
slow and annoying Google Cloud warning)."""
from cloudpathlib import AnyPath # noqa: F811
"""Temporary helper to prevent importing cloudpathlib globally (which was
originally added due to a slow and annoying Google Cloud warning with
Pathy)"""
try:
from cloudpathlib import AnyPath # noqa: F811
except ImportError as e:
import sys

if sys.version >= (3, 12):
warnings.warn(Warnings.W802)
raise e

return AnyPath(path)

Expand Down

0 comments on commit 2a571fe

Please sign in to comment.