Skip to content

Commit db59ec9

Browse files
committed
removed walkup as it is unstable
1 parent 827a887 commit db59ec9

File tree

2 files changed

+20
-38
lines changed

2 files changed

+20
-38
lines changed

RATapi/project.py

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import warnings
88
from enum import Enum
99
from pathlib import Path
10-
from sys import version_info
1110
from textwrap import indent
1211
from typing import Annotated, Any, Callable, Union
1312

@@ -972,28 +971,15 @@ def try_relative_to(path: Path, relative_to: Path) -> Path:
972971
abs_path = Path(path).resolve()
973972
abs_base = Path(relative_to).resolve()
974973

975-
# 'walking up' paths is only added in Python 3.12
976-
if version_info.minor < 12:
977-
try:
978-
relative_path = abs_path.relative_to(abs_base)
979-
except ValueError as err:
980-
warnings.warn(
981-
"Could not save a custom file path as relative to the project directory. "
982-
"This may mean the project may not open on other devices. "
983-
f"Error message: {err}",
984-
stacklevel=2,
985-
)
986-
return abs_path
987-
else:
988-
try:
989-
relative_path = abs_path.relative_to(abs_base, walk_up=True)
990-
except ValueError as err:
991-
warnings.warn(
992-
"Could not save a custom file path as relative to the project directory. "
993-
"This may mean the project may not open on other devices. "
994-
f"Error message: {err}",
995-
stacklevel=2,
996-
)
997-
return abs_path
974+
try:
975+
relative_path = abs_path.relative_to(abs_base)
976+
except ValueError:
977+
warnings.warn(
978+
"Could not save custom file path as relative to the project directory. "
979+
"To ensure that your project works on other devices, make sure your custom files "
980+
"are in a subfolder of the project save location.",
981+
stacklevel=2,
982+
)
983+
return abs_path
998984

999985
return relative_path

tests/test_project.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import tempfile
55
import warnings
66
from pathlib import Path
7-
from sys import version_info
87
from typing import Callable
98

109
import numpy as np
@@ -1574,7 +1573,7 @@ def test_save_load(project, request):
15741573

15751574

15761575
def test_relative_paths():
1577-
"""Test that ``try_relative_to`` correctly creates relative paths."""
1576+
"""Test that ``try_relative_to`` correctly creates relative paths to subfolders."""
15781577

15791578
with tempfile.TemporaryDirectory() as tmp:
15801579
data_path = Path(tmp, "data/myfile.dat")
@@ -1583,19 +1582,16 @@ def test_relative_paths():
15831582

15841583

15851584
def test_relative_paths_version():
1586-
"""Test that we only walk up paths on Python 3.12 or greater."""
1585+
"""Test that we get a warning for trying to walk up paths."""
15871586

15881587
data_path = "/tmp/project/data/mydata.dat"
15891588
relative_path = "/tmp/project/project_path/myproj.dat"
15901589

1591-
if version_info.minor >= 12:
1592-
with warnings.catch_warnings():
1593-
warnings.simplefilter("error")
1594-
assert RATapi.project.try_relative_to(data_path, relative_path) == Path("../../data/mydata.dat")
1595-
else:
1596-
with pytest.warns(
1597-
match="Could not save a custom file path as relative to the project directory. "
1598-
"This may mean the project may not open on other devices. "
1599-
"Error message:"
1600-
):
1601-
assert RATapi.project.try_relative_to(data_path, relative_path) == Path("/tmp/project/data/mydata.dat")
1590+
with pytest.warns(
1591+
match="Could not save custom file path as relative to the project directory. "
1592+
"To ensure that your project works on other devices, make sure your custom files "
1593+
"are in a subfolder of the project save location."
1594+
):
1595+
assert (
1596+
RATapi.project.try_relative_to(data_path, relative_path) == Path("/tmp/project/data/mydata.dat").resolve()
1597+
)

0 commit comments

Comments
 (0)