Skip to content

Commit ef03b22

Browse files
authored
Merge pull request #108 from python-accelerator-middle-layer/absolute-path-support
Modifications for absolute path
2 parents ff48f25 + 3c3acb3 commit ef03b22

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

pyaml/configuration/csvcurve.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from pydantic import BaseModel, ConfigDict
55

66
from ..common.exception import PyAMLException
7-
from ..configuration import get_root_folder
7+
from ..configuration.fileloader import get_path
88
from .curve import Curve
99

1010
# Define the main class name for this module
@@ -27,7 +27,7 @@ def __init__(self, cfg: ConfigModel):
2727
self._cfg = cfg
2828

2929
# Load CSV curve
30-
path: Path = get_root_folder() / cfg.file
30+
path = get_path(cfg.file)
3131
try:
3232
self._curve = np.genfromtxt(path, delimiter=",", dtype=float, loose=False)
3333
except ValueError as e:

pyaml/configuration/csvmatrix.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from pydantic import BaseModel, ConfigDict
55

66
from ..common.exception import PyAMLException
7-
from ..configuration import get_root_folder
7+
from ..configuration.fileloader import get_path
88
from .matrix import Matrix
99

1010
# Define the main class name for this module
@@ -26,7 +26,7 @@ class CSVMatrix(Matrix):
2626
def __init__(self, cfg: ConfigModel):
2727
self._cfg = cfg
2828
# Load CSV matrix
29-
path: Path = get_root_folder() / cfg.file
29+
path = get_path(cfg.file)
3030
try:
3131
self._mat = np.genfromtxt(path, delimiter=",", dtype=float, loose=False)
3232
except ValueError as e:

pyaml/configuration/fileloader.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import io
44
import json
55
import logging
6+
import os
67
from pathlib import Path
78
from typing import TYPE_CHECKING, Union
89

@@ -41,6 +42,18 @@ def get_root_folder() -> Path:
4142
return ROOT["path"]
4243

4344

45+
def get_path(p: Path) -> Path:
46+
"""
47+
Return unchanged input path if it is an absolute path,
48+
path relative to root folder otherwise.
49+
"""
50+
if os.path.isabs(p):
51+
return p
52+
else:
53+
root = get_root_folder()
54+
return root / p
55+
56+
4457
class PyAMLConfigCyclingException(PyAMLException):
4558
def __init__(self, error_filename: str, path_stack: list[Path]):
4659
self.error_filename = error_filename
@@ -78,7 +91,7 @@ def hasToExpand(value):
7891
# Loader base class (nested files expansion)
7992
class Loader:
8093
def __init__(self, filename: str, parent_path_stack: list[Path]):
81-
self.path: Path = get_root_folder() / filename
94+
self.path: Path = get_path(filename)
8295
self.files_stack: list[Path] = []
8396
if parent_path_stack:
8497
if any(

0 commit comments

Comments
 (0)