Skip to content

Commit

Permalink
Added custom "is_relative_to" function to support python versions bel…
Browse files Browse the repository at this point in the history
…ow 3.9
  • Loading branch information
davidbhr committed Feb 29, 2024
1 parent bfb73f8 commit 7516128
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion saenopy/result_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,16 @@ def common_start(values):
start = start[:-1]


def is_relative_to(path, base):
"""
Check if 'path' is relative to 'base'.
"""
try:
path.relative_to(base)
return True
except ValueError:
return False

def make_path_relative(filename, base):
"""
Returns the relative path of `filename` with respect to the `base` directory,
Expand All @@ -252,7 +262,7 @@ def make_path_relative(filename, base):

offset = ""
for i in range(3):
if file_path.is_relative_to(base_path):
if is_relative_to(file_path,base_path):
return str(offset / file_path.relative_to(base_path))
base_path = base_path.parent
offset /= PurePath("..")
Expand Down

0 comments on commit 7516128

Please sign in to comment.