From 62efdb1c48fffccfcce2eff1280f0d6b0ddb41fc Mon Sep 17 00:00:00 2001 From: Sambhav Kothari Date: Wed, 31 Jan 2018 23:17:29 +0530 Subject: [PATCH] Move pyinstaller related env variables to utils and add documentation --- picard/acoustid/__init__.py | 5 ++--- picard/util/__init__.py | 9 +++++++-- tagger.py | 6 ++++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/picard/acoustid/__init__.py b/picard/acoustid/__init__.py index 10d5a2d94..25b60f9f1 100644 --- a/picard/acoustid/__init__.py +++ b/picard/acoustid/__init__.py @@ -19,11 +19,10 @@ from collections import deque from functools import partial -import sys from PyQt5 import QtCore from picard import config, log from picard.const import FPCALC_NAMES -from picard.util import find_executable +from picard.util import find_executable, is_frozen from picard.acoustid.json_helpers import parse_recording @@ -38,7 +37,7 @@ class AcoustIDClient(QtCore.QObject): # The second condition is checked because in case of a packaged build of picard # the temp directory that pyinstaller decompresses picard into changes on every # launch, thus we need to ignore the existing config values. - if not config.setting["acoustid_fpcalc"] or getattr(sys, 'frozen', False): + if not config.setting["acoustid_fpcalc"] or is_frozen: fpcalc_path = find_executable(*FPCALC_NAMES) if fpcalc_path: config.setting["acoustid_fpcalc"] = fpcalc_path diff --git a/picard/util/__init__.py b/picard/util/__init__.py index b86a3c300..0e27f1154 100644 --- a/picard/util/__init__.py +++ b/picard/util/__init__.py @@ -34,6 +34,11 @@ from string import Template # Required for compatibility with lastfmplus which imports this from here rather than loading it direct. from picard.const import MUSICBRAINZ_SERVERS +# These variables are set by pyinstaller if running from a packaged build +# See http://pyinstaller.readthedocs.io/en/stable/runtime-information.html +is_frozen = getattr(sys, 'frozen', False) +frozen_temp_path = getattr(sys, '_MEIPASS', '') + class LockableObject(QtCore.QObject): @@ -198,8 +203,8 @@ def find_executable(*executables): paths = [os.path.dirname(sys.executable)] if sys.executable else [] paths += os.environ.get('PATH', '').split(os.pathsep) # This is for searching for executables bundled in packaged builds - if getattr(sys, 'frozen', False): - paths += [sys._MEIPASS] + if is_frozen: + paths += [frozen_temp_path] for path in paths: for executable in executables: f = os.path.join(path, executable) diff --git a/tagger.py b/tagger.py index e6c5321d1..8885c3e3d 100755 --- a/tagger.py +++ b/tagger.py @@ -6,10 +6,12 @@ import sys sys.path.insert(0, '.') from picard.tagger import main +from picard.util import is_frozen, frozen_temp_path + # This is needed to find resources when using pyinstaller -if getattr(sys, 'frozen', False): - basedir = sys._MEIPASS +if is_frozen: + basedir = frozen_temp_path else: basedir = os.path.dirname(os.path.abspath(__file__))