From 240f75ff0677e305bcab876dd7019b395e43354d Mon Sep 17 00:00:00 2001 From: frcroth Date: Tue, 2 Jan 2024 12:04:25 +0100 Subject: [PATCH] Add dynamic versioning and version in footer (#452) --- myhpi/core/markdown/extensions.py | 11 +++++++++++ myhpi/core/migrations/0002_rootpage.py | 2 +- myhpi/settings.py | 11 +++++++++++ pyproject.toml | 9 ++++++--- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/myhpi/core/markdown/extensions.py b/myhpi/core/markdown/extensions.py index b7754c85..f151a687 100644 --- a/myhpi/core/markdown/extensions.py +++ b/myhpi/core/markdown/extensions.py @@ -8,6 +8,8 @@ from markdown.preprocessors import Preprocessor from wagtail.models import Page +from myhpi import settings + class MinutesBasePreprocessor(Preprocessor): def run(self, lines): @@ -162,6 +164,14 @@ def default_pattern(): return r"\[(?P[^\[]+)\]\(page:(?P<id>\d+)\)" +class VersionPreprocessor(MinutesBasePreprocessor): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.patterns = [ + (r"\[MYHPI-VERSION\]", lambda match: settings.MYHPI_VERSION), + ] + + class MinuteExtension(Extension): def extendMarkdown(self, md): md.registerExtension(self) @@ -171,6 +181,7 @@ def extendMarkdown(self, md): md.preprocessors.register(QuorumPreprocessor(md), "quorumify", 200) md.preprocessors.register(EnterLeavePreprocessor(md), "enter_or_leavify", 200) md.preprocessors.register(HeadingLevelPreprocessor(md), "decrease", 200) + md.preprocessors.register(VersionPreprocessor(md), "version", 200) md.inlinePatterns.register( InternalLinkPattern(InternalLinkPattern.default_pattern(), md), "InternalLinkPattern", diff --git a/myhpi/core/migrations/0002_rootpage.py b/myhpi/core/migrations/0002_rootpage.py index 41736d94..72348f86 100644 --- a/myhpi/core/migrations/0002_rootpage.py +++ b/myhpi/core/migrations/0002_rootpage.py @@ -50,7 +50,7 @@ def create_homepage(apps, schema_editor): Footer.objects.get_or_create( column_1="# Fachschaft\r\n\r\n- [Twitter](https://twitter.com/fachschaftsrat)\r\n- [Discord](https://discord.com)\r\n- [Telegram](https://telegram.org)", column_2="# Rechtliches\r\n\r\n- [Impressum]()\r\n- [Datenschutzerklärung]()", - column_3="# Entwicklung\r\n\r\n- [GitHub](https://github.com/fsr-de/myHPI/)", + column_3="# Entwicklung\r\n\r\n- [GitHub](https://github.com/fsr-de/myHPI/)\r\n[MYHPI-VERSION]", column_4="# Sprache\r\n\r\n", ) diff --git a/myhpi/settings.py b/myhpi/settings.py index 51f154a4..e0dc75d8 100644 --- a/myhpi/settings.py +++ b/myhpi/settings.py @@ -6,6 +6,12 @@ from django.contrib.messages import constants from environ import environ +try: + import importlib_metadata # importlib is broken on python 3.8, using backport +except ImportError: + import importlib.metadata as importlib_metadata + + BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) env = environ.Env(interpolate=True) @@ -366,3 +372,8 @@ } BS_ICONS_CACHE = os.path.join(STATIC_ROOT, "icon_cache") + +try: + MYHPI_VERSION = importlib_metadata.version("myHPI") +except importlib_metadata.PackageNotFoundError: + MYHPI_VERSION = "dev" diff --git a/pyproject.toml b/pyproject.toml index 8f98c678..9201f6f5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "myHPI" -version = "0.1.0" +version = "0.0.0" # automatically set by poetry-dynamic-versioning description = "" authors = ["FSR DE <fachschaftsrat@hpi.de>"] license = "MIT" @@ -37,8 +37,8 @@ pgsql = ["psycopg2"] mysql = ["mysqlclient"] [build-system] -requires = ["poetry-core>=1.0.0"] -build-backend = "poetry.core.masonry.api" +requires = ["poetry-core>=1.0.0", "poetry-dynamic-versioning>=1.0.0,<2.0.0"] +build-backend = "poetry_dynamic_versioning.backend" [tool.black] line-length = 100 @@ -64,3 +64,6 @@ useless-object-inheritance, logging-fstring-interpolation [tool.pylint.format] max-line-length = "100" + +[tool.poetry-dynamic-versioning] +enable = true