Skip to content

Commit

Permalink
Fix displaying the installed version of Django-Jazzmin in the UI.
Browse files Browse the repository at this point in the history
Since we changed our CD process and now will automatically generate test
builds (#550), the version in the `__init__` file now needs to be
updated to stop it from being hardcoded. As in development the version
is now set to 0.0.0 in the `pyproject.toml` file, we need to get the
version dyanmically. We can call the package manager to check which
version of `django-jazzmin` was installed. This sadly does vary
depending on which version of Python is installed - support for these
older versions are soon to be dropped.
  • Loading branch information
PacificGilly committed Mar 30, 2024
1 parent 5a22e0a commit b96d9e1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
15 changes: 14 additions & 1 deletion jazzmin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
import django
import sys

# We automatically grab the version of `django-jazzmin` from the package manager instead of
# hard coding it. The method for determining the version changed since PY3.8. N.B. For
# development versions of `django-jazzmin`, the version will be 0.0.0 (see pyproject.toml) as it's
# not technically installed.
if sys.version_info >= (3, 8):
from importlib.metadata import version as package_version

version = package_version("django-jazzmin")
else:
import pkg_resources

version = pkg_resources.get_distribution("django-jazzmin").version

version = "2.6.1"

if django.VERSION < (3, 2):
default_app_config = "jazzmin.apps.JazzminConfig"
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,10 @@ commands =
[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"


[[tool.mypy.overrides]]
module = [
"pkg_resources.*",
]
ignore_missing_imports = true

0 comments on commit b96d9e1

Please sign in to comment.