Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/jade/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import jade.resources as res
from jade import resources
from jade.app.fetch import fetch_f4e_inputs, fetch_iaea_inputs
from jade.app.fetch import fetch_f4e_inputs, fetch_iaea_inputs, fetch_nonIAEA_exp_data
from jade.config.paths_tree import PathsTree
from jade.config.pp_config import PostProcessConfig
from jade.config.raw_config import ConfigRawProcessor
Expand Down Expand Up @@ -91,18 +91,24 @@ def update_inputs(self):

This will re-fetch inputs from the various repositories that feed JADE.
"""
# install IAEA inputs and experimental data
success = fetch_iaea_inputs(
self.tree.benchmark_input_templates, self.tree.exp_data
)
if not success:
logging.error("Failed to update the IAEA benchmark inputs.")

# Install F4E exp data
success = fetch_nonIAEA_exp_data(self.tree.exp_data)
if not success:
logging.error("Failed to update the F4E experimental data.")

# Install F4E inputs
f4e_gitlab_token = os.getenv("F4E_GITLAB_TOKEN")

if f4e_gitlab_token is not None:
success = fetch_f4e_inputs(
self.tree.benchmark_input_templates,
self.tree.exp_data,
f4e_gitlab_token,
)
if not success:
Expand Down
65 changes: 51 additions & 14 deletions src/jade/app/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

from jade.helper.aux_functions import PathLike

BRANCH = "main" # TODO change in main once merged the PR
IAEA_URL = f"https://github.com/IAEA-NDS/open-benchmarks/archive/{BRANCH}.zip"
IAEA_URL = r"https://github.com/IAEA-NDS/open-benchmarks/archive/main.zip"
RAW_DATA_GITHUB_URL = r"https://github.com/JADE-V-V/JADE-RAW-RESULTS/archive/main.zip"


def _fetch_from_git(
Expand Down Expand Up @@ -128,14 +128,23 @@ def _install_standard_folder_structure(
exp_data_root: PathLike,
path_to_inputs: str | os.PathLike,
path_to_exp_data: str | os.PathLike,
only_exp_data: bool = False,
only_inputs: bool = False,
) -> bool:
if isinstance(extracted_folder, bool):
return False

for fetched_folder, install_folder in [
(path_to_inputs, inputs_root),
(path_to_exp_data, exp_data_root),
]:
if only_exp_data:
to_install = [(path_to_exp_data, exp_data_root)]
elif only_inputs:
to_install = [(path_to_inputs, inputs_root)]
else:
to_install = [
(path_to_inputs, inputs_root),
(path_to_exp_data, exp_data_root),
]

for fetched_folder, install_folder in to_install:
_install_data(fetched_folder, install_folder)

# Once done, delete the src folder
Expand Down Expand Up @@ -175,19 +184,15 @@ def fetch_iaea_inputs(inputs_root: PathLike, exp_data_root: PathLike) -> bool:
return success


def fetch_f4e_inputs(
inputs_root: PathLike, exp_data_root: PathLike, access_token: str
) -> bool:
"""Fetch F4E benchmark inputs and experimental data and copy them to
def fetch_f4e_inputs(inputs_root: PathLike, access_token: str) -> bool:
"""Fetch F4E benchmark inputs and copy them to
the correct folder in jade structure. This will always override the available
data.

Parameters
----------
inputs_root : PathLike
path to the root folder where the inputs will be stored.
exp_data_root : PathLike
path to the root folder where the experimental data will be stored.
access_token : str
Authorization token to access the F4E GitLab.

Expand All @@ -207,11 +212,43 @@ def fetch_f4e_inputs(
if not isinstance(extracted_folder, PathLike): # anything else that went wrong
return False
Comment on lines 212 to 213
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

find . -name "aux_functions.py" -type f

Repository: JADE-V-V/JADE

Length of output: 91


🏁 Script executed:

cat -n ./src/jade/helper/aux_functions.py | head -100

Repository: JADE-V-V/JADE

Length of output: 3264


🏁 Script executed:

sed -n '205,220p' ./src/jade/app/fetch.py

Repository: JADE-V-V/JADE

Length of output: 577


🏁 Script executed:

head -50 ./src/jade/app/fetch.py | grep -E "import|PathLike"

Repository: JADE-V-V/JADE

Length of output: 285


isinstance() check with PathLike will fail at runtime.

Line 212 uses isinstance(extracted_folder, PathLike) where PathLike is defined as Union[str, os.PathLike, Path] in jade.helper.aux_functions (line 16). Type aliases cannot be used with isinstance()—it requires a class or tuple of classes. At runtime, this will raise TypeError: isinstance() arg 2 must be a type, a tuple of types, or a union.

Replace with a runtime check like: isinstance(extracted_folder, (str, os.PathLike, Path)) or use a helper function to validate the type.

🤖 Prompt for AI Agents
In src/jade/app/fetch.py around lines 212 to 213, the
isinstance(extracted_folder, PathLike) call uses a type-alias PathLike (defined
as Union[str, os.PathLike, Path]) which will raise TypeError at runtime; replace
that check with a runtime-valid type check such as isinstance(extracted_folder,
(str, os.PathLike, Path)) or call a small helper validator that explicitly
checks for str, os.PathLike, or pathlib.Path and return False when it doesn't
match.

path_to_inputs = Path(extracted_folder, "inputs")

success = _install_standard_folder_structure(
extracted_folder,
inputs_root,
"",
path_to_inputs,
"",
only_inputs=True,
)
return success


def fetch_nonIAEA_exp_data(exp_data_root: PathLike) -> bool:
"""Fetch non IAEA benchmark experimental data and copy them to
the correct folder in jade structure. This will always override the available
data.

