Skip to content

Commit

Permalink
Add dynamic versioning and version in footer (#452)
Browse files Browse the repository at this point in the history
  • Loading branch information
frcroth authored Jan 2, 2024
1 parent 63031eb commit 240f75f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
11 changes: 11 additions & 0 deletions myhpi/core/markdown/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -162,6 +164,14 @@ def default_pattern():
return r"\[(?P<title>[^\[]+)\]\(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)
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion myhpi/core/migrations/0002_rootpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)

Expand Down
11 changes: 11 additions & 0 deletions myhpi/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"
9 changes: 6 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
license = "MIT"
Expand Down Expand Up @@ -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
Expand All @@ -64,3 +64,6 @@ useless-object-inheritance, logging-fstring-interpolation

[tool.pylint.format]
max-line-length = "100"

[tool.poetry-dynamic-versioning]
enable = true

0 comments on commit 240f75f

Please sign in to comment.