From faabd39e2f1a8ad53fa7222b5bc3431caafb4222 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Magalh=C3=A3es?= Date: Sat, 13 May 2023 17:22:20 +0100 Subject: [PATCH] Add hook for pylibmagic --- news/581.new.rst | 1 + requirements-test-libraries.txt | 1 + .../hooks/stdhooks/hook-pylibmagic.py | 19 +++++++++++++++++++ .../tests/test_libraries.py | 17 +++++++++++++++++ 4 files changed, 38 insertions(+) create mode 100644 news/581.new.rst create mode 100644 src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-pylibmagic.py 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..b36b80b75 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.0; 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..f984fa1a2 100644 --- a/src/_pyinstaller_hooks_contrib/tests/test_libraries.py +++ b/src/_pyinstaller_hooks_contrib/tests/test_libraries.py @@ -1559,3 +1559,20 @@ 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" + + files_to_assert = ["libmagic.so.1", "magic.mgc"] + + for file in files_to_assert: + assert os.path.isfile(f"{pylibmagic_data_path}/{file}"), \ + f"The {file} was not collected to _MEIPASS!" + """)