Source: sphinx-panels
Version: 0.6.0-2
Severity: wishlist
Tags: patch
User: reproducible-bui...@lists.alioth.debian.org
Usertags: randomness
X-Debbugs-Cc: reproducible-b...@lists.alioth.debian.org

Hi,

Whilst working on the Reproducible Builds effort [0] we noticed that
sphinx-panels could not be built reproducibly.

This is because it uses Python's uuid.uuid4 to generate unique
identifiers, but those numbers are random/nondeterminstic by design.
I've attached a patch that will seed these random numbers from
SOURCE_DATE_EPOCH if it exists, otherwise it will revert back to
random numbers.

  [0] https://reproducible-builds.org/


Regards,

-- 
      ,''`.
     : :'  :     Chris Lamb
     `. `'`      la...@debian.org / chris-lamb.co.uk
       `-
diff --git a/sphinx_panels/tabs.py b/sphinx_panels/tabs.py
index ac2a546..725a5f4 100644
--- a/sphinx_panels/tabs.py
+++ b/sphinx_panels/tabs.py
@@ -1,4 +1,8 @@
-from uuid import uuid4
+import os
+import random
+import time
+import uuid
+
 from typing import Optional
 
 from docutils import nodes
@@ -10,6 +14,9 @@ from sphinx.util.nodes import NodeMatcher
 
 LOGGER = getLogger(__name__)
 
+rnd = random.Random()
+rnd.seed(os.environ.get("SOURCE_DATE_EPOCH", time.time()))
+
 
 def setup_tabs(app):
     app.add_directive("tabbed", TabbedDirective)
@@ -122,7 +129,7 @@ class TabbedHtmlTransform(SphinxPostTransform):
     formats = ("html",)
 
     def get_unique_key(self):
-        return str(uuid4())
+        return uuid.UUID(int=rnd.getrandbits(128), version=4).hex
 
     def run(self):
         matcher = NodeMatcher(nodes.container, type="tabbed")

Reply via email to