From dee602246b6d652bee9cda815b89ffe1b80159d2 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 27 May 2017 22:31:15 +0530 Subject: [PATCH] Consolidate development env detection --- src/calibre/constants.py | 8 ++++++-- src/calibre/gui2/__init__.py | 7 +++---- src/calibre/srv/embedded.py | 5 ++--- src/calibre/srv/standalone.py | 5 ++--- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/calibre/constants.py b/src/calibre/constants.py index 670ec16b37..057af58b9f 100644 --- a/src/calibre/constants.py +++ b/src/calibre/constants.py @@ -258,13 +258,17 @@ else: # }}} +dv = os.environ.get('CALIBRE_DEVELOP_FROM') +is_running_from_develop = bool(getattr(sys, 'frozen', False) and dv and os.path.abspath(dv) in sys.path) +del dv + + def get_version(): '''Return version string for display to user ''' - dv = os.environ.get('CALIBRE_DEVELOP_FROM', None) v = __version__ if numeric_version[-1] == 0: v = v[:-2] - if getattr(sys, 'frozen', False) and dv and os.path.abspath(dv) in sys.path: + if is_running_from_develop: v += '*' if iswindows and is64bit: v += ' [64bit]' diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index 7f75d8d82a..45cc47a510 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -13,7 +13,7 @@ from PyQt5.Qt import ( QApplication, QDialog, QUrl, QFont, QFontDatabase, QLocale, QFontInfo) from calibre import prints -from calibre.constants import (islinux, iswindows, isbsd, isfrozen, isosx, +from calibre.constants import (islinux, iswindows, isbsd, isfrozen, isosx, is_running_from_develop, plugins, config_dir, filesystem_encoding, isxp, DEBUG, __version__, __appname__ as APP_UID) from calibre.ptempfile import base_dir from calibre.utils.config import Config, ConfigProxy, dynamic, JSONConfig @@ -1420,9 +1420,8 @@ def build_forms(srcdir, info=None, summary=False, check_for_migration=False): gprefs.set('migrated_forms_to_qt5', True) -_df = os.environ.get('CALIBRE_DEVELOP_FROM', None) -if _df and os.path.exists(_df): - build_forms(_df, check_for_migration=True) +if is_running_from_develop: + build_forms(os.environ['CALIBRE_DEVELOP_FROM'], check_for_migration=True) def event_type_name(ev_or_etype): diff --git a/src/calibre/srv/embedded.py b/src/calibre/srv/embedded.py index 5d705751a2..2d3233f966 100644 --- a/src/calibre/srv/embedded.py +++ b/src/calibre/srv/embedded.py @@ -8,7 +8,7 @@ import os from threading import Thread from calibre import as_unicode -from calibre.constants import cache_dir +from calibre.constants import cache_dir, is_running_from_develop from calibre.srv.bonjour import BonJour from calibre.srv.handler import Handler from calibre.srv.http_response import create_http_handler @@ -82,8 +82,7 @@ class Server(object): self.exception = None from calibre.srv.content import reset_caches try: - _df = os.environ.get('CALIBRE_DEVELOP_FROM', None) - if _df and os.path.exists(_df): + if is_running_from_develop: from calibre.utils.rapydscript import compile_srv compile_srv() except BaseException as e: diff --git a/src/calibre/srv/standalone.py b/src/calibre/srv/standalone.py index 05540ef792..b822f3aff8 100644 --- a/src/calibre/srv/standalone.py +++ b/src/calibre/srv/standalone.py @@ -10,7 +10,7 @@ import sys, os, signal from functools import partial from calibre import as_unicode, prints -from calibre.constants import plugins, iswindows, preferred_encoding +from calibre.constants import plugins, iswindows, preferred_encoding, is_running_from_develop from calibre.srv.loop import ServerLoop from calibre.srv.library_broker import load_gui_libraries from calibre.srv.bonjour import BonJour @@ -77,8 +77,7 @@ class Server(object): self.handler.set_jobs_manager(self.loop.jobs_manager) self.serve_forever = self.loop.serve_forever self.stop = self.loop.stop - _df = os.environ.get('CALIBRE_DEVELOP_FROM', None) - if _df and os.path.exists(_df): + if is_running_from_develop: from calibre.utils.rapydscript import compile_srv compile_srv()