Move pyinstaller related env variables to utils and add documentation

This commit is contained in:
Sambhav Kothari
2018-01-31 23:17:29 +05:30
parent 9f3cb9ced8
commit 62efdb1c48
3 changed files with 13 additions and 7 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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__))