From 59c4a5e962d8c4d33aea7cc5e0375936754f3f3c Mon Sep 17 00:00:00 2001 From: Siddhant Goel Date: Wed, 5 Jul 2023 20:10:03 +0200 Subject: [PATCH] Replace pkg_resources with importlib (#1301) * Install importlib_metadata for Python 3.7 * Replace pkg_resources with importlib --- poetry.lock | 2 +- pyproject.toml | 3 ++- reflex/constants.py | 8 ++++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/poetry.lock b/poetry.lock index c64a40815..4992d7eb4 100644 --- a/poetry.lock +++ b/poetry.lock @@ -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" diff --git a/pyproject.toml b/pyproject.toml index c0675828c..8611aef08 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"] \ No newline at end of file +"reflex/.templates/*.py" = ["D100", "D103", "D104"] diff --git a/reflex/constants.py b/reflex/constants.py index 31fe2edcf..0dc406cad 100644 --- a/reflex/constants.py +++ b/reflex/constants.py @@ -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"