From 2c162e9417db3ca686b11662485dc42bc71d66aa Mon Sep 17 00:00:00 2001 From: Mo <109725814+mo-dkrz@users.noreply.github.com> Date: Thu, 16 Jan 2025 00:20:22 +0100 Subject: [PATCH] hooks: add hook for fsspec (#856) --- .../stdhooks/hook-fsspec.py | 15 ++++++ news/856.new.rst | 2 + requirements-test-libraries.txt | 1 + tests/test_libraries.py | 47 +++++++++++++++++++ 4 files changed, 65 insertions(+) create mode 100644 _pyinstaller_hooks_contrib/stdhooks/hook-fsspec.py create mode 100644 news/856.new.rst diff --git a/_pyinstaller_hooks_contrib/stdhooks/hook-fsspec.py b/_pyinstaller_hooks_contrib/stdhooks/hook-fsspec.py new file mode 100644 index 00000000..e57a32db --- /dev/null +++ b/_pyinstaller_hooks_contrib/stdhooks/hook-fsspec.py @@ -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') diff --git a/news/856.new.rst b/news/856.new.rst new file mode 100644 index 00000000..0ddcbdd3 --- /dev/null +++ b/news/856.new.rst @@ -0,0 +1,2 @@ +Add hook for ``fsspec`` to collect the package's submodules +and ensure the protocol plugins are working. \ No newline at end of file diff --git a/requirements-test-libraries.txt b/requirements-test-libraries.txt index 022ee5eb..8f7b8e24 100644 --- a/requirements-test-libraries.txt +++ b/requirements-test-libraries.txt @@ -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 diff --git a/tests/test_libraries.py b/tests/test_libraries.py index a52efe92..1d618fef 100644 --- a/tests/test_libraries.py +++ b/tests/test_libraries.py @@ -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):