From a7d58386eb18c8f0cfafb790876d81e84c2e3fbe Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Mon, 5 Aug 2024 20:27:21 +0200 Subject: [PATCH] Get version info from importlib.metadata --- cps/about.py | 8 ++++++-- cps/debug_info.py | 6 ++++-- requirements.txt | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/cps/about.py b/cps/about.py index 355978c3..9053dfee 100644 --- a/cps/about.py +++ b/cps/about.py @@ -23,6 +23,7 @@ import sys import platform import sqlite3 +import importlib from collections import OrderedDict import flask @@ -41,8 +42,11 @@ req = dep_check.load_dependencies(False) opt = dep_check.load_dependencies(True) for i in (req + opt): modules[i[1]] = i[0] -modules['Jinja2'] = jinja2.__version__ -modules['pySqlite'] = sqlite3.version +modules['Jinja2'] = importlib.metadata.version("jinja2") +try: + modules['pySqlite'] = sqlite3.version +except Exception: + pass modules['SQLite'] = sqlite3.sqlite_version sorted_modules = OrderedDict((sorted(modules.items(), key=lambda x: x[0].casefold()))) diff --git a/cps/debug_info.py b/cps/debug_info.py index 879846ab..3be60700 100644 --- a/cps/debug_info.py +++ b/cps/debug_info.py @@ -26,7 +26,8 @@ from flask_babel.speaklater import LazyString import os -from flask import send_file, __version__ +from flask import send_file +import importlib from . import logger, config from .about import collect_stats @@ -49,7 +50,8 @@ def assemble_logfiles(file_name): with open(f, 'rb') as fd: shutil.copyfileobj(fd, wfd) wfd.seek(0) - if int(__version__.split('.')[0]) < 2: + version = importlib.metadata.version("flask") + if int(version.split('.')[0]) < 2: return send_file(wfd, as_attachment=True, attachment_filename=os.path.basename(file_name)) diff --git a/requirements.txt b/requirements.txt index 460a7357..71074892 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,7 +13,7 @@ Wand>=0.4.4,<0.7.0 unidecode>=0.04.19,<1.4.0 lxml>=4.9.1,<5.3.0 flask-wtf>=0.14.2,<1.3.0 -chardet>=3.0.0,<4.1.0 +chardet>=3.0.0,<5.3.0 advocate>=1.0.0,<1.1.0 Flask-Limiter>=2.3.0,<3.9.0 regex>=2022.3.2,<2024.6.25