From 19537141eb62c8630b78beec6ce90c813b5c5c9f Mon Sep 17 00:00:00 2001 From: Patrick Ogenstad Date: Fri, 20 Dec 2024 10:17:32 +0100 Subject: [PATCH] Fix import_root in case a Path object was submitted --- changelog/+513f19bc.fixed.md | 1 + infrahub_sdk/_importer.py | 4 ++++ 2 files changed, 5 insertions(+) create mode 100644 changelog/+513f19bc.fixed.md diff --git a/changelog/+513f19bc.fixed.md b/changelog/+513f19bc.fixed.md new file mode 100644 index 00000000..fe0fa1f6 --- /dev/null +++ b/changelog/+513f19bc.fixed.md @@ -0,0 +1 @@ +Convert import_root to a string if it was submitted as a Path object to ensure that anything added to sys.path is a string diff --git a/infrahub_sdk/_importer.py b/infrahub_sdk/_importer.py index 071388d6..fd45e254 100644 --- a/infrahub_sdk/_importer.py +++ b/infrahub_sdk/_importer.py @@ -22,6 +22,10 @@ def import_module( if import_root and relative_path: file_on_disk = Path(import_root, relative_path, module_path.name) + # This is a temporary workaround for to account for issues if "import_root" is a Path instead of a str + # Later we should rework this so that import_root and relative_path are all Path objects. Here we must + # ensure that anything we add to sys.path is a string and not a Path or PosixPath object. + import_root = str(import_root) if import_root not in sys.path: sys.path.append(import_root)