🌐 AI搜索 & 代理 主页
Skip to content

Commit 25eb8c5

Browse files
Added logic for creation of the baseline images
1 parent ddbdf89 commit 25eb8c5

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

lib/matplotlib/testing/decorators.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from pathlib import Path
77
import shutil
88
import string
9+
import subprocess
910
import sys
1011
import unittest
1112
import warnings
@@ -486,7 +487,7 @@ def _image_directories(func):
486487
try:
487488
import matplotlib_baseline_images
488489
except:
489-
raise ImportError("Not able to import matplotlib_baseline_images")
490+
generate_matplotlib_baseline_images_from_previous_commit()
490491
baseline_dir = (Path(matplotlib_baseline_images.__file__).parent /
491492
module_path.stem)
492493
elif func.__module__.startswith("mpl_toolkits."):
@@ -504,3 +505,23 @@ def _image_directories(func):
504505
result_dir = Path().resolve() / "result_images" / module_path.stem
505506
result_dir.mkdir(parents=True, exist_ok=True)
506507
return baseline_dir, result_dir
508+
509+
510+
def generate_matplotlib_baseline_images_from_previous_commit():
511+
# Check if current repository is a git repository
512+
subprocess.call(['git', '-C', '.' , 'status'],
513+
stderr=subprocess.STDOUT,
514+
stdout = open(os.devnull,
515+
'w')) == 0
516+
# Check that git is installed.
517+
subprocess.call(shutil.which('git'),
518+
stderr=subprocess.STDOUT,
519+
stdout = open(os.devnull,
520+
'w')) == 0
521+
# Create virtual env in tmpdir.
522+
subprocess.run([sys.executable, "-mvenv", tmpenv])
523+
subprocess.run(["git", "clone", "<current repo>", "<tmpenv/...>"])
524+
... git checkout HEAD~
525+
... python -mpytest ...
526+
# -> this will generate result_images in that temporary directory
527+
# -> copy it and cache it.

0 commit comments

Comments
 (0)