Skip to content

Commit e4140bd

Browse files
committed
add conditions for windows paths
1 parent 35ac190 commit e4140bd

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

PyStemmusScope/utils.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,13 @@ def to_absolute_path(
4747
Returns:
4848
The input path that is an absolute path and a :py:class:`pathlib.Path` object.
4949
"""
50-
# care for windows, see issue 22
51-
must_exist = os_name() == 'nt'
5250

51+
must_exist = False
5352
pathlike = Path(input_path)
5453
if parent:
54+
if not parent.is_absolute():
55+
# care for windows, see issue 22
56+
must_exist = os_name() == 'nt'
5557
pathlike = parent.joinpath(pathlike)
5658
if must_be_in_parent:
5759
try:
@@ -60,5 +62,8 @@ def to_absolute_path(
6062
raise ValueError(
6163
f"Input path {input_path} is not a subpath of parent {parent}"
6264
) from exc
65+
else:
66+
# care for windows, see issue 22
67+
must_exist = os_name() == 'nt'
6368

6469
return pathlike.expanduser().resolve(strict=must_exist)

tests/test_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def test_to_absolute_path():
1414
expected = Path.home() / "nonexistent_file.txt"
1515
assert parsed == expected
1616

17+
1718
@patch("PyStemmusScope.utils.os_name")
1819
def test_to_absolute_path_must_exist(mocked_osname):
1920
input_path = "~/nonexistent_file.txt"

0 commit comments

Comments
 (0)