mind-inria / mri-nufft

Doing non-Cartesian MR Imaging has never been so easy.
https://mind-inria.github.io/mri-nufft/
BSD 3-Clause "New" or "Revised" License
51 stars 10 forks source link

Prevent multiple runs for examples #183

Open chaithyagr opened 2 months ago

chaithyagr commented 2 months ago

Currently we run examples once with sphinx gallery and once with test-examples. This is mainly done to ensure our coverage is rightly reported. However, in practice the 2 can be done together.

A simple case:

import os
import coverage

# Start coverage collection
cov = coverage.Coverage()
cov.start()

# Sphinx configuration
extensions = [
    'sphinx.ext.autodoc',
    'sphinx.ext.napoleon',
    'sphinx_gallery.gen_gallery',
]

# Sphinx Gallery configuration
sphinx_gallery_conf = {
    'examples_dirs': 'examples',   # path to your example scripts
    'gallery_dirs': 'auto_examples',  # path where to save gallery generated output
    'filename_pattern': r'\.py',
    'run_stale_examples': True,  # Execute all examples even if they haven't changed
}

# Add a build-finished event to stop coverage and generate a report
def coverage_report(app, exception):
    cov.stop()
    cov.save()
    print("\nCoverage Summary:\n")
    cov.report()

def setup(app):
    app.connect('build-finished', coverage_report)

However, this is not trivial when we run examples in parallel. Some attempts was done in #181 but spawing an issue to track it separately,.

paquiteau commented 2 months ago

this was done in #181

chaithyagr commented 2 months ago

Umm, no it wasnt. In fact, as I told, attempts were made, but some issues occurred...