Browse Source

Replace pkg_resources with importlib (#1301)

* Install importlib_metadata for Python 3.7

* Replace pkg_resources with importlib
Siddhant Goel 1 year ago
parent
commit
59c4a5e962
3 changed files with 9 additions and 4 deletions
  1. 1 1
      poetry.lock
  2. 2 1
      pyproject.toml
  3. 6 2
      reflex/constants.py

+ 1 - 1
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"

+ 2 - 1
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"]
+"reflex/.templates/*.py" = ["D100", "D103", "D104"]

+ 6 - 2
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"