From b4d2618313581f4739e01ae3ff2ed49b1c80008a Mon Sep 17 00:00:00 2001 From: Rok Mandeljc Date: Sun, 24 Jul 2022 19:02:10 +0200 Subject: [PATCH] Add hook for Hydra config system (hydra-core) --- news/424.new.rst | 1 + requirements-test-libraries.txt | 1 + .../hooks/stdhooks/hook-hydra.py | 19 ++++++++++++++ .../tests/data/test_hydra/config.yaml | 3 +++ .../tests/test_libraries.py | 25 +++++++++++++++++++ 5 files changed, 49 insertions(+) create mode 100644 news/424.new.rst create mode 100644 src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-hydra.py create mode 100644 src/_pyinstaller_hooks_contrib/tests/data/test_hydra/config.yaml diff --git a/news/424.new.rst b/news/424.new.rst new file mode 100644 index 000000000..b229e3b2e --- /dev/null +++ b/news/424.new.rst @@ -0,0 +1 @@ +Add hook for Hydra config system (``hydra-core``). diff --git a/requirements-test-libraries.txt b/requirements-test-libraries.txt index 77d335cef..7a56600a9 100644 --- a/requirements-test-libraries.txt +++ b/requirements-test-libraries.txt @@ -104,6 +104,7 @@ great-expectations==0.15.13 tensorflow==2.9.1 pyshark==0.4.6 opencv-python==4.6.0.66 +hydra-core==1.2.0 # ------------------- Platform (OS) specifics diff --git a/src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-hydra.py b/src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-hydra.py new file mode 100644 index 000000000..68c958095 --- /dev/null +++ b/src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-hydra.py @@ -0,0 +1,19 @@ +# ------------------------------------------------------------------ +# Copyright (c) 2022 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 collect_submodules, collect_data_files + +# Collect core plugins. +hiddenimports = collect_submodules('hydra._internal.core_plugins') + +# Collect package's data files, such as default configuration files. +datas = collect_data_files('hydra') diff --git a/src/_pyinstaller_hooks_contrib/tests/data/test_hydra/config.yaml b/src/_pyinstaller_hooks_contrib/tests/data/test_hydra/config.yaml new file mode 100644 index 000000000..f9f740384 --- /dev/null +++ b/src/_pyinstaller_hooks_contrib/tests/data/test_hydra/config.yaml @@ -0,0 +1,3 @@ +test_group: + secret_string: secret + secret_number: 123 diff --git a/src/_pyinstaller_hooks_contrib/tests/test_libraries.py b/src/_pyinstaller_hooks_contrib/tests/test_libraries.py index 2ffee5573..a14a4ae71 100644 --- a/src/_pyinstaller_hooks_contrib/tests/test_libraries.py +++ b/src/_pyinstaller_hooks_contrib/tests/test_libraries.py @@ -1276,3 +1276,28 @@ def test_pyqtgraph(pyi_builder): import pyqtgraph.imageview.ImageView """ ) + + +@importorskip('hydra') +def test_hydra(pyi_builder, tmpdir): + config_file = str((Path(__file__) / '../data/test_hydra/config.yaml').resolve(strict=True).as_posix()) + + pyi_builder.test_source( + """ + import os + + import hydra + from omegaconf import DictConfig, OmegaConf + + config_path = os.path.join(os.path.dirname(__file__), 'conf') + + @hydra.main(config_path=config_path, config_name="config") + def my_app(cfg): + assert cfg.test_group.secret_string == 'secret' + assert cfg.test_group.secret_number == 123 + + if __name__ == "__main__": + my_app() + """, + pyi_args=['--add-data', os.pathsep.join((config_file, 'conf'))] + )