From 7317084a4ed9c03f109e27e4a478dee840e69726 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Sat, 12 Feb 2022 11:11:08 +0100 Subject: [PATCH 1/4] Update requirements --- optional-requirements.txt | 1 - setup.cfg | 1 - 2 files changed, 2 deletions(-) diff --git a/optional-requirements.txt b/optional-requirements.txt index 2370bc7e..123f4686 100644 --- a/optional-requirements.txt +++ b/optional-requirements.txt @@ -10,7 +10,6 @@ pyasn1>=0.1.9,<0.5.0 PyDrive2>=1.3.1,<1.11.0 PyYAML>=3.12 rsa>=3.4.2,<4.9.0 -# six>=1.10.0,<1.17.0 # Gmail google-auth-oauthlib>=0.4.3,<0.5.0 diff --git a/setup.cfg b/setup.cfg index 5053d19f..e6774776 100644 --- a/setup.cfg +++ b/setup.cfg @@ -70,7 +70,6 @@ gdrive = PyDrive2>=1.3.1,<1.11.0 PyYAML>=3.12 rsa>=3.4.2,<4.9.0 - six>=1.10.0,<1.17.0 gmail = google-auth-oauthlib>=0.4.3,<0.5.0 google-api-python-client>=1.7.11,<2.37.0 From 295888c654b114f350c2973bd12f8865af54f962 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Sat, 12 Feb 2022 11:20:09 +0100 Subject: [PATCH 2/4] 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 From 0436f0f9b252dc4a35a232abfd5a02657c02b42c Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Sat, 12 Feb 2022 11:58:56 +0100 Subject: [PATCH 3/4] Improved dependency check for executables --- cps/dep_check.py | 12 ++++++++---- optional-requirements.txt | 2 +- requirements.txt | 2 +- setup.cfg | 4 ++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/cps/dep_check.py b/cps/dep_check.py index 5e8e36cf..84e16e85 100644 --- a/cps/dep_check.py +++ b/cps/dep_check.py @@ -23,8 +23,12 @@ 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()) + pip_installed = os.path.join(BASE_DIR, ".pip_installed") + if os.path.exists(pip_installed): + with open(pip_installed) as f: + exe_deps = json.loads("".join(f.readlines())) + else: + return deps if importlib or pkgresources: if optional: req_path = os.path.join(BASE_DIR, "optional-requirements.txt") @@ -37,13 +41,13 @@ def load_dependencys(optional=False): res = re.match(r'(.*?)([<=>\s]+)([\d\.]+),?\s?([<=>\s]+)?([\d\.]+)?', line.strip()) try: if getattr(sys, 'frozen', False): - dep_version = exe_deps[res.group(1).lower()] + dep_version = exe_deps[res.group(1).lower().replace('_','-')] else: if importlib: dep_version = version(res.group(1)) else: dep_version = pkg_resources.get_distribution(res.group(1)).version - except ImportNotFound: + except (ImportNotFound, KeyError): if optional: continue dep_version = "not installed" diff --git a/optional-requirements.txt b/optional-requirements.txt index 123f4686..f7c7b572 100644 --- a/optional-requirements.txt +++ b/optional-requirements.txt @@ -33,7 +33,7 @@ scholarly>=1.2.0,<1.6 markdown2>=2.0.0,<2.5.0 html2text>=2020.1.16,<2022.1.1 python-dateutil>=2.1,<2.9.0 -beautifulsoup4>=4.0.1,<4.2.0 +beautifulsoup4>=4.0.1,<4.11.0 cchardet>=2.0.0,<2.2.0 # Comics diff --git a/requirements.txt b/requirements.txt index 0b95dfa3..d9bed7bb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,7 +5,7 @@ Flask-Principal>=0.3.2,<0.5.1 backports_abc>=0.4 Flask>=1.0.2,<2.1.0 iso-639>=0.4.5,<0.5.0 -PyPDF3>=1.0.0,<1.0.6 +PyPDF3>=1.0.0,<1.0.7 pytz>=2016.10 requests>=2.11.1,<2.28.0 SQLAlchemy>=1.3.0,<1.5.0 diff --git a/setup.cfg b/setup.cfg index e6774776..12874151 100644 --- a/setup.cfg +++ b/setup.cfg @@ -45,7 +45,7 @@ install_requires = backports_abc>=0.4 Flask>=1.0.2,<2.1.0 iso-639>=0.4.5,<0.5.0 - PyPDF3>=1.0.0,<1.0.6 + PyPDF3>=1.0.0,<1.0.7 pytz>=2016.10 requests>=2.11.1,<2.28.0 SQLAlchemy>=1.3.0,<1.5.0 @@ -88,7 +88,7 @@ metadata = markdown2>=2.0.0,<2.5.0 html2text>=2020.1.16,<2022.1.1 python-dateutil>=2.1,<2.9.0 - beautifulsoup4>=4.0.1,<4.2.0 + beautifulsoup4>=4.0.1,<4.11.0 cchardet>=2.0.0,<2.2.0 comics = natsort>=2.2.0,<8.2.0 From 6b026513cbe877c1ac103e0fcaf92a1e90719183 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Sat, 12 Feb 2022 12:12:30 +0100 Subject: [PATCH 4/4] refactored about --- cps/about.py | 86 ++++++++-------------------------------------------- 1 file changed, 12 insertions(+), 74 deletions(-) diff --git a/cps/about.py b/cps/about.py index ec7b1172..8f2bf715 100644 --- a/cps/about.py +++ b/cps/about.py @@ -25,47 +25,15 @@ import platform import sqlite3 from collections import OrderedDict -import babel -import pytz -import requests -import sqlalchemy import werkzeug import flask import flask_login -import flask_principal import jinja2 from flask_babel import gettext as _ -try: - from flask_wtf import __version__ as flaskwtf_version -except ImportError: - flaskwtf_version = _(u'not installed') -from . import db, calibre_db, converter, uploader, server, isoLanguages, constants, gdriveutils, dep_check +from . import db, calibre_db, converter, uploader, constants, dep_check from .render_template import render_title_template -try: - from flask_login import __version__ as flask_loginVersion -except ImportError: - from flask_login.__about__ import __version__ as flask_loginVersion -try: - # pylint: disable=unused-import - import unidecode - # _() necessary to make babel aware of string for translation - unidecode_version = _(u'installed') -except ImportError: - unidecode_version = _(u'not installed') - -try: - from flask_dance import __version__ as flask_danceVersion -except ImportError: - flask_danceVersion = None - -try: - from greenlet import __version__ as greenlet_Version -except ImportError: - greenlet_Version = None - -from . import services about = flask.Blueprint('about', __name__) @@ -87,47 +55,17 @@ if getattr(sys, 'frozen', False): elif constants.HOME_CONFIG: calibre_web_version += " - pyPi" -if not ret: - _VERSIONS = OrderedDict( - Platform='{0[0]} {0[2]} {0[3]} {0[4]} {0[5]}'.format(platform.uname()), - Python=sys.version, - Calibre_Web=calibre_web_version, - WebServer=server.VERSION, - Flask=flask.__version__, - Flask_Login=flask_loginVersion, - Flask_Principal=flask_principal.__version__, - Flask_WTF=flaskwtf_version, - Werkzeug=werkzeug.__version__, - Babel=babel.__version__, - Jinja2=jinja2.__version__, - Requests=requests.__version__, - SqlAlchemy=sqlalchemy.__version__, - pySqlite=sqlite3.version, - SQLite=sqlite3.sqlite_version, - iso639=isoLanguages.__version__, - pytz=pytz.__version__, - Unidecode=unidecode_version, - Flask_SimpleLDAP=u'installed' if bool(services.ldap) else None, - python_LDAP=services.ldapVersion if bool(services.ldapVersion) else None, - Goodreads=u'installed' if bool(services.goodreads_support) else None, - jsonschema=services.SyncToken.__version__ if bool(services.SyncToken) else None, - flask_dance=flask_danceVersion, - greenlet=greenlet_Version - ) - _VERSIONS.update(gdriveutils.get_versions()) - _VERSIONS.update(uploader.get_versions(True)) -else: - _VERSIONS = OrderedDict( - Platform='{0[0]} {0[2]} {0[3]} {0[4]} {0[5]}'.format(platform.uname()), - Python=sys.version, - Calibre_Web=calibre_web_version, - Werkzeug=werkzeug.__version__, - Jinja2=jinja2.__version__, - pySqlite=sqlite3.version, - SQLite=sqlite3.sqlite_version, - ) - _VERSIONS.update(ret) - _VERSIONS.update(uploader.get_versions(False)) +_VERSIONS = OrderedDict( + Platform='{0[0]} {0[2]} {0[3]} {0[4]} {0[5]}'.format(platform.uname()), + Python=sys.version, + Calibre_Web=calibre_web_version, + Werkzeug=werkzeug.__version__, + Jinja2=jinja2.__version__, + pySqlite=sqlite3.version, + SQLite=sqlite3.sqlite_version, +) +_VERSIONS.update(ret) +_VERSIONS.update(uploader.get_versions(False)) def collect_stats():