syabruk / pync

Python wrapper for Mac OS 10.8 Notification Center

Home Page:https://pypi.org/project/pync

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for PyInstaller bundle?

JokerQyou opened this issue · comments

Hi SeTeM! First of all thanks for providing this python binding of Terminal-Notifier.
I found it failed within a PyInstaller bundled .app folder. And as I could not ask every end user to install terminal-notifier, I decide to pack the vendor folder into the .app bundle. But that leaded to another problem: the path of vendor folder was coded as the same level of TerminalNotifier.py file, yet TerminalNotifier.py would be bundled into a .pyz archive file.
If this could be solved I'd be very much appreciated.

commented

@JokerQyou interesting idea, please send me poc.

Any update on this @maxkrivich @JokerQyou

Hmmm, I wonder how I missed the last notification from this thread. I'll take a look and try to reproduce it this weekend. I'll post my progress here.

commented

@JokerQyou @jajoosam thank you, I will be waiting for any updates from you.

Okay. This is easier to reproduce than I thought. Basically it's like this:

  • Create a virtual environment and install pync and pyinstaller.
  • In file main.py:
# coding: utf-8
import time

import pync


if __name__ == '__main__':
    pync.notify('Hello World', title='PyInstaller')
    time.sleep(3)
    pync.notify('About to quit')
    time.sleep(1)
  • Produce an app bundle like this: pyinstaller -y -w --clean -n PyncPoC --osx-bundle-identifier test.debug.pync_poc main.py.
  • Run this app, and it will instantly crash.
  • Run like this to view its stdout content: dist/PyncPoC.app/Contents/MacOS/PyncPoC.
commented

@JokerQyou Thanks, I will try as soon as possible

This would be great if there's a fix or some workaround, any update on this? @maxkrivich @JokerQyou

I kinda found a workaround for this problem by putting the pync folder into my resources folder, which are then bundled into the app.app/Contents/MacOS folder. Because pync is searching for the terminal-notifier.app from the folder its been called (os.path.dirname(file) == /path/to/app.app/Contents/MacOS/pync, this works for me now.

self.app_path = os.path.join(
    os.path.dirname(__file__),
    "vendor/terminal-notifier-%s/terminal-notifier.app" % self.TERMINAL_NOTIFIER_VERSION
)
self.bin_path = os.path.join(self.app_path, "Contents/MacOS/terminal-notifier")

So in the resulting app bundle the terminal-notifier.app should be found in /path/to/app.app/Contents/MacOS/pync/vendor/terminal-notifier-2.0.0/terminal-notifier.app.

This issue was created so long ago that it's very hard to recall the context of the specific project involved. I end up calling macOS notification API directly via objc module. Some basic code could be found here.