From e690af77fc7a4c32d62a29163014995fcb0c3726 Mon Sep 17 00:00:00 2001 From: Laurie Nevay Date: Sat, 4 Jan 2025 11:06:55 +0100 Subject: [PATCH 1/5] Ignore pycharm directory. --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 80f5a99..59da8e3 100644 --- a/.gitignore +++ b/.gitignore @@ -160,4 +160,4 @@ cython_debug/ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. -#.idea/ +.idea/ From 8ed676df0e0e5cf47ce3f9b7bc19efd065002a14 Mon Sep 17 00:00:00 2001 From: Laurie Nevay Date: Sat, 4 Jan 2025 11:09:38 +0100 Subject: [PATCH 2/5] Build a list of files available dynamically. Docstring for class. --- src/g4edgetestdata/core.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/g4edgetestdata/core.py b/src/g4edgetestdata/core.py index 6bac64d..0211e1e 100644 --- a/src/g4edgetestdata/core.py +++ b/src/g4edgetestdata/core.py @@ -12,12 +12,26 @@ class G4EdgeTestData: + """ + Class to access all test data. Data can be accessed via the path using the + [] operator. A full list of available files (built dynamically) is given in + the member `files`. + + >>> d = G4EdgeTestData() + >>> d.files + ['convert/T001_geant4Box2Fluka.gdml', + 'convert/T001_geant4Box2Fluka.inp', + 'convert/T001_geant4Box2Fluka_baked.inp', + ... + >>> abs_path = d['convert/T001_geant4Box2Fluka.inp'] + """ def __init__(self): self._default_git_ref = "main" self._repo_path = Path( os.getenv("G4EDGE_TESTDATA", gettempdir() + "/g4edge-testdata-" + getuser()) ) self._repo: Repo = self._init_testdata_repo() + self._build_list_of_available_data() def _init_testdata_repo(self) -> None: if not self._repo_path.is_dir(): @@ -64,3 +78,17 @@ def __getitem__(self, filename: str | Path) -> Path: raise FileNotFoundError(msg) return full_path + + def _build_list_of_available_data(self): + """ + Build a list of all available data dynamically. From python 3.12 we could use + `Path.walk`, but we use down to 3.7, therefore use the `os.walk` method instead. + """ + self.files = [] + root = Path(self._repo_path / "data") + for dirpath, dirnames, filenames in os.walk(root): + for f in filenames: + common = os.path.relpath(dirpath, root) + rp = os.path.join(common, f) + self.files.append(rp) + self.files = sorted(self.files) From 1b290c3cb2d65fcf806b1c0c6818f85e577b2c0c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 4 Jan 2025 10:11:24 +0000 Subject: [PATCH 3/5] style: pre-commit fixes --- src/g4edgetestdata/core.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/g4edgetestdata/core.py b/src/g4edgetestdata/core.py index 0211e1e..18aec64 100644 --- a/src/g4edgetestdata/core.py +++ b/src/g4edgetestdata/core.py @@ -25,6 +25,7 @@ class G4EdgeTestData: ... >>> abs_path = d['convert/T001_geant4Box2Fluka.inp'] """ + def __init__(self): self._default_git_ref = "main" self._repo_path = Path( @@ -86,7 +87,7 @@ def _build_list_of_available_data(self): """ self.files = [] root = Path(self._repo_path / "data") - for dirpath, dirnames, filenames in os.walk(root): + for dirpath, _dirnames, filenames in os.walk(root): for f in filenames: common = os.path.relpath(dirpath, root) rp = os.path.join(common, f) From 4d166aaf42c0b3ee12ce90220f425c04f72f410c Mon Sep 17 00:00:00 2001 From: Laurie Nevay Date: Sat, 4 Jan 2025 11:14:51 +0100 Subject: [PATCH 4/5] Ruff demans more complex implementation. --- src/g4edgetestdata/core.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/g4edgetestdata/core.py b/src/g4edgetestdata/core.py index 0211e1e..2debee0 100644 --- a/src/g4edgetestdata/core.py +++ b/src/g4edgetestdata/core.py @@ -4,6 +4,7 @@ import os from getpass import getuser from pathlib import Path +from pathlib import PurePath from tempfile import gettempdir from git import GitCommandError, InvalidGitRepositoryError, Repo @@ -89,6 +90,6 @@ def _build_list_of_available_data(self): for dirpath, dirnames, filenames in os.walk(root): for f in filenames: common = os.path.relpath(dirpath, root) - rp = os.path.join(common, f) - self.files.append(rp) + rp = PurePath(common) / f + self.files.append(str(rp)) self.files = sorted(self.files) From 17039bf2ae7913c3766f59fd01f8208160294f15 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 4 Jan 2025 10:15:12 +0000 Subject: [PATCH 5/5] style: pre-commit fixes --- src/g4edgetestdata/core.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/g4edgetestdata/core.py b/src/g4edgetestdata/core.py index 4eed846..204f9c6 100644 --- a/src/g4edgetestdata/core.py +++ b/src/g4edgetestdata/core.py @@ -3,8 +3,7 @@ import logging import os from getpass import getuser -from pathlib import Path -from pathlib import PurePath +from pathlib import Path, PurePath from tempfile import gettempdir from git import GitCommandError, InvalidGitRepositoryError, Repo