Skip to content

Commit

Permalink
Add hook for pylibmagic
Browse files Browse the repository at this point in the history
  • Loading branch information
pjrm committed May 13, 2023
1 parent 1ec0eff commit faabd39
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions news/581.new.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add hook for pylibmagic
1 change: 1 addition & 0 deletions requirements-test-libraries.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-pylibmagic.py
Original file line number Diff line number Diff line change
@@ -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")
17 changes: 17 additions & 0 deletions src/_pyinstaller_hooks_contrib/tests/test_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!"
""")

0 comments on commit faabd39

Please sign in to comment.