Commit ec01a2e1 authored by reisenho's avatar reisenho
Browse files

add is_relative_to to pathlib.Path, which is only available from python 3.9 onwards

No related merge requests found
Showing with 18 additions and 1 deletion
+18 -1
import inspect
import logging
from pathlib import Path
import string
import sys
import uuid
import inspect
import appdirs
try:
import coloredlogs
coloredlogs_available = True
......@@ -18,6 +21,19 @@ CORE_SERVICE_PATH = Path(__file__).parent / "services"
USER_SERVICE_PATH = Path(appdirs.user_data_dir("labc")) / "services"
if sys.version_info < (3,9):
"""
Add is_relative_to function to pathlib.Path class, which was only added in python 3.9
"""
def is_relative_to(self, *other):
try:
self.relative_to(*other)
return True
except ValueError:
return False
Path.is_relative_to = is_relative_to
del is_relative_to
def quantify_scope(scope: str):
if scope == "network":
return 3
......@@ -153,6 +169,7 @@ def escape_path(path):
"""
Return path relative to local path or replaces home with ~
"""
path = Path(path)
local_path = Path('.').absolute()
if path.is_relative_to(CORE_SERVICE_PATH):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment