diff --git a/news/581.new.rst b/news/581.new.rst new file mode 100644 index 000000000..b8366afff --- /dev/null +++ b/news/581.new.rst @@ -0,0 +1 @@ +Add hook for pylibmagic diff --git a/requirements-test-libraries.txt b/requirements-test-libraries.txt index c27f00586..eed20896a 100644 --- a/requirements-test-libraries.txt +++ b/requirements-test-libraries.txt @@ -63,6 +63,7 @@ pycparser==2.21 pycryptodome==3.17 pycryptodomex==3.17 pyexcelerate==0.10.0 +pylibmagic==0.3.1; sys_platform != 'win32' and python_version >= '3.7' pylint==2.17.4 pypemicro==0.1.11 pyphen==0.14.0 diff --git a/src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-pylibmagic.py b/src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-pylibmagic.py new file mode 100644 index 000000000..4b6221922 --- /dev/null +++ b/src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-pylibmagic.py @@ -0,0 +1,19 @@ +# ------------------------------------------------------------------ +# Copyright (c) 2023 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 +# ------------------------------------------------------------------ + +""" +Pylibmagic contains data files (libmagic compiled and configurations) required to use the python-magic package. +""" + +from PyInstaller.utils.hooks import collect_data_files + +datas = collect_data_files("pylibmagic") diff --git a/src/_pyinstaller_hooks_contrib/tests/test_libraries.py b/src/_pyinstaller_hooks_contrib/tests/test_libraries.py index 8f761f2e7..e6b4945e9 100644 --- a/src/_pyinstaller_hooks_contrib/tests/test_libraries.py +++ b/src/_pyinstaller_hooks_contrib/tests/test_libraries.py @@ -1559,3 +1559,18 @@ def test_customtkinter(pyi_builder): pyi_builder.test_source(""" import customtkinter """) + + +@importorskip('pylibmagic') +def test_pylibmagic(pyi_builder): + pyi_builder.test_source(""" + import pylibmagic + import os + + bundle_dir = os.path.normpath(sys._MEIPASS) + pylibmagic_data_path = f"{bundle_dir}/pylibmagic" + assert os.path.isfile(f"{bundle_dir}/libmagic.so.1", \ + f"The libmagic compiled file was not collected to _MEIPASS!" + assert os.path.isfile(f"{bundle_dir}/magic.mgc", \ + f"The magic.mgc file was not collected to _MEIPASS!" + """)