Package: python3-distro-info
Followup-For: Bug #1085112

Please find attached an updated patch that conforms to the package's 'black'
code formatting guidelines, and with an amended commit message to automatically
close this bug.
>From 24c9745003936b48af856aecc075e0b366e44c87 Mon Sep 17 00:00:00 2001
From: James Addison <j...@jp-hosting.net>
Date: Mon, 14 Oct 2024 21:10:32 +0100
Subject: [PATCH] python: add release filtering by SOURCE_DATE_EPOCH

Closes: #1085112
---
 python/distro_info.py                       |  6 +++++-
 python/distro_info_test/test_distro_info.py | 17 +++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/python/distro_info.py b/python/distro_info.py
index 34f1299..5822580 100644
--- a/python/distro_info.py
+++ b/python/distro_info.py
@@ -124,7 +124,11 @@ class DistroInfo:
                     _get_date(row, "eol-server"),
                 )
                 self._releases.append(release)
-        self._date = datetime.date.today()
+        source_date_epoch = os.environ.get("SOURCE_DATE_EPOCH")
+        if source_date_epoch is not None:
+            self._date = datetime.date.fromtimestamp(int(source_date_epoch))
+        else:
+            self._date = datetime.date.today()
 
     @property
     def all(self) -> list[str]:
diff --git a/python/distro_info_test/test_distro_info.py 
b/python/distro_info_test/test_distro_info.py
index b9e1cc1..abab592 100644
--- a/python/distro_info_test/test_distro_info.py
+++ b/python/distro_info_test/test_distro_info.py
@@ -18,6 +18,7 @@
 
 import datetime
 import unittest
+from unittest.mock import patch
 
 from distro_info import DebianDistroInfo, UbuntuDistroInfo
 
@@ -91,6 +92,14 @@ class DebianDistroInfoTestCase(unittest.TestCase):  # 
pylint: disable=too-many-p
         unsupported = ["buzz", "rex", "bo", "hamm", "slink", "potato", 
"woody", "sarge", "etch"]
         self.assertEqual(self._distro_info.unsupported(self._date), 
unsupported)
 
+    @patch.dict("os.environ", {"SOURCE_DATE_EPOCH": "1500000000"})
+    def test_date_filtering(self) -> None:
+        """Test: filter supported Debian releases based on build date"""
+        supported = ["jessie", "stretch", "buster", "sid", "experimental"]
+
+        distro_info = DebianDistroInfo()
+        self.assertEqual(distro_info.supported(), supported)
+
     def test_codename(self) -> None:
         """Test: Codename decoding"""
         self.assertIsNone(self._distro_info.codename("foobar"))
@@ -171,6 +180,14 @@ class UbuntuDistroInfoTestCase(unittest.TestCase):  # 
pylint: disable=too-many-p
         unsupported = ["warty", "hoary", "breezy", "edgy", "feisty", "gutsy", 
"intrepid", "jaunty"]
         self.assertEqual(self._distro_info.unsupported(self._date), 
unsupported)
 
+    @patch.dict("os.environ", {"SOURCE_DATE_EPOCH": "1500000000"})
+    def test_date_filtering(self) -> None:
+        """Test: filter supported Ubuntu releases based on build date"""
+        supported = ["trusty", "xenial", "yakkety", "zesty", "artful"]
+
+        distro_info = UbuntuDistroInfo()
+        self.assertEqual(distro_info.supported(), supported)
+
     def test_current_unsupported(self) -> None:
         """Test: List all unsupported Ubuntu distributions today."""
         unsupported = {"warty", "hoary", "breezy", "edgy", "feisty", "gutsy", 
"intrepid", "jaunty"}
-- 
2.45.2

Reply via email to