Skip to content

Commit

Permalink
hooks: add hook for xarray
Browse files Browse the repository at this point in the history
Add hook for `xarray`, which ensures that metadata for `numpy`
(required by `xarray`) is collected.
  • Loading branch information
rokm committed Apr 18, 2024
1 parent aa7d19f commit d2a4a24
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions news/728.new.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add hook for ``xarray``, which ensures that metadata for ``numpy``
(required by ``xarray``) is collected.
1 change: 1 addition & 0 deletions requirements-test-libraries.txt
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ eth-hash==0.7.0
pypylon==3.0.1
python-pptx==0.6.23
opentelemetry-sdk==1.24.0
xarray==2024.3.0; python_version >= '3.9'

# ------------------- Platform (OS) specifics

Expand Down
17 changes: 17 additions & 0 deletions src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-xarray.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# ------------------------------------------------------------------
# Copyright (c) 2024 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.GPL.txt, distributed with
# this software.
#
# SPDX-License-Identifier: GPL-2.0-or-later
# ------------------------------------------------------------------

from PyInstaller.utils.hooks import copy_metadata

# `xarray` requires `numpy` metadata due to several calls to its `xarray.core.utils.module_available` with specified
# `minversion` argument, which end up calling `importlib.metadata.version`.
datas = copy_metadata('numpy')
15 changes: 15 additions & 0 deletions src/_pyinstaller_hooks_contrib/tests/test_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -1995,3 +1995,18 @@ def test_cryptography(pyi_builder):
print(f"Decrypted message: {f.decrypt(token)}")
""")


@importorskip('xarray')
def test_xarray(pyi_builder):
pyi_builder.test_source("""
import xarray as xr
import numpy as np
data = xr.DataArray(
np.random.randn(2, 3),
dims=("x", "y"),
coords={"x": [10, 20]},
)
print(data)
""")

0 comments on commit d2a4a24

Please sign in to comment.