# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@octobus.net>
# Date 1660806965 -7200
#      Thu Aug 18 09:16:05 2022 +0200
# Node ID 01ac3c4109b71f52109e00a30728a2169f0a55e4
# Parent  04aef913328545630886d69be028c3297331b9d4
variants: factor the code to gather dimensions in the benchmarks class

This will help use to make this generic as we introduce more variants.

diff --git a/python-libs/poulpe/runner.py b/python-libs/poulpe/runner.py
--- a/python-libs/poulpe/runner.py
+++ b/python-libs/poulpe/runner.py
@@ -36,11 +36,7 @@
     def __init__(self, data, variants=None):
         super().__init__(data, variants)
 
-        l_1 = self._data.get('simple-command', {})
-        l_2 = l_1.get('variants', {})
-        all_dimensions = l_2.get('dimensions', {})
-
-        for dimension, variants in all_dimensions.items():
+        for dimension, variants in self.all_dimensions.items():
             # find the variants we should use.
             selected = self._selected_variants.get(dimension)
             if selected is None:
@@ -61,6 +57,13 @@
             if extend_command is not None:
                 self._data['simple-command']['command'] += extend_command
 
+    @property
+    def all_dimensions(self):
+        l_1 = self._data.get('simple-command', {})
+        l_2 = l_1.get('variants', {})
+        all_dimensions = l_2.get('dimensions', {})
+        return all_dimensions.copy()
+
 
 def get_benchmark(path_def):
     """get a benchmark from path applying possible variant selection on the way
diff --git a/scm-perf/poulpe-scheduler-bin/auto-cases b/scm-perf/poulpe-scheduler-bin/auto-cases
--- a/scm-perf/poulpe-scheduler-bin/auto-cases
+++ b/scm-perf/poulpe-scheduler-bin/auto-cases
@@ -14,6 +14,7 @@
 sys.path.insert(0, os.path.join(poulpe_root, 'python-libs'))
 
 import poulpe
+from poulpe import runner as runner_lib
 
 TARGET_PYTHON_VERSIONS = [
     "3.7"
@@ -123,11 +124,9 @@
     all_files = [Path(*p.parts[prefix:]) for p in bench_dir.rglob("*.pbd")]
     all_benchmarks = []
     for f in all_files:
-        data = poulpe.get_data(bench_dir / f)
-        l_1 = data.get('simple-command', {})
-        l_2 = l_1.get('variants', {})
+        benchmark = runner_lib.get_benchmark(bench_dir / f)
         all_dimensions = []
-        for d, v in l_2.get('dimensions', {}).items():
+        for d, v in benchmark.all_dimensions.items():
             all_dimensions.append([f'{d}={k}' for k in list(v.keys())])
         if not all_dimensions:
             all_benchmarks.append(f)