Skip to content

Commit

Permalink
Merge pull request #49 from trendelkampschroer/feature/fix_deprecatio…
Browse files Browse the repository at this point in the history
…n_warning

Feature/fix deprecation warning
  • Loading branch information
trendelkampschroer authored Jun 3, 2022
2 parents 58ac6de + 877940a commit 1b4754e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ Possible types of changes are:
- `Fixed` for any bug fixes
- `Security` in case of vulnerabilities

1.5.0 - 09.03.2022
------------------
Added
'''''
- missing ``preserve_time`` keyword arguments to the methods ``copy`` and ``move``

Fixed
'''''
- calls to deprecated methods ``getbasic``, ``setbytes``, and ``getbytes``.

1.4.5 - 25.03.2021
------------------

Expand Down
16 changes: 10 additions & 6 deletions fs_gcsfs/_gcsfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import os
import tempfile
import mimetypes
import warnings
from typing import Optional, List, Union, Tuple, Iterator, MutableMapping, Any

import google
Expand Down Expand Up @@ -404,7 +405,9 @@ def removedir(self, path: str) -> None:
def setinfo(self, path, info):
self.getinfo(path)

def copy(self, src_path: str, dst_path: str, overwrite: bool = False) -> None:
def copy(self, src_path: str, dst_path: str, overwrite: bool = False, preserve_time=False) -> None:
if preserve_time:
warnings.warn("`GCSFS` cannot preserve time on `copy` operations, ignoring `preserve_time=True`.")
if not overwrite and self.exists(dst_path):
raise errors.DestinationExists(dst_path)
_src_path = self.validatepath(src_path)
Expand All @@ -422,8 +425,8 @@ def copy(self, src_path: str, dst_path: str, overwrite: bool = False) -> None:
raise errors.ResourceNotFound(_src_key)
self.bucket.copy_blob(blob, self.bucket, new_name=_dst_key)

def move(self, src_path: str, dst_path: str, overwrite: bool = False) -> None:
self.copy(src_path, dst_path, overwrite=overwrite)
def move(self, src_path: str, dst_path: str, overwrite: bool = False, preserve_time: bool = False) -> None:
self.copy(src_path, dst_path, overwrite=overwrite, preserve_time=preserve_time)
self.remove(src_path)

def exists(self, path: str) -> bool:
Expand Down Expand Up @@ -458,7 +461,8 @@ def opendir(self, path: str, factory=None) -> SubFS[FS]:
# Implemented to support skipping the directory check if strict=False
_factory = factory or SubFS

if self.strict and not self.getbasic(path).is_dir:
# if self.strict and not self.getbasic(path).is_dir:
if self.strict and not self.getinfo(path, namespaces=["basic"]).is_dir:
raise errors.DirectoryExpected(path=path)

return _factory(self, path)
Expand Down Expand Up @@ -653,13 +657,13 @@ def __init__(self, gcsfs: GCSFS):

def __getitem__(self, key: Any) -> bytes:
try:
return self.gcsfs.getbytes(str(key))
return self.gcsfs.readbytes(str(key))
except errors.ResourceNotFound:
raise KeyError(key)

def __setitem__(self, key: Any, value: Any) -> None:
self.gcsfs.makedirs(dirname(str(key)), recreate=True)
self.gcsfs.setbytes(str(key), bytes(value))
self.gcsfs.writebytes(str(key), bytes(value))

def __delitem__(self, key) -> None:
self.gcsfs.remove(str(key))
Expand Down
2 changes: 1 addition & 1 deletion fs_gcsfs/tests/test_gcsfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def test_fix_storage_does_not_overwrite_existing_directory_markers_with_custom_c

gcsfs.fix_storage()

assert blob.download_as_string() == content
assert blob.download_as_bytes() == content


def test_instantiation_with_create_false_fails_for_non_existing_root_path():
Expand Down

0 comments on commit 1b4754e

Please sign in to comment.