diff --git a/news/424.new.rst b/news/424.new.rst new file mode 100644 index 00000000..b229e3b2 --- /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 77d335ce..7a56600a 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 00000000..68c95809 --- /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 00000000..f9f74038 --- /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 2ffee557..6a1a9551 100644 --- a/src/_pyinstaller_hooks_contrib/tests/test_libraries.py +++ b/src/_pyinstaller_hooks_contrib/tests/test_libraries.py @@ -9,8 +9,12 @@ # # SPDX-License-Identifier: GPL-2.0-or-later # ------------------------------------------------------------------ -import pytest + +import os from pathlib import Path + +import pytest + from PyInstaller.compat import is_darwin, is_linux, is_py39, is_win from PyInstaller.utils.hooks import is_module_satisfies, can_import_module from PyInstaller.utils.tests import importorskip, requires, xfail @@ -1276,3 +1280,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'))] + )