From 256f11dcce8374191144cc2dae5973849988de06 Mon Sep 17 00:00:00 2001 From: Kesara Rathnayake Date: Sat, 20 Jul 2024 11:51:55 -0700 Subject: [PATCH 1/5] feat: Expose important library versions Update `/api/version` to include ``` "other": { "xml2rfc": "", "weasyprint": "" }, ``` Fixes #3415 --- ietf/__init__.py | 15 +++++++++++++++ ietf/api/tests.py | 3 +++ ietf/api/views.py | 1 + 3 files changed, 19 insertions(+) diff --git a/ietf/__init__.py b/ietf/__init__.py index 26124c3c67a..950926ccf8a 100644 --- a/ietf/__init__.py +++ b/ietf/__init__.py @@ -35,6 +35,21 @@ __release_branch__ = branch __release_hash__ = git_hash +# important libraries +__version_extra__ = {} +# xml2rfc +try: + import xml2rfc + __version_extra__['xml2rfc'] = xml2rfc.__version__ +except Exception: + pass + +# weasyprint +try: + import weasyprint + __version_extra__['weasyprint'] = weasyprint.__version__ +except Exception: + pass # This will make sure the app is always imported when # Django starts so that shared_task will use this app. diff --git a/ietf/api/tests.py b/ietf/api/tests.py index 7dc9c42cc84..4eecde2fc10 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__) + self.assertEqual(data['other']['xml2rfc'], ietf.__version_extra__['xml2rfc']) + self.assertEqual(data['other']['weasyprint'], ietf.__version_extra__['weasyprint']) self.assertEqual(data['dumptime'], "2022-08-31 07:10:01 +0000") DumpInfo.objects.update(tz='PST8PDT') r = self.client.get(url) @@ -943,6 +945,7 @@ def test_api_version(self): self.assertEqual(data['dumptime'], "2022-08-31 07:10:01 -0700") + def test_api_appauth(self): for app in ["authortools", "bibxml"]: url = urlreverse('ietf.api.views.app_auth', kwargs={"app": app}) diff --git a/ietf/api/views.py b/ietf/api/views.py index df67cffd56f..2b5c2d59931 100644 --- a/ietf/api/views.py +++ b/ietf/api/views.py @@ -243,6 +243,7 @@ def version(request): return HttpResponse( json.dumps({ 'version': ietf.__version__+ietf.__patch__, + 'other': ietf.__version_extra__, 'dumptime': dumptime, }), content_type='application/json', From 19dda28eed628417fac9f98193f91fe7ec0a9610 Mon Sep 17 00:00:00 2001 From: Kesara Rathnayake Date: Sun, 3 Nov 2024 12:20:44 +0000 Subject: [PATCH 2/5] fix: Use importlib --- ietf/__init__.py | 15 --------------- ietf/api/tests.py | 4 ++-- ietf/api/views.py | 9 ++++++++- ietf/settings.py | 2 ++ 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/ietf/__init__.py b/ietf/__init__.py index 950926ccf8a..26124c3c67a 100644 --- a/ietf/__init__.py +++ b/ietf/__init__.py @@ -35,21 +35,6 @@ __release_branch__ = branch __release_hash__ = git_hash -# important libraries -__version_extra__ = {} -# xml2rfc -try: - import xml2rfc - __version_extra__['xml2rfc'] = xml2rfc.__version__ -except Exception: - pass - -# weasyprint -try: - import weasyprint - __version_extra__['weasyprint'] = weasyprint.__version__ -except Exception: - pass # This will make sure the app is always imported when # Django starts so that shared_task will use this app. diff --git a/ietf/api/tests.py b/ietf/api/tests.py index 4eecde2fc10..d37871c6a99 100644 --- a/ietf/api/tests.py +++ b/ietf/api/tests.py @@ -936,8 +936,8 @@ def test_api_version(self): r = self.client.get(url) data = r.json() self.assertEqual(data['version'], ietf.__version__+ietf.__patch__) - self.assertEqual(data['other']['xml2rfc'], ietf.__version_extra__['xml2rfc']) - self.assertEqual(data['other']['weasyprint'], ietf.__version_extra__['weasyprint']) + for lib in settings.IMPORTANT_LIBRARIES: + 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 2b5c2d59931..e4b17d6f47f 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,10 +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.IMPORTANT_LIBRARIES: + __version_extra__[lib] = metadata_version(lib) + return HttpResponse( json.dumps({ 'version': ietf.__version__+ietf.__patch__, - 'other': ietf.__version_extra__, + 'other': __version_extra__, 'dumptime': dumptime, }), content_type='application/json', diff --git a/ietf/settings.py b/ietf/settings.py index a1a7fee1025..6e0923347ef 100644 --- a/ietf/settings.py +++ b/ietf/settings.py @@ -1279,6 +1279,8 @@ def skip_unreadable_post(record): PUBLISH_IPR_STATES = ['posted', 'removed', 'removed_objfalse'] +IMPORTANT_LIBRARIES = ["django", "celery", "lxml", "markdown", "psycopg2", "pyang", "rfc2html", "weasyprint", "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 From 8261226cb1aa9db4dccc63e3d6c1221295e260c8 Mon Sep 17 00:00:00 2001 From: Kesara Rathnayake Date: Tue, 5 Nov 2024 15:03:09 +0000 Subject: [PATCH 3/5] chore: Reomve additional newline --- ietf/api/tests.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ietf/api/tests.py b/ietf/api/tests.py index d37871c6a99..c8d07167713 100644 --- a/ietf/api/tests.py +++ b/ietf/api/tests.py @@ -945,7 +945,6 @@ def test_api_version(self): self.assertEqual(data['dumptime'], "2022-08-31 07:10:01 -0700") - def test_api_appauth(self): for app in ["authortools", "bibxml"]: url = urlreverse('ietf.api.views.app_auth', kwargs={"app": app}) From c474310c17325f6b81fdc01f7d8126758d4970bf Mon Sep 17 00:00:00 2001 From: Kesara Rathnayake Date: Tue, 19 Nov 2024 11:10:25 +1300 Subject: [PATCH 4/5] fix: Expose libraries that are important for document submission --- ietf/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ietf/settings.py b/ietf/settings.py index 6e0923347ef..59e0a79e1c4 100644 --- a/ietf/settings.py +++ b/ietf/settings.py @@ -1279,7 +1279,7 @@ def skip_unreadable_post(record): PUBLISH_IPR_STATES = ['posted', 'removed', 'removed_objfalse'] -IMPORTANT_LIBRARIES = ["django", "celery", "lxml", "markdown", "psycopg2", "pyang", "rfc2html", "weasyprint", "xml2rfc"] +IMPORTANT_LIBRARIES = ["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 From 4d917fb93e4e78341af816d28672c92eda3fc8a3 Mon Sep 17 00:00:00 2001 From: Kesara Rathnayake Date: Wed, 27 Nov 2024 14:38:45 +1300 Subject: [PATCH 5/5] fix: Rename IMPORTANT_LIBRARIES as ADVERTISE_VERSIONS --- ietf/api/tests.py | 2 +- ietf/api/views.py | 2 +- ietf/settings.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ietf/api/tests.py b/ietf/api/tests.py index c8d07167713..a8d6ac4e577 100644 --- a/ietf/api/tests.py +++ b/ietf/api/tests.py @@ -936,7 +936,7 @@ 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.IMPORTANT_LIBRARIES: + 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') diff --git a/ietf/api/views.py b/ietf/api/views.py index e4b17d6f47f..3e56757528d 100644 --- a/ietf/api/views.py +++ b/ietf/api/views.py @@ -244,7 +244,7 @@ def version(request): # important libraries __version_extra__ = {} - for lib in settings.IMPORTANT_LIBRARIES: + for lib in settings.ADVERTISE_VERSIONS: __version_extra__[lib] = metadata_version(lib) return HttpResponse( diff --git a/ietf/settings.py b/ietf/settings.py index 59e0a79e1c4..419a7a497c9 100644 --- a/ietf/settings.py +++ b/ietf/settings.py @@ -1279,7 +1279,7 @@ def skip_unreadable_post(record): PUBLISH_IPR_STATES = ['posted', 'removed', 'removed_objfalse'] -IMPORTANT_LIBRARIES = ["markdown", "pyang", "rfc2html", "xml2rfc"] +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