Skip to content

Commit

Permalink
Merge pull request #23 from Othoz/fix-storage-bugfix
Browse files Browse the repository at this point in the history
Fixed bug in GCSFS.fix_storage() and prepared release of 1.1.0
Closes #19
  • Loading branch information
birnbaum committed Jan 7, 2020
2 parents c155b89 + 072c548 commit 9a447ab
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
19 changes: 14 additions & 5 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,20 @@ Possible types of changes are:
Unreleased
----------


1.1.0 - 07.01.2020
------------------

Added
'''''
- ``GCSFS.get_mapper()`` which returns a ``GCSMap`` that wraps a ``GCSFS`` as a ``MutableMapping``.
The keys of the mapping become files and the values (which must be bytes) the contents of those files.
This is particularly useful to be used with libraries such as `xarray <http://xarray.pydata.org/>`_ or `zarr <https://zarr.readthedocs.io/>`_.
This is particularly useful to be used with libraries such as `xarray <http://xarray.pydata.org/>`_ or `zarr <https://zarr.readthedocs.io/>`_. (#21)

Fixed
'''''
- ``GCSFS.fix_storage()`` no longer creates a directory marker if ``root_path`` is the actual root of the bucket.
Apart from not having any advantage, this caused subsequent ``GCSFS.fix_storage()`` calls as well as ``GCSFS.walk()`` to be stuck in endless loops. (#19)


1.0.0 - 27.08.2019
Expand All @@ -33,23 +42,23 @@ Added
Changed
'''''''
- Instead of uploading all blobs as *application/octet-stream*, the MIME type is now guessed via ``mimetypes.guess_type()``.
This enables e.g. hotlinking images directly from GCS.
This enables e.g. hotlinking images directly from GCS. (#15)


0.4.2 - 30.07.2019
------------------

Fixed
'''''
- Fixed a bug where the url parameter ``strict`` was not considered by GCSFS, e.g. in ``open_fs("gs://bucket_name?strict=False")``
- Fixed a bug where the url parameter ``strict`` was not considered by GCSFS, e.g. in ``open_fs("gs://bucket_name?strict=False")`` (#11)


0.4.1 - 18.12.2018
------------------

Fixed
'''''
- Fixed a bug where ``create=True`` in combination with an "empty-ish ``root_path`` like ``""``, ``"."`` or ``"/"`` would create a directory marker.
- Fixed a bug where ``create=True`` in combination with an empty-ish ``root_path`` like ``""``, ``"."`` or ``"/"`` would create a directory marker.


0.4.0 - 11.12.2018
Expand All @@ -58,7 +67,7 @@ Fixed
Added
'''''
- Implemented the ``create`` property on ``GCSFS`` and the corresponding opener. By default all new GCSFS instances have ``create=False`` (PyFilesystem default)
which means they will raise a ``CreateFailed`` exception if ``root_path`` does not exist
which means they will raise a ``CreateFailed`` exception if ``root_path`` does not exist (#8)


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

import google
from fs import ResourceType, errors, tools
Expand Down Expand Up @@ -477,7 +477,9 @@ def fix_storage(self) -> None: # TODO test
while name != self.root_path:
all_dirs.add(name)
name = dirname(name)
all_dirs.add(self.root_path)

if forcedir(self.root_path) != "/":
all_dirs.add(self.root_path)

unmarked_dirs = all_dirs.difference(marked_dirs)
logger.info("{} directories in total".format(len(all_dirs)))
Expand Down Expand Up @@ -632,17 +634,17 @@ class GCSMap(MutableMapping):
def __init__(self, gcsfs: GCSFS):
self.gcsfs = gcsfs

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

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

def __delitem__(self, key):
def __delitem__(self, key) -> None:
self.gcsfs.remove(str(key))

def __iter__(self) -> Iterator[str]:
Expand All @@ -651,7 +653,7 @@ def __iter__(self) -> Iterator[str]:
def __len__(self) -> int:
return sum(1 for _ in self.keys())

def __contains__(self, key: str) -> bool:
def __contains__(self, key: Any) -> bool:
return self.gcsfs.exists(str(key))

def keys(self) -> Iterator[str]:
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: Implementation",
"Topic :: System :: Filesystems",
],
Expand Down

0 comments on commit 9a447ab

Please sign in to comment.