From 4ace0d3e1c49d5b8db12eef6b14d471c758ceb82 Mon Sep 17 00:00:00 2001 From: Thomas W <69774548+yctomwang@users.noreply.github.com> Date: Wed, 31 Jan 2024 10:04:55 +1100 Subject: [PATCH] fix deprecation warning for __version__ (#543) --- tests/test_config.py | 16 +++++++++++++++- tox.ini | 1 + 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/test_config.py b/tests/test_config.py index f38bcfc4..fa938795 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -1,10 +1,10 @@ import json +import sys from datetime import date from datetime import timedelta import pytest from dateutil.relativedelta import relativedelta -from flask import __version__ as flask_version from flask import Flask from flask_jwt_extended import JWTManager @@ -12,6 +12,20 @@ from flask_jwt_extended.internal_utils import JSONEncoder +def get_package_version(package_name): + if sys.version_info >= (3, 8): + # Use importlib.metadata for Python 3.8 and newer + import importlib.metadata + + return importlib.metadata.version(package_name) + else: + # Use pkg_resources for older versions + import pkg_resources + + return pkg_resources.get_distribution(package_name).version + + +flask_version = get_package_version("flask") flask_version_tuple = tuple(map(int, flask_version.split("."))) diff --git a/tox.ini b/tox.ini index 5a91819b..843b0c11 100644 --- a/tox.ini +++ b/tox.ini @@ -27,6 +27,7 @@ deps = python-dateutil types-python-dateutil mypy + types-setuptools [testenv:coverage] commands =