From 3ffb82d550d3d0f2998dcf82aa0496bbd78cc77f Mon Sep 17 00:00:00 2001 From: ThatXliner Date: Fri, 22 Jan 2021 18:16:14 -0800 Subject: [PATCH 1/2] 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 --- userpath/core.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/userpath/core.py b/userpath/core.py index 86dc3c6..e5b0587 100644 --- a/userpath/core.py +++ b/userpath/core.py @@ -1,22 +1,30 @@ from .interface import Interface from .utils import in_current_path - +import os def prepend(location, app_name=None, shells=None, all_shells=False, home=None, check=False): + if isinstance(location, os.PathLike): + location = location.__fspath__() interface = Interface(shells=shells, all_shells=all_shells, home=home) return interface.put(location, front=True, app_name=app_name, check=check) def append(location, app_name=None, shells=None, all_shells=False, home=None, check=False): + if isinstance(location, os.PathLike): + location = location.__fspath__() interface = Interface(shells=shells, all_shells=all_shells, home=home) return interface.put(location, front=False, app_name=app_name, check=check) def in_new_path(location, shells=None, all_shells=False, home=None, check=False): + if isinstance(location, os.PathLike): + location = location.__fspath__() interface = Interface(shells=shells, all_shells=all_shells, home=home) return interface.location_in_new_path(location, check=check) def need_shell_restart(location, shells=None, all_shells=False, home=None): + if isinstance(location, os.PathLike): + location = location.__fspath__() interface = Interface(shells=shells, all_shells=all_shells, home=home) return not in_current_path(location) and interface.location_in_new_path(location) From 20be070c7a58ba9fea384ebb7966a31737ea481d Mon Sep 17 00:00:00 2001 From: Bryan Hu Date: Fri, 22 Jan 2021 18:33:00 -0800 Subject: [PATCH 2/2] Patched for python2 support --- userpath/core.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/userpath/core.py b/userpath/core.py index e5b0587..b647676 100644 --- a/userpath/core.py +++ b/userpath/core.py @@ -1,30 +1,29 @@ from .interface import Interface from .utils import in_current_path -import os def prepend(location, app_name=None, shells=None, all_shells=False, home=None, check=False): - if isinstance(location, os.PathLike): + if hasattr(location, "__fspath__"): location = location.__fspath__() interface = Interface(shells=shells, all_shells=all_shells, home=home) return interface.put(location, front=True, app_name=app_name, check=check) def append(location, app_name=None, shells=None, all_shells=False, home=None, check=False): - if isinstance(location, os.PathLike): + if hasattr(location, "__fspath__"): location = location.__fspath__() interface = Interface(shells=shells, all_shells=all_shells, home=home) return interface.put(location, front=False, app_name=app_name, check=check) def in_new_path(location, shells=None, all_shells=False, home=None, check=False): - if isinstance(location, os.PathLike): + if hasattr(location, "__fspath__"): location = location.__fspath__() interface = Interface(shells=shells, all_shells=all_shells, home=home) return interface.location_in_new_path(location, check=check) def need_shell_restart(location, shells=None, all_shells=False, home=None): - if isinstance(location, os.PathLike): + if hasattr(location, "__fspath__"): location = location.__fspath__() interface = Interface(shells=shells, all_shells=all_shells, home=home) return not in_current_path(location) and interface.location_in_new_path(location)