Skip to content

Commit

Permalink
feat(service): add support for any alone output import
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBelthle authored and laurent-laporte-pro committed Dec 19, 2023
1 parent 92b8917 commit ec59260
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def _import_study_output(
# `antarest.launcher.service.LauncherService._import_output`
return self.callbacks.import_output(
job_id,
self.local_workspace / STUDIES_OUTPUT_DIR_NAME / job_id / "output",
self.local_workspace / STUDIES_OUTPUT_DIR_NAME / job_id,
launcher_logs,
)

Expand Down
4 changes: 2 additions & 2 deletions antarest/launcher/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
)
from antarest.launcher.repository import JobResultRepository
from antarest.study.service import StudyService
from antarest.study.storage.utils import assert_permission, extract_output_name, find_single_output_path
from antarest.study.storage.utils import assert_permission, extract_output_name, retrieve_output_path

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -498,7 +498,7 @@ def _import_output(
job_launch_params = LauncherParametersDTO.parse_raw(job_result.launcher_params or "{}")

# this now can be a zip file instead of a directory !
output_true_path = find_single_output_path(output_path)
output_true_path = retrieve_output_path(output_path)
output_is_zipped = is_zip(output_true_path)
output_suffix = cast(
Optional[str],
Expand Down
9 changes: 0 additions & 9 deletions antarest/study/storage/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,6 @@ def fix_study_root(study_path: Path) -> None:
shutil.rmtree(sub_root_path)


def find_single_output_path(all_output_path: Path) -> Path:
children = os.listdir(all_output_path)
if len(children) == 1:
if children[0].endswith(".zip"):
return all_output_path / children[0]
return find_single_output_path(all_output_path / children[0])
return all_output_path


def retrieve_output_path(job_path: Path) -> Path:
inside_study_output_path = job_path / "output"
if job_path.exists() and len([file for file in os.listdir(str(job_path)) if ".zip" in file]) == 1:
Expand Down
8 changes: 4 additions & 4 deletions tests/launcher/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,9 +757,9 @@ def test_manage_output(self, tmp_path: Path) -> None:
),
]
with pytest.raises(JobNotFound):
launcher_service._import_output(job_id, output_path, {"out.log": [additional_log]})
launcher_service._import_output(job_id, tmp_path, {"out.log": [additional_log]})

launcher_service._import_output(job_id, output_path, {"out.log": [additional_log]})
launcher_service._import_output(job_id, tmp_path, {"out.log": [additional_log]})
assert not launcher_service._get_job_output_fallback_path(job_id).exists()
launcher_service.study_service.import_output.assert_called()

Expand Down Expand Up @@ -788,10 +788,10 @@ def test_manage_output(self, tmp_path: Path) -> None:
StudyNotFoundError(""),
]

assert launcher_service._import_output(job_id, output_path, {"out.log": [additional_log]}) is None
assert launcher_service._import_output(job_id, tmp_path, {"out.log": [additional_log]}) is None

(new_output_path / "info.antares-output").write_text(f"[general]\nmode=eco\nname=foo\ntimestamp={time.time()}")
output_name = launcher_service._import_output(job_id, output_path, {"out.log": [additional_log]})
output_name = launcher_service._import_output(job_id, tmp_path, {"out.log": [additional_log]})
assert output_name is not None
assert output_name.endswith("-hello")
assert launcher_service._get_job_output_fallback_path(job_id).exists()
Expand Down

0 comments on commit ec59260

Please sign in to comment.