From 295888c654b114f350c2973bd12f8865af54f962 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Sat, 12 Feb 2022 11:20:09 +0100 Subject: [PATCH] Find imports in executables --- cps/about.py | 1 + cps/dep_check.py | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/cps/about.py b/cps/about.py index 7ff178e3..ec7b1172 100644 --- a/cps/about.py +++ b/cps/about.py @@ -81,6 +81,7 @@ else: calibre_web_version = (constants.STABLE_VERSION['version'] + ' - ' + constants.NIGHTLY_VERSION[0].replace('%', '%%') + ' - ' + constants.NIGHTLY_VERSION[1].replace('%', '%%')) + if getattr(sys, 'frozen', False): calibre_web_version += " - Exe-Version" elif constants.HOME_CONFIG: diff --git a/cps/dep_check.py b/cps/dep_check.py index 12436d1d..5e8e36cf 100644 --- a/cps/dep_check.py +++ b/cps/dep_check.py @@ -1,5 +1,7 @@ import os import re +import sys +import json from .constants import BASE_DIR try: @@ -8,7 +10,7 @@ try: ImportNotFound = BaseException except ImportError: importlib = False - + version = None if not importlib: try: @@ -20,6 +22,9 @@ if not importlib: def load_dependencys(optional=False): deps = list() + if getattr(sys, 'frozen', False): + with open(os.path.join(BASE_DIR, ".pip_installed")) as f: + exe_deps = json.loads(f.readlines()) if importlib or pkgresources: if optional: req_path = os.path.join(BASE_DIR, "optional-requirements.txt") @@ -31,10 +36,13 @@ def load_dependencys(optional=False): if not line.startswith('#') and not line == '\n' and not line.startswith('git'): res = re.match(r'(.*?)([<=>\s]+)([\d\.]+),?\s?([<=>\s]+)?([\d\.]+)?', line.strip()) try: - if importlib: - dep_version = version(res.group(1)) + if getattr(sys, 'frozen', False): + dep_version = exe_deps[res.group(1).lower()] else: - dep_version = pkg_resources.get_distribution(res.group(1)).version + if importlib: + dep_version = version(res.group(1)) + else: + dep_version = pkg_resources.get_distribution(res.group(1)).version except ImportNotFound: if optional: continue