Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hook for patoolib #748

Merged
merged 4 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions news/748.new.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add hook for ``patoolib`` to collect dynamically-imported modules from
the ``patoolib.programs`` sub-package.
1 change: 1 addition & 0 deletions requirements-test-libraries.txt
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ opentelemetry-sdk==1.24.0
xarray==2024.5.0; python_version >= '3.9'
tables==3.9.2; python_version >= '3.9'
schwifty==2024.5.3
patool==2.2.0; python_version >= '3.10'

# ------------------- Platform (OS) specifics

Expand Down
16 changes: 16 additions & 0 deletions src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-patoolib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#-----------------------------------------------------------------------------
# Copyright (c) 2017-2024, PyInstaller Development Team.
#
# Distributed under the terms of the GNU General Public License with exception
# for distributing bootloader.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------


"""
patoolib uses importlib and pyinstaller doesn't find it and add it to the list of needed modules
"""

from PyInstaller.utils.hooks import collect_submodules
hiddenimports = collect_submodules('patoolib.programs')
21 changes: 21 additions & 0 deletions src/_pyinstaller_hooks_contrib/tests/test_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -2097,3 +2097,24 @@ async def main():

asyncio.run(main())
""")


@importorskip('patoolib')
def test_patoolib(pyi_builder):
pyi_builder.test_source("""
import patoolib

archive = 'archive.zip'

# The call to `get_archive_cmdlist_func` triggers import of module from `patoolib.programs` via
# `importlib.import_module`; the set up below is based on code from `patoolib._extract_archive`.
archive_format, compression = patoolib.get_archive_format(archive)
print(f"Archive format: {archive_format}")
print(f"Compression: compression")

program = patoolib.find_archive_program(archive_format, 'extract')
print(f"Program: {program}")

cmdlist = patoolib.get_archive_cmdlist_func(program, 'extract', archive_format)
print(f"Cmdlist: {cmdlist}")
""")
Loading