Parameters
----------
exp_data_root : PathLike
path to the root folder where the experimental data will be stored.

Returns
-------
bool
True if the experimental data were successfully fetched, False otherwise.
"""
extracted_folder = str(
_fetch_from_git(RAW_DATA_GITHUB_URL)
) # no token required anymore

path_to_exp_data = Path(
extracted_folder,
"exp_results",
"ROOT",
"_exp_-_exp_",
)
success = _install_standard_folder_structure(
extracted_folder, inputs_root, exp_data_root, path_to_inputs, path_to_exp_data
extracted_folder, "", exp_data_root, "", path_to_exp_data, only_exp_data=True
)
return success
1 change: 0 additions & 1 deletion src/jade/utilities.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import argparse

from jade.app.app import JadeApp
from jade.helper.aux_functions import add_rmode0


def main():
Expand Down
25 changes: 17 additions & 8 deletions tests/app/test_fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pytest

from jade.app.fetch import fetch_f4e_inputs, fetch_iaea_inputs
from jade.app.fetch import fetch_f4e_inputs, fetch_iaea_inputs, fetch_nonIAEA_exp_data

# By default this should set the token to None if not found
F4E_GITLAB_TOKEN = os.getenv("F4E_GITLAB_TOKEN")
Expand Down Expand Up @@ -46,27 +46,36 @@ def test_wrong_fetch_f4e_inputs(tmpdir):
test also the overwriting"""
# test correct fetching in an empty folder
inp_path = tmpdir.mkdir("inputs")
exp_path = tmpdir.mkdir("exp")
success = fetch_f4e_inputs(inp_path, exp_path, access_token="wrongtoken")
success = fetch_f4e_inputs(inp_path, access_token="wrongtoken")
assert not success


@pytest.mark.skipif(
F4E_GITLAB_TOKEN is None or os.environ.get("GITHUB_ACTIONS") == "true",
reason="No token found or running on GitHub CI"
reason="No token found or running on GitHub CI",
)
def test_fetch_f4e_inputs(tmpdir):
assert F4E_GITLAB_TOKEN is not None
# test correct fetching in an empty folder
inp_path = tmpdir.mkdir("inputs")
exp_path = tmpdir.mkdir("exp")
success = fetch_f4e_inputs(inp_path, exp_path, F4E_GITLAB_TOKEN)
success = fetch_f4e_inputs(inp_path, F4E_GITLAB_TOKEN)
assert success
assert len(os.listdir(inp_path)) > 0
assert len(os.listdir(exp_path)) > 0

# test that there no problems when the folder is not empty
success = fetch_f4e_inputs(inp_path, exp_path, F4E_GITLAB_TOKEN)
success = fetch_f4e_inputs(inp_path, F4E_GITLAB_TOKEN)
assert success
assert len(os.listdir(inp_path)) > 0


def test_fetch_f4e_exp_data(tmpdir):
""" " Test that experimental data can be correctly fetched from the F4E GitLab."""
exp_path = tmpdir.mkdir("exp")
success = fetch_nonIAEA_exp_data(exp_path)
assert success
assert len(os.listdir(exp_path)) > 0

# test that there no problems when the folder is not empty
success = fetch_nonIAEA_exp_data(exp_path)
assert success
assert len(os.listdir(exp_path)) > 0