From 7516128f17418b6844fc36d8641e746045e6bcbd Mon Sep 17 00:00:00 2001 From: David Date: Thu, 29 Feb 2024 23:42:18 +0100 Subject: [PATCH] Added custom "is_relative_to" function to support python versions below 3.9 --- saenopy/result_file.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/saenopy/result_file.py b/saenopy/result_file.py index 35d899d..7a78d20 100644 --- a/saenopy/result_file.py +++ b/saenopy/result_file.py @@ -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, @@ -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("..")