Skip to content

Commit e99d40e

Browse files
committed
Make the output reproducible
Whilst working on the Reproducible Builds effort [0] I noticed that sphinx-panels and sphinx-design do not create reproducible output. This is because it uses Python's uuid.uuid4 to generate unique identifiers, but those numbers are random/nondeterminstic by design. This patch will seed these random numbers from SOURCE_DATE_EPOCH if it exists, otherwise it will revert back to random numbers. I originally filed this in Debian as bug #1017475 [1], as well as within sphinx-panels [2] [0] https://reproducible-builds.org/ [1] https://bugs.debian.org/1017475 [2] executablebooks/sphinx-panels#82
1 parent f309aee commit e99d40e

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

sphinx_design/tabs.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
import os
2+
import random
3+
import time
4+
import uuid
5+
16
from typing import List
2-
from uuid import uuid4
37

48
from docutils import nodes
59
from docutils.parsers.rst import directives
@@ -12,6 +16,9 @@
1216

1317
LOGGER = getLogger(__name__)
1418

19+
rnd = random.Random()
20+
rnd.seed(os.environ.get("SOURCE_DATE_EPOCH", time.time()))
21+
1522

1623
def setup_tabs(app: Sphinx) -> None:
1724
app.add_directive("tab-set", TabSetDirective)
@@ -209,7 +216,7 @@ class TabSetHtmlTransform(SphinxPostTransform):
209216
formats = ("html",)
210217

211218
def get_unique_key(self):
212-
return str(uuid4())
219+
return uuid.UUID(int=rnd.getrandbits(128), version=4).hex
213220

214221
def run(self) -> None:
215222
"""Run the transform."""

0 commit comments

Comments
 (0)