From c18900a8e693e5704ae6a0336dba25388ced5896 Mon Sep 17 00:00:00 2001 From: Kesara Rathnayake Date: Wed, 27 Nov 2024 14:20:24 +1100 Subject: [PATCH] feat: Expose important library versions (#7713) * feat: Expose important library versions Update `/api/version` to include ``` "other": { "xml2rfc": "", "weasyprint": "" }, ``` Fixes #3415 * fix: Use importlib * chore: Reomve additional newline * fix: Expose libraries that are important for document submission * fix: Rename IMPORTANT_LIBRARIES as ADVERTISE_VERSIONS --- ietf/api/tests.py | 2 ++ ietf/api/views.py | 8 ++++++++ ietf/settings.py | 2 ++ 3 files changed, 12 insertions(+) diff --git a/ietf/api/tests.py b/ietf/api/tests.py index 7dc9c42cc8..a8d6ac4e57 100644 --- a/ietf/api/tests.py +++ b/ietf/api/tests.py @@ -936,6 +936,8 @@ def test_api_version(self): r = self.client.get(url) data = r.json() self.assertEqual(data['version'], ietf.__version__+ietf.__patch__) + for lib in settings.ADVERTISE_VERSIONS: + self.assertIn(lib, data['other']) self.assertEqual(data['dumptime'], "2022-08-31 07:10:01 +0000") DumpInfo.objects.update(tz='PST8PDT') r = self.client.get(url) diff --git a/ietf/api/views.py b/ietf/api/views.py index df67cffd56..3e56757528 100644 --- a/ietf/api/views.py +++ b/ietf/api/views.py @@ -23,6 +23,7 @@ from django.views.decorators.gzip import gzip_page from django.views.generic.detail import DetailView from email.message import EmailMessage +from importlib.metadata import version as metadata_version from jwcrypto.jwk import JWK from tastypie.exceptions import BadRequest from tastypie.serializers import Serializer @@ -240,9 +241,16 @@ def version(request): if dumpinfo.tz != "UTC": dumpdate = pytz.timezone(dumpinfo.tz).localize(dumpinfo.date.replace(tzinfo=None)) dumptime = dumpdate.strftime('%Y-%m-%d %H:%M:%S %z') if dumpinfo else None + + # important libraries + __version_extra__ = {} + for lib in settings.ADVERTISE_VERSIONS: + __version_extra__[lib] = metadata_version(lib) + return HttpResponse( json.dumps({ 'version': ietf.__version__+ietf.__patch__, + 'other': __version_extra__, 'dumptime': dumptime, }), content_type='application/json', diff --git a/ietf/settings.py b/ietf/settings.py index 30f4b367c6..368f61c6e6 100644 --- a/ietf/settings.py +++ b/ietf/settings.py @@ -1273,6 +1273,8 @@ def skip_unreadable_post(record): PUBLISH_IPR_STATES = ['posted', 'removed', 'removed_objfalse'] +ADVERTISE_VERSIONS = ["markdown", "pyang", "rfc2html", "xml2rfc"] + # We provide a secret key only for test and development modes. It's # absolutely vital that django fails to start in production mode unless a # secret key has been provided elsewhere, not in this file which is