Skip to content

Commit 2d49574

Browse files
committed
Fixed set_root_path() relative path
1 parent 298d8d2 commit 2d49574

6 files changed

Lines changed: 14 additions & 20 deletions

File tree

.github/workflows/tests.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ jobs:
1919

2020
steps:
2121
- uses: actions/checkout@v4
22-
- name: Set up Python 3.10
22+
- name: Set up Python 3.12
2323
uses: actions/setup-python@v3
2424
with:
25-
python-version: ">=3.10"
25+
python-version: ">=3.12"
2626
- name: Install dependencies
2727
run: |
2828
python -m pip install --upgrade pip
2929
pip install numpy
30+
pip install scipy
31+
pip install pydantic
3032
pip install flake8 pytest
3133
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
3234
- name: Lint with flake8

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727

2828
TOPLEVEL_DIR = pathlib.Path(__file__).parent.parent.absolute()
29-
ABOUT_FILE = TOPLEVEL_DIR / "pyAML" / "__init__.py"
29+
ABOUT_FILE = TOPLEVEL_DIR / "pyaml" / "__init__.py"
3030

3131
if str(TOPLEVEL_DIR) not in sys.path:
3232
sys.path.insert(0, str(TOPLEVEL_DIR))

pyaml/configuration/__init__.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ def set_root_folder(path: str | Path):
1111
"""
1212
Set the root path for configuration files.
1313
"""
14-
#ROOT["path"] = Path(path).resolve()
1514
ROOT["path"] = Path(path)
1615

1716

@@ -21,13 +20,5 @@ def get_root_folder() -> Path:
2120
"""
2221
return ROOT["path"]
2322

24-
25-
def get_config_file_path(path: str | Path) -> Path:
26-
"""Ensure the path is absolute and resolved."""
27-
path = Path(path)
28-
if not path.is_absolute():
29-
path = get_root_folder() / path
30-
return path.resolve()
31-
3223
from .fileloader import load
3324
from .factory import depthFirstBuild

pyaml/pyaml.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
from pydantic import BaseModel,ConfigDict
66
from .instrument import Instrument
77
from .configuration.factory import depthFirstBuild
8-
from pyaml.configuration import load
8+
from pyaml.configuration import load,set_root_folder
9+
import os
910

1011
# Define the main class name for this module
1112
PYAMLCLASS = "PyAML"
@@ -35,6 +36,10 @@ def pyaml(fileName:str) -> PyAML:
3536
"""Load an accelerator middle layer"""
3637

3738
# Asume that all files are referenced from folder where main AML file is stored
38-
aml_cfg = load(fileName)
39+
if not os.path.exists(fileName):
40+
raise Exception(f"{fileName} file nnot found")
41+
rootfolder = os.path.abspath(os.path.dirname(fileName))
42+
set_root_folder(rootfolder)
43+
aml_cfg = load(os.path.basename(fileName))
3944
aml:PyAML = depthFirstBuild(aml_cfg)
4045
return aml

tests/test_aml.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
from pyaml.pyaml import pyaml,PyAML
22
from pyaml.instrument import Instrument
3-
from pyaml.configuration import set_root_folder
43
import pyaml as pyaml_pkg
54
from pyaml.lattice.element_holder import MagnetType
65
from pyaml.magnet.model import MagnetModel
76
import at
87

98
#def test_aml(config_root_dir):
10-
set_root_folder("tests/config")
119

12-
ml:PyAML = pyaml("sr.yaml")
10+
ml:PyAML = pyaml("tests/config/sr.yaml")
1311
sr:Instrument = ml.get('sr')
1412
sr.design.get_lattice().disable_6d()
1513
sr.design.get_magnet(MagnetType.HCORRECTOR,"SH1A-C01-H").strength.set(0.000010)

tests/test_tune.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
from pyaml.pyaml import pyaml,PyAML
22
from pyaml.instrument import Instrument
3-
from pyaml.configuration import set_root_folder
43
import pyaml as pyaml_pkg
54
from pyaml.lattice.element_holder import MagnetType
65
from pyaml.arrays.magnet_array import MagnetArray
76
import numpy as np
87
import at
98

109
#def test_aml(config_root_dir):
11-
set_root_folder("tests/config")
1210

13-
ml:PyAML = pyaml("EBSTune.yaml")
11+
ml:PyAML = pyaml("tests/config/EBSTune.yaml")
1412
sr:Instrument = ml.get('sr')
1513
sr.design.get_lattice().disable_6d()
1614

0 commit comments

Comments
 (0)