Replace pkg_resources with importlib (#1301)

* Install importlib_metadata for Python 3.7

* Replace pkg_resources with importlib
This commit is contained in:
Siddhant Goel 2023-07-05 20:10:03 +02:00 committed by GitHub
parent 51452a6e5a
commit 59c4a5e962
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 4 deletions

2
poetry.lock generated
View File

@ -1836,4 +1836,4 @@ testing = ["big-O", "flake8 (<5)", "jaraco.functools", "jaraco.itertools", "more
[metadata]
lock-version = "2.0"
python-versions = "^3.7"
content-hash = "c7ef30a96b3882cdd07982ce661e174edd8ae8cd52976a23e02f16a6b8cd3eae"
content-hash = "b07623f193778651dd3ece81370d2d9a2ba3b53855a57baf0147e67bf07aaed8"

View File

@ -44,6 +44,7 @@ watchfiles = "^0.19.0"
websockets = "^10.4"
starlette-admin = "^0.9.0"
python-dotenv = "^0.13.0"
importlib-metadata = {version = "^6.7.0", python = ">=3.7, <3.8"}
[tool.poetry.group.dev.dependencies]
pytest = "^7.1.2"
@ -83,4 +84,4 @@ target-version = "py37"
"__init__.py" = ["F401"]
"tests/*.py" = ["D100", "D103", "D104"]
"reflex/.templates/*.py" = ["D100", "D103", "D104"]
"reflex/.templates/*.py" = ["D100", "D103", "D104"]

View File

@ -6,7 +6,11 @@ from enum import Enum
from types import SimpleNamespace
from typing import Any, Type
import pkg_resources
# importlib is only available for Python 3.8+ so we need the backport for Python 3.7
try:
from importlib import metadata
except ImportError:
import importlib_metadata as metadata # pyright: ignore[reportMissingImports]
def get_value(key: str, default: Any = None, type_: Type = str) -> Type:
@ -38,7 +42,7 @@ def get_value(key: str, default: Any = None, type_: Type = str) -> Type:
# The name of the Reflex package.
MODULE_NAME = "reflex"
# The current version of Reflex.
VERSION = pkg_resources.get_distribution(MODULE_NAME).version
VERSION = metadata.version(MODULE_NAME)
# Minimum version of Node.js required to run Reflex.
MIN_NODE_VERSION = "16.8.0"