Skip to content

Commit

Permalink
hooks: add hook for fsspec (#856)
Browse files Browse the repository at this point in the history
  • Loading branch information
mo-dkrz authored Jan 15, 2025
1 parent 6c7df30 commit 2c162e9
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
15 changes: 15 additions & 0 deletions _pyinstaller_hooks_contrib/stdhooks/hook-fsspec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# ------------------------------------------------------------------
# Copyright (c) 2025 PyInstaller Development Team.
#
# This file is distributed under the terms of the GNU General Public
# License (version 2.0 or later).
#
# The full license is available in LICENSE, distributed with
# this software.
#
# SPDX-License-Identifier: GPL-2.0-or-later
# ------------------------------------------------------------------

from PyInstaller.utils.hooks import collect_submodules

hiddenimports = collect_submodules('fsspec')
2 changes: 2 additions & 0 deletions news/856.new.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add hook for ``fsspec`` to collect the package's submodules
and ensure the protocol plugins are working.
1 change: 1 addition & 0 deletions requirements-test-libraries.txt
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ pysaml2==7.5.0; python_version >= '3.9'
pysaml2==7.3.0; python_version < '3.9' # pyup: ignore
toga==0.4.8; python_version >= '3.9'
numbers-parser==4.14.2; python_version >= '3.9'
fsspec==2024.12.0; python_version >= '3.9'
zarr==3.0.0; python_version >= '3.11'
intake==2.0.7; python_version >= '3.9'
h3==4.1.2
Expand Down
47 changes: 47 additions & 0 deletions tests/test_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -2388,6 +2388,53 @@ def test_numbers_parser(pyi_builder, tmp_path):
""", app_args=[str(output_filename)])


@importorskip('fsspec')
def test_fsspec_protocols(pyi_builder, tmp_path):
# Get the list of working protocols in unfrozen python
@isolated.decorate
def _get_working_fsspec_protocols():
import fsspec

working_protocols = []
for protocol in fsspec.available_protocols():
try:
fsspec.get_filesystem_class(protocol)
working_protocols.append(protocol)
except ImportError:
pass

return sorted(working_protocols)

protocols_unfrozen = _get_working_fsspec_protocols()
print(f"Unfrozen protocols: {protocols_unfrozen}")

# Obtain list of working protocols in frozen application.
output_file = tmp_path / "output.txt"

pyi_builder.test_source("""
import sys
import fsspec
working_protocols = []
for protocol in fsspec.available_protocols():
try:
obj = fsspec.get_filesystem_class(protocol)
working_protocols.append(protocol)
except ImportError:
pass
with open(sys.argv[1], 'w') as fp:
for protocol in working_protocols:
print(f"{protocol}", file=fp)
""", app_args=[str(output_file)])

with open(output_file, "r") as fp:
protocols_frozen = sorted(line.strip() for line in fp)
print(f"Frozen protocols: {protocols_frozen}")

assert protocols_frozen == protocols_unfrozen


@importorskip('zarr')
@importorskip('xarray')
def test_xarray_to_zarr(pyi_builder):
Expand Down

0 comments on commit 2c162e9

Please sign in to comment.