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 discid package #506

Merged
merged 1 commit into from
Nov 2, 2022
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
4 changes: 4 additions & 0 deletions .github/workflows/pr-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ jobs:
libpulse0 libpulse-mainloop-glib0
# Install cairo dependencies.
sudo apt-get install -y libcairo2
# Install libdiscid (dependency of discid python package).
sudo apt-get install -y libdiscid0

- name: Install brew dependencies
if: startsWith(matrix.os, 'macos')
Expand All @@ -94,6 +96,8 @@ jobs:
brew install cairo
# Install pango dependencies (weasyprint hook).
brew install pango
# Install libdiscid (dependency of discid python package).
brew install libdiscid

- name: Install dependencies
shell: bash
Expand Down
1 change: 1 addition & 0 deletions news/506.new.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add hook for ``discid``.
3 changes: 3 additions & 0 deletions requirements-test-libraries.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ cloudscraper==1.2.64
dash==2.6.2
dash-bootstrap-components==1.2.1
dash-uploader==0.6.0
# discid requires libdiscid to be provided by the system.
# We install it via apt-get and brew on ubuntu and macOS CI runners, respectively.
discid==1.2.0; sys_platform != 'win32'
fabric==2.7.1
fiona==1.8.22; sys_platform != 'win32'
folium==0.13.0
Expand Down
41 changes: 41 additions & 0 deletions src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-discid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# ------------------------------------------------------------------
# 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
# ------------------------------------------------------------------

import os

from PyInstaller.utils.hooks import get_module_attribute, logger
from PyInstaller.depend.utils import _resolveCtypesImports


binaries = []

# Use the _LIB_NAME attribute of discid.libdiscid to resolve the shared library name. This saves us from having to
# duplicate the name guessing logic from discid.libdiscid.
# On error, PyInstaller >= 5.0 raises exception, earlier versions return an empty string.
try:
lib_name = get_module_attribute("discid.libdiscid", "_LIB_NAME")
except Exception:
lib_name = None

if lib_name:
lib_name = os.path.basename(lib_name)
try:
resolved_binary = _resolveCtypesImports([lib_name])
lib_file = resolved_binary[0][1]
except Exception as e:
lib_file = None
logger.warning("Error while trying to resolve %s: %s", lib_name, e)

if lib_file:
binaries += [(lib_file, '.')]
else:
logger.warning("Failed to determine name of libdiscid shared library from _LIB_NAME attribute of discid.libdiscid!")
18 changes: 18 additions & 0 deletions src/_pyinstaller_hooks_contrib/tests/test_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -1385,3 +1385,21 @@ def test_spiceypy(pyi_builder):
pyi_builder.test_source("""
import spiceypy
""")


@importorskip('discid')
def test_discid(pyi_builder):
pyi_builder.test_source(
"""
# Basic import check
import discid

# Check that shared library is in fact collected into application bundle.
# We expect the hook to collect it to top-level directory (sys._MEIPASS).
import discid.libdiscid
lib_name = discid.libdiscid._LIB_NAME

lib_file = os.path.join(sys._MEIPASS, lib_name)
assert os.path.isfile(lib_file), f"Shared library {lib_name} not collected to _MEIPASS!"
"""
)