From 2bed8c8b00a1ed1cde9aad6205d27e0ad7cf8e97 Mon Sep 17 00:00:00 2001 From: Roman Kuzmenko Date: Thu, 15 Aug 2024 08:59:30 -0700 Subject: [PATCH] Fixed paths on Windows --- partcad/src/partcad/context.py | 10 ++++++---- partcad/src/partcad/runtime_python_conda.py | 13 ++++++++++++- partcad/src/partcad/utils.py | 7 +++++-- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/partcad/src/partcad/context.py b/partcad/src/partcad/context.py index 4a9491c..862ad58 100644 --- a/partcad/src/partcad/context.py +++ b/partcad/src/partcad/context.py @@ -89,7 +89,7 @@ def __init__(self, root_path=None, search_root=True): self.current_project_path += os.path.relpath( initial_root_path, root_path, - ) + ).replace(os.path.sep, "/") if self.current_project_path == self.name + "/.": self.current_project_path = self.name @@ -205,6 +205,10 @@ def import_project(self, parent, project_import_config): return imported_project def get_project_abs_path(self, rel_project_path: str): + """ + Get the full package path (not a filesystem path) of a package + given the relative path from the current package + """ if rel_project_path.startswith("/"): return rel_project_path @@ -215,9 +219,7 @@ def get_project_abs_path(self, rel_project_path: str): if rel_project_path == "": return project_path - if not project_path.endswith("/"): - project_path += "/" - return os.path.abspath(project_path + rel_project_path) + return get_child_project_path(project_path, rel_project_path) def get_project(self, rel_project_path: str): project_path = self.get_project_abs_path(rel_project_path) diff --git a/partcad/src/partcad/runtime_python_conda.py b/partcad/src/partcad/runtime_python_conda.py index 861b33b..0474f3b 100644 --- a/partcad/src/partcad/runtime_python_conda.py +++ b/partcad/src/partcad/runtime_python_conda.py @@ -32,9 +32,20 @@ def __init__(self, ctx, version=None): root_prefix = info["root_prefix"] root_bin = os.path.join(root_prefix, "bin") root_scripts = os.path.join(root_prefix, "Scripts") + search_paths = [ + root_scripts, + root_bin, + root_prefix, + ] + if os.name == "nt": + search_path_strings = ";".join(search_paths) + else: + search_path_strings = ":".join(search_paths) self.conda_path = shutil.which( - "conda", path=f"{root_scripts}:{root_bin}:{root_prefix}" + "conda", + path=search_path_strings, ) + pc_logging.error("Conda path corrected: %s" % self.conda_path) async def run(self, cmd, stdin="", cwd=None): with self.lock: diff --git a/partcad/src/partcad/utils.py b/partcad/src/partcad/utils.py index 1d7f7cc..3bb658a 100644 --- a/partcad/src/partcad/utils.py +++ b/partcad/src/partcad/utils.py @@ -22,9 +22,12 @@ def get_child_project_path(parent_path, child_name): if parent_path.endswith("/"): - return parent_path + child_name + result = parent_path + child_name else: - return parent_path + "/" + child_name + result = parent_path + "/" + child_name + + result = re.sub(r"/[^/]*/\.\.", "", result) + return result def resolve_resource_path(current_project_name, pattern: str):