浏览代码

Fixed importing of o3de package modules within the o3de.py script when a relative path is used to invoke it

lumberyard-employee-dm 4 年之前
父节点
当前提交
1a95b96985
共有 1 个文件被更改,包括 15 次插入7 次删除
  1. 15 7
      scripts/o3de.py

+ 15 - 7
scripts/o3de.py

@@ -27,18 +27,26 @@ def add_args(parser, subparsers) -> None:
     # As o3de.py shares the same name as the o3de package attempting to use a regular
     # As o3de.py shares the same name as the o3de package attempting to use a regular
     # from o3de import <module> line tries to import from the current o3de.py script and not the package
     # from o3de import <module> line tries to import from the current o3de.py script and not the package
     # So the current script directory is removed from the sys.path temporary
     # So the current script directory is removed from the sys.path temporary
-    SCRIPT_DIR_REMOVED = False
-    SCRIPT_DIR = pathlib.Path(__file__).parent.resolve()
-    while str(SCRIPT_DIR) in sys.path:
-        SCRIPT_DIR_REMOVED = True
-        sys.path.remove(str(SCRIPT_DIR))
+    script_dir_removed = False
+    script_abs_dir_removed = False
+    script_dir = pathlib.Path(__file__).parent
+    script_abs_dir = pathlib.Path(__file__).parent.resolve()
+    while str(script_dir) in sys.path:
+        script_dir_removed = True
+        sys.path.remove(str(script_dir))
+    while str(script_abs_dir) in sys.path:
+        script_abs_dir_removed = True
+        # Remove the absolute path to the script_dir as well
+        sys.path.remove(str(script_abs_dir.resolve()))
 
 
     from o3de import engine_template, global_project, register, print_registration, get_registration, download, \
     from o3de import engine_template, global_project, register, print_registration, get_registration, download, \
         add_external_subdirectory, remove_external_subdirectory, add_gem_cmake, remove_gem_cmake, add_gem_project, \
         add_external_subdirectory, remove_external_subdirectory, add_gem_cmake, remove_gem_cmake, add_gem_project, \
         remove_gem_project, sha256
         remove_gem_project, sha256
 
 
-    if SCRIPT_DIR_REMOVED:
-        sys.path.insert(0, str(SCRIPT_DIR))
+    if script_abs_dir_removed:
+        sys.path.insert(0, str(script_abs_dir))
+    if script_dir_removed:
+        sys.path.insert(0, str(script_dir))
 
 
     # global_project
     # global_project
     global_project.add_args(subparsers)
     global_project.add_args(subparsers)