From 301edf9f1d7b0f5bcd7ef55628275e00d704d5ec Mon Sep 17 00:00:00 2001
From: TNA-Allan <96120886+TNA-Allan@users.noreply.github.com>
Date: Wed, 3 Jan 2024 12:01:43 +0000
Subject: [PATCH 1/5] FIX:Fix test compatible with python 3.12 (#1500)
---
etna/ciim/tests/test_utils.py | 24 +++----
etna/collections/tests/test_models.py | 30 +++------
etna/core/tests/test_decorators.py | 4 +-
etna/core/tests/test_middleware.py | 14 ++--
etna/records/tests/test_blocks.py | 2 +-
etna/records/tests/test_models.py | 4 +-
etna/records/tests/test_urls.py | 2 +-
etna/records/tests/test_views.py | 96 +++++++++++++--------------
8 files changed, 83 insertions(+), 93 deletions(-)
diff --git a/etna/ciim/tests/test_utils.py b/etna/ciim/tests/test_utils.py
index 12cd6fa60..6ed7251cc 100644
--- a/etna/ciim/tests/test_utils.py
+++ b/etna/ciim/tests/test_utils.py
@@ -114,7 +114,7 @@ def test_test(self):
stripped_markup = format_description_markup(markup)
- self.assertEquals(
+ self.assertEqual(
'link text',
stripped_markup,
)
@@ -124,7 +124,7 @@ def test_no_links(self):
stripped_markup = format_description_markup(markup)
- self.assertEquals("", stripped_markup)
+ self.assertEqual("", stripped_markup)
def test_multiple_links(self):
markup = (
@@ -136,7 +136,7 @@ def test_multiple_links(self):
stripped_markup = format_description_markup(markup)
- self.assertEquals(
+ self.assertEqual(
(
""
'link text one'
@@ -155,7 +155,7 @@ def test_external_link(self):
stripped_markup = format_description_markup(markup)
- self.assertEquals(
+ self.assertEqual(
("" 'link text one' ""),
stripped_markup,
)
@@ -166,7 +166,7 @@ def test_invalid_link(self):
stripped_markup = format_description_markup(markup)
- self.assertEquals(
+ self.assertEqual(
(""),
stripped_markup,
)
@@ -327,46 +327,46 @@ def test_none(self):
index = convert_sort_key_to_index(sort)
- self.assertEquals(index, 0)
+ self.assertEqual(index, 0)
def test_empty_string(self):
sort = None
index = convert_sort_key_to_index(sort)
- self.assertEquals(index, 0)
+ self.assertEqual(index, 0)
def test_converts_sort_key_with_leading_zero(self):
sort = "01"
index = convert_sort_key_to_index(sort)
- self.assertEquals(index, 0)
+ self.assertEqual(index, 0)
def test_converts_sort_key_at_three_digit_boundary(self):
sort = "31000"
index = convert_sort_key_to_index(sort)
- self.assertEquals(index, 999)
+ self.assertEqual(index, 999)
def test_converts_sort_key_at_four_digit_boundary(self):
sort = "31001"
index = convert_sort_key_to_index(sort)
- self.assertEquals(index, 1000)
+ self.assertEqual(index, 1000)
def test_index_is_zero_for_invalid_sort_key(self):
sort = "10000"
index = convert_sort_key_to_index(sort)
- self.assertEquals(index, 0)
+ self.assertEqual(index, 0)
def test_index_is_zero_for_non_int_sort_key(self):
sort = "NaN"
index = convert_sort_key_to_index(sort)
- self.assertEquals(index, 0)
+ self.assertEqual(index, 0)
diff --git a/etna/collections/tests/test_models.py b/etna/collections/tests/test_models.py
index 178f5f5f1..c730893d6 100644
--- a/etna/collections/tests/test_models.py
+++ b/etna/collections/tests/test_models.py
@@ -22,9 +22,7 @@ def setUp(self):
root_page.add_child(instance=self.topic_explorer_index_page)
def test_no_child_pages(self):
- self.assertEquals(
- self.topic_explorer_index_page.topic_explorer_pages.count(), 0
- )
+ self.assertEqual(self.topic_explorer_index_page.topic_explorer_pages.count(), 0)
def test_unpublish_page_excluded(self):
unpublished_topic_page = TopicExplorerPage(
@@ -33,9 +31,7 @@ def test_unpublish_page_excluded(self):
self.topic_explorer_index_page.add_child(instance=unpublished_topic_page)
unpublished_topic_page.unpublish()
- self.assertEquals(
- self.topic_explorer_index_page.topic_explorer_pages.count(), 0
- )
+ self.assertEqual(self.topic_explorer_index_page.topic_explorer_pages.count(), 0)
@unittest.skip(
"Disabled test due to all child pages on home being private during beta."
@@ -47,9 +43,7 @@ def test_private_page_excluded(self):
self.topic_explorer_index_page.add_child(instance=private_topic_page)
PageViewRestriction.objects.create(page=private_topic_page)
- self.assertEquals(
- self.topic_explorer_index_page.topic_explorer_pages.count(), 0
- )
+ self.assertEqual(self.topic_explorer_index_page.topic_explorer_pages.count(), 0)
def test_published_public_pages(self):
topic_page = TopicExplorerPage(
@@ -57,9 +51,7 @@ def test_published_public_pages(self):
)
self.topic_explorer_index_page.add_child(instance=topic_page)
- self.assertEquals(
- self.topic_explorer_index_page.topic_explorer_pages.count(), 1
- )
+ self.assertEqual(self.topic_explorer_index_page.topic_explorer_pages.count(), 1)
def test_published_time_period_pages_excluded(self):
topic_page = TimePeriodExplorerPage(
@@ -71,9 +63,7 @@ def test_published_time_period_pages_excluded(self):
)
self.topic_explorer_index_page.add_child(instance=topic_page)
- self.assertEquals(
- self.topic_explorer_index_page.topic_explorer_pages.count(), 0
- )
+ self.assertEqual(self.topic_explorer_index_page.topic_explorer_pages.count(), 0)
class TestTopicExplorerPage(TestCase):
@@ -158,7 +148,7 @@ def setUp(self):
root_page.add_child(instance=self.time_period_explorer_index_page)
def test_no_child_pages(self):
- self.assertEquals(
+ self.assertEqual(
self.time_period_explorer_index_page.time_period_explorer_pages.count(), 0
)
@@ -173,7 +163,7 @@ def test_unpublish_page_excluded(self):
self.time_period_explorer_index_page.add_child(instance=unpublished_topic_page)
unpublished_topic_page.unpublish()
- self.assertEquals(
+ self.assertEqual(
self.time_period_explorer_index_page.time_period_explorer_pages.count(), 0
)
@@ -191,7 +181,7 @@ def test_private_page_excluded(self):
self.time_period_explorer_index_page.add_child(instance=private_topic_page)
PageViewRestriction.objects.create(page=private_topic_page)
- self.assertEquals(
+ self.assertEqual(
self.time_period_explorer_index_page.time_period_explorer_pages.count(), 0
)
@@ -205,7 +195,7 @@ def test_published_public_pages(self):
)
self.time_period_explorer_index_page.add_child(instance=topic_page)
- self.assertEquals(
+ self.assertEqual(
self.time_period_explorer_index_page.time_period_explorer_pages.count(), 1
)
@@ -215,6 +205,6 @@ def test_topic_pages_excluded(self):
)
self.time_period_explorer_index_page.add_child(instance=topic_page)
- self.assertEquals(
+ self.assertEqual(
self.time_period_explorer_index_page.time_period_explorer_pages.count(), 0
)
diff --git a/etna/core/tests/test_decorators.py b/etna/core/tests/test_decorators.py
index d5e6a64e1..1cf194722 100644
--- a/etna/core/tests/test_decorators.py
+++ b/etna/core/tests/test_decorators.py
@@ -71,7 +71,7 @@ def test_allows_request_when_setting_value_is_true_and_authenticated(self):
for url in CONDITIONALLY_PROTECTED_URLS:
with self.subTest(f"URL: {url}"):
response = self.client.get(url)
- self.assertEquals(response.status_code, 200)
+ self.assertEqual(response.status_code, 200)
@responses.activate
@override_settings(
@@ -83,4 +83,4 @@ def test_allows_unauthenticated_access_when_setting_value_is_false(self):
for url in CONDITIONALLY_PROTECTED_URLS:
with self.subTest(f"URL: {url}"):
response = self.client.get(url)
- self.assertEquals(response.status_code, 200)
+ self.assertEqual(response.status_code, 200)
diff --git a/etna/core/tests/test_middleware.py b/etna/core/tests/test_middleware.py
index 332d4f301..2ed1073c4 100644
--- a/etna/core/tests/test_middleware.py
+++ b/etna/core/tests/test_middleware.py
@@ -14,15 +14,15 @@ class TestMaintenanceMode(TestCase):
@prevent_request_warnings
def test_without_maintenance_mode_ends(self):
response = self.client.get("/")
- self.assertEquals(response.status_code, 503)
+ self.assertEqual(response.status_code, 503)
self.assertNotIn("Retry-After", response.headers)
@prevent_request_warnings
@override_settings(MAINTENENCE_MODE_ENDS="2011-11-04T00:05:23+04:00")
def test_maintenance_mode_ends_with_timezone_info(self):
response = self.client.get("/")
- self.assertEquals(response.status_code, 503)
- self.assertEquals(
+ self.assertEqual(response.status_code, 503)
+ self.assertEqual(
response.headers["Retry-After"], "Thu, 03 Nov 2011 20:05:23 GMT"
)
@@ -30,8 +30,8 @@ def test_maintenance_mode_ends_with_timezone_info(self):
@override_settings(MAINTENENCE_MODE_ENDS="2011-11-04T00:05:23")
def test_maintenance_mode_ends_without_timezone_info(self):
response = self.client.get("/")
- self.assertEquals(response.status_code, 503)
- self.assertEquals(
+ self.assertEqual(response.status_code, 503)
+ self.assertEqual(
response.headers["Retry-After"], "Fri, 04 Nov 2011 00:05:23 GMT"
)
@@ -40,7 +40,7 @@ def test_maintenance_mode_ends_without_timezone_info(self):
def test_maintenance_mode_bypassed_when_ip_in_allow_list(self, *args):
response = self.client.get("/")
- self.assertEquals(response.status_code, 200)
+ self.assertEqual(response.status_code, 200)
@prevent_request_warnings
@override_settings(MAINTENENCE_MODE_ALLOW_IPS=["123.4.5.6"])
@@ -49,7 +49,7 @@ def test_maintenance_mode_enforced_when_ip_not_in_allowed_list(
self, mock_get_client_ip
):
response = self.client.get("/")
- self.assertEquals(response.status_code, 503)
+ self.assertEqual(response.status_code, 503)
class TestInterpretCookiesMiddleware(SimpleTestCase):
diff --git a/etna/records/tests/test_blocks.py b/etna/records/tests/test_blocks.py
index 78739ec72..ba158aa2c 100644
--- a/etna/records/tests/test_blocks.py
+++ b/etna/records/tests/test_blocks.py
@@ -234,4 +234,4 @@ def test_view_edit_page_with_client_api_exception(self):
reverse("wagtailadmin_pages:edit", args=(self.article_page.id,))
)
- self.assertEquals(response.status_code, 200)
+ self.assertEqual(response.status_code, 200)
diff --git a/etna/records/tests/test_models.py b/etna/records/tests/test_models.py
index c38720514..a2e8660ef 100644
--- a/etna/records/tests/test_models.py
+++ b/etna/records/tests/test_models.py
@@ -588,7 +588,7 @@ def test_thumbnail_url(self):
images = Image.search.filter(rid="")
image = images[0]
- self.assertEquals(
+ self.assertEqual(
image.thumbnail_url, "https://media.preview/path/to/thumbnail.jpeg"
)
@@ -610,7 +610,7 @@ def test_thumbnail_url_fallback(self):
image = images[0]
# Fallback serves image through Wagtail instead of from Client API
- self.assertEquals(image.thumbnail_url, "/records/image/path/to/image.jpeg")
+ self.assertEqual(image.thumbnail_url, "/records/image/path/to/image.jpeg")
@override_settings(CLIENT_BASE_URL=f"{settings.CLIENT_BASE_URL}")
diff --git a/etna/records/tests/test_urls.py b/etna/records/tests/test_urls.py
index 0109c37f4..88972b156 100644
--- a/etna/records/tests/test_urls.py
+++ b/etna/records/tests/test_urls.py
@@ -141,7 +141,7 @@ def test_resolves_iaid(self):
def test_iaid_with_non_standard_prefix(self):
resolver = resolve("/catalogue/id/C123456/")
- self.assertEquals(resolver.view_name, "details-page-machine-readable")
+ self.assertEqual(resolver.view_name, "details-page-machine-readable")
self.assertEqual(resolver.kwargs["iaid"], "C123456")
def test_resolves_uuid(self):
diff --git a/etna/records/tests/test_views.py b/etna/records/tests/test_views.py
index ac24edb72..2f9a668fc 100644
--- a/etna/records/tests/test_views.py
+++ b/etna/records/tests/test_views.py
@@ -33,10 +33,10 @@ def test_no_matches_respond_with_404(self):
response = self.client.get("/catalogue/ref/AD/2/2/")
- self.assertEquals(
+ self.assertEqual(
response.resolver_match.view_name, "details-page-human-readable"
)
- self.assertEquals(response.status_code, 404)
+ self.assertEqual(response.status_code, 404)
@responses.activate
def test_disambiguation_page_rendered_for_multiple_results(self):
@@ -53,7 +53,7 @@ def test_disambiguation_page_rendered_for_multiple_results(self):
response = self.client.get("/catalogue/ref/ADM/223/3/")
- self.assertEquals(
+ self.assertEqual(
response.resolver_match.view_name, "details-page-human-readable"
)
self.assertTemplateUsed(response, "records/record_disambiguation_page.html")
@@ -82,8 +82,8 @@ def test_rendering_deferred_to_details_page_view(self):
response = self.client.get("/catalogue/ref/ADM/223/3/", follow=False)
- self.assertEquals(response.status_code, 200)
- self.assertEquals(
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(
response.resolver_match.view_name, "details-page-human-readable"
)
self.assertTemplateUsed(response, "records/record_detail.html")
@@ -101,8 +101,8 @@ def test_no_matches_respond_with_404(self):
response = self.client.get("/catalogue/id/C123456/")
- self.assertEquals(response.status_code, 404)
- self.assertEquals(
+ self.assertEqual(response.status_code, 404)
+ self.assertEqual(
response.resolver_match.view_name, "details-page-machine-readable"
)
@@ -120,8 +120,8 @@ def test_record_rendered_for_single_result(self):
response = self.client.get("/catalogue/id/C123456/")
- self.assertEquals(response.status_code, 200)
- self.assertEquals(
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(
response.resolver_match.view_name, "details-page-machine-readable"
)
self.assertTemplateUsed(response, "records/record_detail.html")
@@ -149,8 +149,8 @@ def test_record_renders_for_record_with_no_image(self):
response = self.client.get("/catalogue/id/C123456/")
- self.assertEquals(response.status_code, 200)
- self.assertEquals(
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(
response.resolver_match.view_name, "details-page-machine-readable"
)
self.assertTemplateUsed(response, "records/record_detail.html")
@@ -190,7 +190,7 @@ def test_record_renders_for_record_with_image(self):
response = self.client.get("/catalogue/id/C123456/")
- self.assertEquals(response.status_code, 200)
+ self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, "records/record_detail.html")
self.assertTemplateUsed(response, "includes/records/image-viewer-panel.html")
@@ -213,8 +213,8 @@ def test_record_rendered_for_archive_record(self):
response = self.client.get("/catalogue/id/A13532479/")
- self.assertEquals(response.status_code, 200)
- self.assertEquals(
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(
response.resolver_match.view_name, "details-page-machine-readable"
)
self.assertTemplateUsed(response, "records/archive_detail.html")
@@ -255,8 +255,8 @@ def test_record_rendered_for_record_creators(self):
response = self.client.get("/catalogue/id/F74321/")
- self.assertEquals(response.status_code, 200)
- self.assertEquals(
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(
response.resolver_match.view_name, "details-page-machine-readable"
)
self.assertTemplateUsed(response, "records/record_creators.html")
@@ -451,7 +451,7 @@ class TestImageServeView(TestCase):
def test_no_location_404s(self):
response = self.client.get("/records/media/")
- self.assertEquals(response.status_code, 404)
+ self.assertEqual(response.status_code, 404)
@responses.activate
def test_404_response_from_client_api_is_forwarded(self):
@@ -463,8 +463,8 @@ def test_404_response_from_client_api_is_forwarded(self):
response = self.client.get("/records/image/missing/image.jpeg")
- self.assertEquals(response.status_code, 404)
- self.assertEquals(response.resolver_match.url_name, "image-serve")
+ self.assertEqual(response.status_code, 404)
+ self.assertEqual(response.resolver_match.url_name, "image-serve")
@responses.activate
def test_success(self):
@@ -478,8 +478,8 @@ def test_success(self):
response = self.client.get("/records/image/valid/path.jpg")
- self.assertEquals(response["content-type"], "image/jpeg")
- self.assertEquals(response.status_code, 200)
+ self.assertEqual(response["content-type"], "image/jpeg")
+ self.assertEqual(response.status_code, 200)
self.assertTrue(response.streaming)
@@ -500,8 +500,8 @@ def test_image_browse_non_digitised_record(self):
)
response = self.client.get("/records/images/C123456/")
- self.assertEquals(response.status_code, 404)
- self.assertEquals(response.resolver_match.url_name, "image-browse")
+ self.assertEqual(response.status_code, 404)
+ self.assertEqual(response.resolver_match.url_name, "image-browse")
@responses.activate
def test_image_browse_record_with_no_media(self):
@@ -518,8 +518,8 @@ def test_image_browse_record_with_no_media(self):
)
response = self.client.get("/records/images/C123456/")
- self.assertEquals(response.status_code, 404)
- self.assertEquals(response.resolver_match.url_name, "image-browse")
+ self.assertEqual(response.status_code, 404)
+ self.assertEqual(response.resolver_match.url_name, "image-browse")
@responses.activate
def test_success(self):
@@ -550,8 +550,8 @@ def test_success(self):
response = self.client.get("/records/images/C123456/")
- self.assertEquals(response.status_code, 200)
- self.assertEquals(response.resolver_match.url_name, "image-browse")
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(response.resolver_match.url_name, "image-browse")
@unittest.skip(
@@ -581,8 +581,8 @@ def test_image_browse_non_digitised_record(self):
)
response = self.client.get("/records/images/C123456/01/")
- self.assertEquals(response.status_code, 404)
- self.assertEquals(response.resolver_match.url_name, "image-viewer")
+ self.assertEqual(response.status_code, 404)
+ self.assertEqual(response.resolver_match.url_name, "image-viewer")
@responses.activate
def test_image_browse_record_with_no_media(self):
@@ -599,8 +599,8 @@ def test_image_browse_record_with_no_media(self):
)
response = self.client.get("/records/images/C123456/01/")
- self.assertEquals(response.status_code, 404)
- self.assertEquals(response.resolver_match.url_name, "image-viewer")
+ self.assertEqual(response.status_code, 404)
+ self.assertEqual(response.resolver_match.url_name, "image-viewer")
@responses.activate
def test_success(self):
@@ -633,13 +633,13 @@ def test_success(self):
response = self.client.get("/records/images/C123456/02/")
- self.assertEquals(response.status_code, 200)
- self.assertEquals(response.resolver_match.url_name, "image-viewer")
- self.assertEquals(
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(response.resolver_match.url_name, "image-viewer")
+ self.assertEqual(
response.context["previous_image"].location, "path/to/previous-image.jpeg"
)
- self.assertEquals(response.context["image"].location, "path/to/image.jpeg")
- self.assertEquals(
+ self.assertEqual(response.context["image"].location, "path/to/image.jpeg")
+ self.assertEqual(
response.context["next_image"].location, "path/to/next-image.jpeg"
)
@@ -667,13 +667,13 @@ def test_no_next_image(self):
response = self.client.get("/records/images/C123456/02/")
- self.assertEquals(response.status_code, 200)
- self.assertEquals(response.resolver_match.url_name, "image-viewer")
- self.assertEquals(
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(response.resolver_match.url_name, "image-viewer")
+ self.assertEqual(
response.context["previous_image"].location, "path/to/previous-image.jpeg"
)
- self.assertEquals(response.context["image"].location, "path/to/image.jpeg")
- self.assertEquals(response.context["next_image"], None)
+ self.assertEqual(response.context["image"].location, "path/to/image.jpeg")
+ self.assertEqual(response.context["next_image"], None)
@responses.activate
def test_no_previous_image(self):
@@ -699,11 +699,11 @@ def test_no_previous_image(self):
response = self.client.get("/records/images/C123456/01/")
- self.assertEquals(response.status_code, 200)
- self.assertEquals(response.resolver_match.url_name, "image-viewer")
- self.assertEquals(response.context["previous_image"], None)
- self.assertEquals(response.context["image"].location, "path/to/image.jpeg")
- self.assertEquals(
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(response.resolver_match.url_name, "image-viewer")
+ self.assertEqual(response.context["previous_image"], None)
+ self.assertEqual(response.context["image"].location, "path/to/image.jpeg")
+ self.assertEqual(
response.context["next_image"].location, "path/to/next-image.jpeg"
)
@@ -732,7 +732,7 @@ def test_previous_image_but_no_selected_image(self):
response = self.client.get("/records/images/C123456/02/")
- self.assertEquals(response.status_code, 404)
+ self.assertEqual(response.status_code, 404)
@responses.activate
def test_invalid_response_from_client_api_raises_404(self):
@@ -766,7 +766,7 @@ def test_invalid_response_from_client_api_raises_404(self):
response = self.client.get("/records/images/C123456/11000000000000000000/")
- self.assertEquals(response.status_code, 404)
+ self.assertEqual(response.status_code, 404)
class RecordDetailBackToSearchTest(TestCase):
From 8a206775516a0d5de0c509f626ad6575a5d41437 Mon Sep 17 00:00:00 2001
From: Andrew Hosgood
Date: Wed, 3 Jan 2024 12:27:36 +0000
Subject: [PATCH 2/5] Move to Python 3.12
---
.platform.app.yaml | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/.platform.app.yaml b/.platform.app.yaml
index 5ca341755..de53c2b9a 100644
--- a/.platform.app.yaml
+++ b/.platform.app.yaml
@@ -7,7 +7,7 @@ name: app
# in multiple versions. Check the Python documentation
# (https://docs.platform.sh/languages/python.html#supported-versions)
# to find the supported versions for the 'python' type.
-type: 'python:3.11'
+type: 'python:3.12'
variables:
env:
@@ -15,7 +15,7 @@ variables:
# pip
POETRY_VIRTUALENVS_IN_PROJECT: true
POETRY_VIRTUALENVS_CREATE: true
- POETRY_VERSION: 1.5.1
+ POETRY_VERSION: 1.6.1
# The size of the persistent disk of the application (in MB).
disk: 2048
@@ -35,7 +35,7 @@ hooks:
curl -sS https://platform.sh/cli/installer | php
# Download the latest version of pip
- python3.11 -m pip install --upgrade pip
+ python3.12 -m pip install --upgrade pip
# Install and configure Poetry
# Set user to false to install Poetry globally
From d381c716b1614b060a62285d1e9928ad6d003ca3 Mon Sep 17 00:00:00 2001
From: Andrew Hosgood
Date: Wed, 3 Jan 2024 12:37:20 +0000
Subject: [PATCH 3/5] Replace strtobool
---
config/settings/base.py | 2 +-
config/settings/dev.py | 2 +-
lib/util.py | 13 +++++++++++++
3 files changed, 15 insertions(+), 2 deletions(-)
create mode 100644 lib/util.py
diff --git a/config/settings/base.py b/config/settings/base.py
index f283fb3d7..d2c2af1b1 100644
--- a/config/settings/base.py
+++ b/config/settings/base.py
@@ -12,7 +12,7 @@
import os
from distutils.sysconfig import get_python_lib
-from distutils.util import strtobool
+from lib.util import strtobool
import sentry_sdk
diff --git a/config/settings/dev.py b/config/settings/dev.py
index 5be53a9f1..240560c12 100644
--- a/config/settings/dev.py
+++ b/config/settings/dev.py
@@ -1,7 +1,7 @@
import logging
import os
-from distutils.util import strtobool
+from lib.util import strtobool
from .base import * # noqa: F401
diff --git a/lib/util.py b/lib/util.py
new file mode 100644
index 000000000..2950dc476
--- /dev/null
+++ b/lib/util.py
@@ -0,0 +1,13 @@
+def strtobool(val):
+ """Convert a string representation of truth to true (1) or false (0).
+ True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values
+ are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if
+ 'val' is anything else.
+ """
+ val = val.lower()
+ if val in ("y", "yes", "t", "true", "on", "1"):
+ return 1
+ elif val in ("n", "no", "f", "false", "off", "0"):
+ return 0
+ else:
+ raise ValueError("invalid truth value %r" % (val,))
\ No newline at end of file
From 99cdb28af0d0830cb3425fd17121547843a6c526 Mon Sep 17 00:00:00 2001
From: Andrew Hosgood
Date: Wed, 3 Jan 2024 12:39:45 +0000
Subject: [PATCH 4/5] Formatting
---
config/settings/base.py | 3 ++-
lib/util.py | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/config/settings/base.py b/config/settings/base.py
index d2c2af1b1..11d8cf74e 100644
--- a/config/settings/base.py
+++ b/config/settings/base.py
@@ -12,12 +12,13 @@
import os
from distutils.sysconfig import get_python_lib
-from lib.util import strtobool
import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration
+from lib.util import strtobool
+
from ..versioning import get_git_sha
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
diff --git a/lib/util.py b/lib/util.py
index 2950dc476..7cfc966c6 100644
--- a/lib/util.py
+++ b/lib/util.py
@@ -10,4 +10,4 @@ def strtobool(val):
elif val in ("n", "no", "f", "false", "off", "0"):
return 0
else:
- raise ValueError("invalid truth value %r" % (val,))
\ No newline at end of file
+ raise ValueError("invalid truth value %r" % (val,))
From d36f39c976f196fd62bf59e2cc41f69d710d85a1 Mon Sep 17 00:00:00 2001
From: Andrew Hosgood
Date: Wed, 3 Jan 2024 12:56:15 +0000
Subject: [PATCH 5/5] Replace strtobool
---
config/settings/base.py | 7 +++----
config/settings/dev.py | 3 +--
{lib => config/settings}/util.py | 0
3 files changed, 4 insertions(+), 6 deletions(-)
rename {lib => config/settings}/util.py (100%)
diff --git a/config/settings/base.py b/config/settings/base.py
index 11d8cf74e..253cd65fa 100644
--- a/config/settings/base.py
+++ b/config/settings/base.py
@@ -11,15 +11,14 @@
"""
import os
-from distutils.sysconfig import get_python_lib
+from sysconfig import get_path
import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration
-from lib.util import strtobool
-
from ..versioning import get_git_sha
+from .util import strtobool
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@@ -111,7 +110,7 @@
"DIRS": [
os.path.join(BASE_DIR, "templates"),
os.path.join(
- get_python_lib(), "nationalarchives-frontend-django/templates"
+ get_path("platlib"), "nationalarchives-frontend-django/templates"
),
],
"APP_DIRS": True,
diff --git a/config/settings/dev.py b/config/settings/dev.py
index 240560c12..bce29c4b6 100644
--- a/config/settings/dev.py
+++ b/config/settings/dev.py
@@ -1,9 +1,8 @@
import logging
import os
-from lib.util import strtobool
-
from .base import * # noqa: F401
+from .util import strtobool
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = strtobool(os.getenv("DEBUG", "True")) # noqa: F405
diff --git a/lib/util.py b/config/settings/util.py
similarity index 100%
rename from lib/util.py
rename to config/settings/util.py