From 9623ac4141bb5178a05d89dd9ed8cbe9c382ca57 Mon Sep 17 00:00:00 2001 From: Anthony LC Date: Mon, 18 Nov 2024 12:31:49 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9(backend)=20get=20current=20release?= =?UTF-8?q?=20from=20pyproject.toml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "get_release" was returning NA, we fixed it by getting the version from pyproject.toml, to do so we use tomllib Since tomllib is a native library from Python 3.11, we bump the required version to 3.11 on the pyproject.toml. --- src/backend/impress/settings.py | 17 +++++------------ src/backend/pyproject.toml | 5 +++-- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/backend/impress/settings.py b/src/backend/impress/settings.py index 8ba26fdf..5e0c60c4 100755 --- a/src/backend/impress/settings.py +++ b/src/backend/impress/settings.py @@ -10,8 +10,8 @@ For the full list of settings and their values, see https://docs.djangoproject.com/en/3.1/ref/settings/ """ -import json import os +import tomllib from django.utils.translation import gettext_lazy as _ @@ -27,19 +27,12 @@ DATA_DIR = os.path.join("/", "data") def get_release(): """ Get the current release of the application - - By release, we mean the release from the version.json file à la Mozilla [1] - (if any). If this file has not been found, it defaults to "NA". - - [1] - https://github.com/mozilla-services/Dockerflow/blob/master/docs/version_object.md """ - # Try to get the current release from the version.json file generated by the - # CI during the Docker image build try: - with open(os.path.join(BASE_DIR, "version.json"), encoding="utf8") as version: - return json.load(version)["version"] - except FileNotFoundError: + with open(os.path.join(BASE_DIR, "pyproject.toml"), "rb") as f: + pyproject_data = tomllib.load(f) + return pyproject_data["project"]["version"] + except (FileNotFoundError, KeyError): return "NA" # Default: not available diff --git a/src/backend/pyproject.toml b/src/backend/pyproject.toml index 00bc5b10..a8afc7ba 100644 --- a/src/backend/pyproject.toml +++ b/src/backend/pyproject.toml @@ -17,13 +17,13 @@ classifiers = [ "License :: OSI Approved :: MIT License", "Natural Language :: English", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.12", ] description = "An application to print markdown to pdf from a set of managed templates." keywords = ["Django", "Contacts", "Templates", "RBAC"] license = { file = "LICENSE" } readme = "README.md" -requires-python = ">=3.10" +requires-python = ">=3.12" dependencies = [ "boto3==1.35.44", "Brotli==1.1.0", @@ -127,6 +127,7 @@ select = [ [tool.ruff.lint.isort] section-order = ["future","standard-library","django","third-party","impress","first-party","local-folder"] sections = { impress=["core"], django=["django"] } +extra-standard-library = ["tomllib"] [tool.ruff.lint.per-file-ignores] "**/tests/*" = ["S", "SLF"]