Skip to content

Commit 57b1b72

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

File tree

2 files changed

+21
-36
lines changed

2 files changed

+21
-36
lines changed

RATapi/project.py

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -972,28 +972,15 @@ def try_relative_to(path: Path, relative_to: Path) -> Path:
972972
abs_path = Path(path).resolve()
973973
abs_base = Path(relative_to).resolve()
974974

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
975+
try:
976+
relative_path = abs_path.relative_to(abs_base)
977+
except ValueError:
978+
warnings.warn(
979+
"Could not save custom file path as relative to the project directory. "
980+
"To ensure that your project works on other devices, make sure your custom files "
981+
"are in a subfolder of the project save location.",
982+
stacklevel=2,
983+
)
984+
return abs_path
998985

999986
return relative_path

tests/test_project.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,7 +1574,7 @@ def test_save_load(project, request):
15741574

15751575

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

15791579
with tempfile.TemporaryDirectory() as tmp:
15801580
data_path = Path(tmp, "data/myfile.dat")
@@ -1583,19 +1583,17 @@ def test_relative_paths():
15831583

15841584

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

15881588
data_path = "/tmp/project/data/mydata.dat"
15891589
relative_path = "/tmp/project/project_path/myproj.dat"
15901590

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")
1591+
with pytest.warns(
1592+
match="Could not save custom file path as relative to the project directory. "
1593+
"To ensure that your project works on other devices, make sure your custom files "
1594+
"are in a subfolder of the project save location."
1595+
):
1596+
assert (
1597+
RATapi.project.try_relative_to(data_path, relative_path)
1598+
== Path("/tmp/project/data/mydata.dat").resolve()
1599+
)

0 commit comments

Comments
 (0)