|
1 | 1 | import hashlib |
2 | 2 | import subprocess |
3 | 3 | import threading |
| 4 | +from .sources import resolve_tutorial_root, PRECICE_EXTERNAL_CACHE_DIR |
4 | 5 | from typing import List, Dict, Optional, Tuple |
5 | 6 | from jinja2 import Environment, FileSystemLoader |
6 | 7 | from dataclasses import dataclass, field |
@@ -480,24 +481,36 @@ def __copy_tutorial_into_directory(self, run_directory: Path): |
480 | 481 | """ |
481 | 482 | current_time_string = datetime.now().strftime('%Y-%m-%d %H:%M:%S') |
482 | 483 | self.run_directory = run_directory |
483 | | - pr_requested = self.params_to_use.get("TUTORIALS_PR") |
484 | | - if pr_requested: |
485 | | - logging.debug(f"Fetching the PR {pr_requested} HEAD reference") |
486 | | - self._fetch_pr(PRECICE_TUTORIAL_DIR, pr_requested) |
487 | | - current_ref = self._get_git_ref(PRECICE_TUTORIAL_DIR) |
488 | | - ref_requested = self.params_to_use.get("TUTORIALS_REF") |
489 | | - if ref_requested: |
490 | | - logging.debug(f"Checking out tutorials {ref_requested} before copying") |
491 | | - self._fetch_ref(PRECICE_TUTORIAL_DIR, ref_requested) |
492 | | - self._checkout_ref_in_subfolder(PRECICE_TUTORIAL_DIR, self.tutorial.path, ref_requested) |
493 | | - |
494 | | - self.tutorial_folder = slugify(f'{self.tutorial.path.name}_{self.case_combination.cases}_{current_time_string}') |
| 484 | + current_ref = None |
| 485 | + ref_requested = None |
| 486 | + |
| 487 | + if self.tutorial.source.type == "local": |
| 488 | + pr_requested = self.params_to_use.get("TUTORIALS_PR") |
| 489 | + if pr_requested: |
| 490 | + logging.debug(f"Fetching the PR {pr_requested} HEAD reference") |
| 491 | + self._fetch_pr(PRECICE_TUTORIAL_DIR, pr_requested) |
| 492 | + current_ref = self._get_git_ref(PRECICE_TUTORIAL_DIR) |
| 493 | + ref_requested = self.params_to_use.get("TUTORIALS_REF") |
| 494 | + if ref_requested: |
| 495 | + logging.debug(f"Checking out tutorials {ref_requested} before copying") |
| 496 | + self._fetch_ref(PRECICE_TUTORIAL_DIR, ref_requested) |
| 497 | + self._checkout_ref_in_subfolder( |
| 498 | + PRECICE_TUTORIAL_DIR, self.tutorial.path, ref_requested) |
| 499 | + |
| 500 | + self.tutorial_folder = slugify( |
| 501 | + f'{self.tutorial.path.name}_{self.case_combination.cases}_{current_time_string}') |
495 | 502 | destination = run_directory / self.tutorial_folder |
496 | | - src = self.tutorial.path |
| 503 | + # External sources are fetched and resolved once at parse time; reuse |
| 504 | + # that path here to avoid a redundant fetch (and duplicate log line). |
| 505 | + src = self.tutorial.resolved_root or resolve_tutorial_root( |
| 506 | + self.tutorial.path, |
| 507 | + self.tutorial.source, |
| 508 | + PRECICE_EXTERNAL_CACHE_DIR, |
| 509 | + ) |
497 | 510 | self.system_test_dir = destination |
498 | 511 | shutil.copytree(src, destination) |
499 | 512 |
|
500 | | - if ref_requested: |
| 513 | + if self.tutorial.source.type == "local" and ref_requested: |
501 | 514 | with open(destination / "tutorials_ref", 'w') as file: |
502 | 515 | file.write(ref_requested) |
503 | 516 | self._checkout_ref_in_subfolder(PRECICE_TUTORIAL_DIR, self.tutorial.path, current_ref) |
@@ -971,7 +984,8 @@ def _run_tutorial(self): |
971 | 984 | return DockerComposeResult(exit_code, stdout_data, stderr_data, self, elapsed_time) |
972 | 985 |
|
973 | 986 | def __repr__(self): |
974 | | - return f"{self.tutorial.name} {self.case_combination}" |
| 987 | + prefix = "External: " if getattr(self.tutorial.source, "type", "local") != "local" else "" |
| 988 | + return f"{prefix}{self.tutorial.name} {self.case_combination}" |
975 | 989 |
|
976 | 990 | def __apply_max_time_override(self): |
977 | 991 | """Overwrite <max-time> or <max-time-windows> value in precice-config.xml.""" |
|
0 commit comments