Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Meier, Moritz
labc
Commits
ec01a2e1
Commit
ec01a2e1
authored
1 year ago
by
reisenho
Browse files
Options
Download
Email Patches
Plain Diff
add is_relative_to to pathlib.Path, which is only available from python 3.9 onwards
parent
7514f897
remove_class_registry_dependency
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
labc/util/util.py
+18
-1
labc/util/util.py
with
18 additions
and
1 deletion
+18
-1
labc/util/util.py
+
18
-
1
View file @
ec01a2e1
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
):
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets