Skip to content

Commit 3ffb82d

Browse files
authored
Added support for os.PathLike
For support for pathlib.Path or anything that supports the interface. See https://docs.python.org/3.8/library/os.html#os.PathLike
1 parent fb29f5a commit 3ffb82d

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

userpath/core.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
11
from .interface import Interface
22
from .utils import in_current_path
3-
3+
import os
44

55
def prepend(location, app_name=None, shells=None, all_shells=False, home=None, check=False):
6+
if isinstance(location, os.PathLike):
7+
location = location.__fspath__()
68
interface = Interface(shells=shells, all_shells=all_shells, home=home)
79
return interface.put(location, front=True, app_name=app_name, check=check)
810

911

1012
def append(location, app_name=None, shells=None, all_shells=False, home=None, check=False):
13+
if isinstance(location, os.PathLike):
14+
location = location.__fspath__()
1115
interface = Interface(shells=shells, all_shells=all_shells, home=home)
1216
return interface.put(location, front=False, app_name=app_name, check=check)
1317

1418

1519
def in_new_path(location, shells=None, all_shells=False, home=None, check=False):
20+
if isinstance(location, os.PathLike):
21+
location = location.__fspath__()
1622
interface = Interface(shells=shells, all_shells=all_shells, home=home)
1723
return interface.location_in_new_path(location, check=check)
1824

1925

2026
def need_shell_restart(location, shells=None, all_shells=False, home=None):
27+
if isinstance(location, os.PathLike):
28+
location = location.__fspath__()
2129
interface = Interface(shells=shells, all_shells=all_shells, home=home)
2230
return not in_current_path(location) and interface.location_in_new_path(location)

0 commit comments

Comments
 (0)