Source: gamera
Version: 3.4.1+svn1423-4
Severity: wishlist
Tags: patch
User: reproducible-builds@lists.alioth.debian.org
Usertags: randomness

Hi!

While working on the “reproducible builds” effort [1], we have noticed
that gamera could not be built reproducibly.

The example/documentation images generated during the build depend
on random values, which are seeded with the current system time.
The attached patch fixes this by seeding the PRNG with a fixed value.
Once applied, gamera can be built reproducibly in our current
experimental framework.

Regards,
 Reiner

 [1]: https://wiki.debian.org/ReproducibleBuilds

diff --git a/debian/changelog b/debian/changelog
index fb15c4f..724e6c6 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+gamera (3.4.1+svn1423-4.0~reproducible1) UNRELEASED; urgency=low
+
+  * Added patch to make build reproducible by using constant seed
+    for generation of example/documentation images.
+
+ -- Reiner Herrmann <rei...@reiner-h.de>  Mon, 12 Jan 2015 20:04:17 +0100
+
 gamera (3.4.1+svn1423-4) unstable; urgency=medium
 
   * Upload to unstable.
diff --git a/debian/patches/constant_seed_for_docs.diff b/debian/patches/constant_seed_for_docs.diff
new file mode 100644
index 0000000..e07cff9
--- /dev/null
+++ b/debian/patches/constant_seed_for_docs.diff
@@ -0,0 +1,87 @@
+Author: Reiner Herrmann <rei...@reiner-h.de>
+Description: use constant seed for example images
+ Importing random will seed the prng with the current system time,
+ which will produce different example images on every build.
+ To make the build reproducible, use a constant seed value.
+
+Index: gamera-3.4.1+svn1423/gamera/plugins/draw.py
+===================================================================
+--- gamera-3.4.1+svn1423.orig/gamera/plugins/draw.py
++++ gamera-3.4.1+svn1423/gamera/plugins/draw.py
+@@ -61,8 +61,9 @@ class draw_marker(PluginFunction):
+   author = "Michael Droettboom"
+ 
+   def __doc_example1__(images):
+-    from random import randint
++    from random import randint, seed
+     from gamera.core import Image, Dim
++    seed(0)
+     image = Image((0, 0), Dim(100, 100), RGB, DENSE)
+     points = [(randint(0, 100), randint(0, 100)) for x in range(4)]
+     image.draw_bezier(*tuple(list(points) + [RGBPixel(255, 0, 0), 0.1]))
+@@ -106,8 +107,9 @@ class draw_line(PluginFunction):
+   __call__ = staticmethod(__call__)
+ 
+   def __doc_example1__(images):
+-    from random import randint
++    from random import randint, seed
+     from gamera.core import Image, Dim
++    seed(0)
+     image = Image((0, 0), Dim(100, 100), RGB, DENSE)
+     for i in range(10):
+       image.draw_line((randint(0, 100), randint(0, 100)),
+@@ -160,8 +162,9 @@ class draw_hollow_rect(PluginFunction):
+   __call__ = staticmethod(__call__)
+ 
+   def __doc_example1__(images):
+-    from random import randint
++    from random import randint, seed
+     from gamera.core import Image, Dim
++    seed(0)
+     image = Image((0, 0), Dim(100, 100), RGB, DENSE)
+     for i in range(10):
+       image.draw_hollow_rect((randint(0, 100), randint(0, 100)),
+@@ -199,8 +202,9 @@ class draw_filled_rect(PluginFunction):
+   __call__ = staticmethod(__call__)
+ 
+   def __doc_example1__(images):
+-    from random import randint
++    from random import randint, seed
+     from gamera.core import Image, Dim
++    seed(0)
+     image = Image((0, 0), Dim(100, 100), RGB, DENSE)
+     for i in range(10):
+       image.draw_filled_rect((randint(0, 100), randint(0, 100)),
+@@ -244,8 +248,9 @@ class draw_bezier(PluginFunction):
+   __call__ = staticmethod(__call__)
+ 
+   def __doc_example1__(images):
+-    from random import randint
++    from random import randint, seed
+     from gamera.core import Image, Dim
++    seed(0)
+     image = Image((0, 0), Dim(100, 100), RGB, DENSE)
+     for i in range(10):
+       image.draw_bezier((randint(0, 100), randint(0, 100)),
+@@ -292,8 +297,9 @@ class draw_circle(PluginFunction):
+   __call__ = staticmethod(__call__)
+ 
+   def __doc_example1__(images):
+-    from random import randint
++    from random import randint, seed
+     from gamera.core import Image, Dim
++    seed(0)
+     image = Image((0, 0), Dim(100, 100), RGB, DENSE)
+     for i in range(10):
+       image.draw_circle((randint(0, 100), randint(0, 100)),
+@@ -447,8 +453,9 @@ class draw_text(PluginFunction):
+   __call__ = staticmethod(__call__)
+ 
+   def __doc_example1__(images):
+-    from random import randint
++    from random import randint, seed
+     from gamera.core import Image, Dim
++    seed(0)
+     image = Image((0, 0), Dim(320, 300), RGB, DENSE)
+ 
+     # These are some various Unicode encoded names of different
diff --git a/debian/patches/series b/debian/patches/series
index 235e76b..c8bb80a 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -11,3 +11,4 @@ trap-errors-from-pclose.diff
 fix-typos.diff
 avoid_mktemp.diff
 gendoc-version-parsing.diff
+constant_seed_for_docs.diff

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Reproducible-builds mailing list
Reproducible-builds@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/reproducible-builds

Reply via email to