From 71d665c47dfea1bf5aea9985caded825fba73abe 2022-06-16 21:01:10 From: Maxim Cournoyer Date: 2022-06-16 21:01:10 Subject: [PATCH] ipython_directive: Adjust doc examples for reproducibility. Before this change, building the documentation twice in a row in an environment configured for reproducible bulids would result in discrepancies such as: diff -ru /gnu/store/...-python-ipython-documentation-8.2.0/share/doc/python-ipython-documentation-8.2.0/html/sphinxext.html /gnu/store/...-python-ipython-documentation-8.2.0-check/share/doc/python-ipython-documentation-8.2.0/html/sphinxext.html --- /gnu/store/...-python-ipython-documentation-8.2.0/share/doc/python-ipython-documentation-8.2.0/html/sphinxext.html 1969-12-31 19:00:01.000000000 -0500 +++ /gnu/store/...-python-ipython-documentation-8.2.0-check/share/doc/python-ipython-documentation-8.2.0/html/sphinxext.html 1969-12-31 19:00:01.000000000 -0500 @@ -682,7 +682,7 @@ In [2]: import datetime ...: datetime.datetime.now() ...: -Out[2]: datetime.datetime(2022, 4, 17, 3, 21, 14, 978155) +Out[2]: datetime.datetime(2022, 4, 17, 3, 37, 37, 115081)

It supports IPython construct that plain @@ -690,7 +690,7 @@

In [3]: import time

    In [4]: %timeit time.sleep(0.05)
   -50.2 ms +- 104 us per loop (mean +- std. dev. of 7 runs, 10 loops each)
   +50.1 ms +- 8.86 us per loop (mean +- std. dev. of 7 runs, 10 loops each)
    

This will also support top-level async when using IPython 7.0+

* IPython/sphinxext/ipython_directive.py: Use a fixed date string in the datetime example, and replace the %timeit example by %pdoc, whole output is static. --- diff --git a/IPython/sphinxext/ipython_directive.py b/IPython/sphinxext/ipython_directive.py index b1f3931..9e3c7b2 100644 --- a/IPython/sphinxext/ipython_directive.py +++ b/IPython/sphinxext/ipython_directive.py @@ -19,7 +19,7 @@ Here is an example of how the IPython directive can In [1]: 1+1 In [1]: import datetime - ...: datetime.datetime.now() + ...: datetime.date.fromisoformat('2022-02-22') It supports IPython construct that plain Python does not understand (like magics): @@ -28,7 +28,7 @@ Python does not understand (like magics): In [0]: import time - In [0]: %timeit time.sleep(0.05) + In [0]: %pdoc time.sleep This will also support top-level async when using IPython 7.0+