Skip to content

armgit / meet

Public Imported from GitHub
0

Open source video conferencing app powered by LiveKit. Built with Django and React.

πŸ›(backend) read the Sentry release from pyproject.toml

briquetb159b2069594
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c48c4d5f..7179e310 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -25,6 +25,7 @@ and this project adheres to
### Fixed
+- πŸ›(backend) report the app release to Sentry instead of "NA"
- πŸ›(backend) acknowledge unknown LiveKit webhook events instead of 422
- πŸ”’οΈ(backend) enforce display name setting on rename API
- πŸ”’οΈ(backend) reject inactive users in resource server backend
diff --git a/src/backend/core/tests/test_settings_release.py b/src/backend/core/tests/test_settings_release.py
new file mode 100644
index 00000000..ad485344
--- /dev/null
+++ b/src/backend/core/tests/test_settings_release.py
@@ -0,0 +1,47 @@
+"""Unit tests for the get_release settings helper."""
+
+import re
+
+import pytest
+
+from meet.settings import get_release
+
+
[email protected](name="base_dir")
+def fixture_empty_base_dir(tmp_path, monkeypatch):
+ """Point get_release at an empty directory."""
+ monkeypatch.setattr("meet.settings.BASE_DIR", str(tmp_path))
+ return tmp_path
+
+
+def test_get_release_reads_project_pyproject():
+ """Should return the semantic version of the backend's pyproject.toml."""
+ assert re.fullmatch(r"\d+\.\d+\.\d+", get_release())
+
+
+def test_get_release_reads_pyproject_version(base_dir):
+ """Should return the version declared in the [project] table."""
+ (base_dir / "pyproject.toml").write_text(
+ '[project]\nname = "meet"\nversion = "1.2.3"\n', encoding="utf-8"
+ )
+ assert get_release() == "1.2.3"
+
+
[email protected]("base_dir")
+def test_get_release_missing_pyproject():
+ """Should fall back to "NA" without a pyproject.toml."""
+ assert get_release() == "NA"
+
+
+ "content",
+ [
+ '[project]\nname = "meet"\n', # no version
+ "[tool.uv]\npackage = true\n", # no [project] table
+ "[project\nversion = ", # malformed TOML
+ ],
+)
+def test_get_release_unreadable_version(base_dir, content):
+ """Should fall back to "NA" without a readable version in pyproject.toml."""
+ (base_dir / "pyproject.toml").write_text(content, encoding="utf-8")
+ assert get_release() == "NA"
diff --git a/src/backend/meet/settings.py b/src/backend/meet/settings.py
index 35137d7c..2f434173 100755
--- a/src/backend/meet/settings.py
+++ b/src/backend/meet/settings.py
@@ -12,7 +12,7 @@ https://docs.djangoproject.com/en/3.1/ref/settings/
# pylint: disable=too-many-lines
-import json
+import tomllib
import warnings
from os import path
from socket import gethostbyname, gethostname
@@ -37,19 +37,11 @@ GB = 1024 * MB
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(path.join(BASE_DIR, "version.json"), encoding="utf8") as version:
- return json.load(version)["version"]
- except FileNotFoundError:
+ with open(path.join(BASE_DIR, "pyproject.toml"), "rb") as pyproject:
+ return tomllib.load(pyproject)["project"]["version"]
+ except (FileNotFoundError, KeyError, tomllib.TOMLDecodeError):
return "NA" # Default: not available