Skip to content

Inconsistent storage options for zip filesystem depending on how it was created #1907

@mraspaud

Description

@mraspaud

In an attempt to make use of UPath in our libs, I stumbled upon this problem with fsspec:
When creating a zip filesystem directly using the ZipFilesystem class, it looks like the storage_options are not set in the same way than if we got that filesystem through eg fsspec.open.

See an example here:

>>> from pathlib import Path
>>> local_path = Path("/tmp/myfile.txt")
>>> local_path.touch()
>>> from zipfile import ZipFile
>>> with ZipFile("/tmp/myzipfile.zip", 'w') as myzip:
...     myzip.write("/tmp/myfile.txt")
...     
>>> import fsspec
>>> fsspec_file = fsspec.open("zip://tmp/myfile.txt::/tmp/myzipfile.zip")
>>> fsspec_file.fs.to_dict()
{'cls': 'fsspec.implementations.zip:ZipFileSystem', 'protocol': 'zip', 'args': [], 'target_options': {}, 'target_protocol': 'file', 'fo': '/tmp/myzipfile.zip'}
>>> fsspec.filesystem("zip", **fsspec_file.fs.storage_options).to_dict()
{'cls': 'fsspec.implementations.zip:ZipFileSystem', 'protocol': 'zip', 'args': [], 'target_options': {}, 'target_protocol': 'file', 'fo': '/tmp/myzipfile.zip'}

>>> from fsspec.implementations.zip import ZipFileSystem
>>> zip_fs = ZipFileSystem("/tmp/myzipfile.zip")
>>> zip_fs.to_dict()
{'cls': 'fsspec.implementations.zip:ZipFileSystem', 'protocol': 'zip', 'args': ['/tmp/myzipfile.zip']}
>>> fsspec.filesystem("zip", **zip_fs.storage_options).to_dict()
Traceback (most recent call last):
  File "<python-input-18>", line 1, in <module>
    fsspec.filesystem("zip", **zip_fs.storage_options).to_dict()
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mraspaud/src/.venv/lib/python3.13/site-packages/fsspec/registry.py", line 322, in filesystem
    return cls(**storage_options)
  File "/home/mraspaud/src/.venv/lib/python3.13/site-packages/fsspec/spec.py", line 81, in __call__
    obj = super().__call__(*args, **kwargs)
  File "/home/mraspaud/src/.venv/lib/python3.13/site-packages/fsspec/implementations/zip.py", line 62, in __init__
    self.fo = fo.__enter__()  # the whole instance is a context
              ~~~~~~~~~~~~^^
  File "/home/mraspaud/src/.venv/lib/python3.13/site-packages/fsspec/core.py", line 105, in __enter__
    f = self.fs.open(self.path, mode=mode)
  File "/home/mraspaud/src/.venv/lib/python3.13/site-packages/fsspec/spec.py", line 1338, in open
    f = self._open(
        path,
    ...<4 lines>...
        **kwargs,
    )
  File "/home/mraspaud/src/.venv/lib/python3.13/site-packages/fsspec/implementations/local.py", line 210, in _open
    return LocalFileOpener(path, mode, fs=self, **kwargs)
  File "/home/mraspaud/src/.venv/lib/python3.13/site-packages/fsspec/implementations/local.py", line 387, in __init__
    self._open()
    ~~~~~~~~~~^^
  File "/home/mraspaud/src/.venv/lib/python3.13/site-packages/fsspec/implementations/local.py", line 392, in _open
    self.f = open(self.path, mode=self.mode)
             ~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
IsADirectoryError: [Errno 21] Is a directory: '/home/mraspaud/src/'

This is problematic when I then want to create a UPath instance with:

path = UPath("/tmp/myfile", protocol=zip_fs.protocol, storage_options=zip_fs.storage_options)

which crashes eventually with the same error as above when one calls open or fs on it for example.

Some relevant versions:

Python 3.13.2 (main, Feb 12 2025, 14:51:17) [Clang 19.1.6 ] on linux

>>> import fsspec
>>> fsspec.__version__
'2025.7.0'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions