Skip to content

Commit 29844a9

Browse files
committed
Properly add the fucntion to fix holoscan init file.
Signed-off-by: M Q <mingmelvinq@nvidia.com>
1 parent 1145c15 commit 29844a9

File tree

2 files changed

+56
-46
lines changed

2 files changed

+56
-46
lines changed

monai/deploy/utils/importutil.py

Lines changed: 52 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -341,42 +341,6 @@ def dist_requires(project_name: str) -> List[str]:
341341
return []
342342

343343

344-
if __name__ == "__main__":
345-
"""Utility functions that can be used in the command line."""
346-
347-
argv = sys.argv
348-
if len(argv) == 3 and argv[1] == "is_dist_editable":
349-
if is_dist_editable(argv[2]):
350-
sys.exit(0)
351-
else:
352-
sys.exit(1)
353-
if len(argv) == 3 and argv[1] == "dist_module_path":
354-
module_path = dist_module_path(argv[2])
355-
if module_path:
356-
print(module_path)
357-
sys.exit(0)
358-
else:
359-
sys.exit(1)
360-
if len(argv) == 3 and argv[1] == "is_module_installed":
361-
is_installed = is_module_installed(argv[2])
362-
if is_installed:
363-
sys.exit(0)
364-
else:
365-
sys.exit(1)
366-
if len(argv) == 3 and argv[1] == "dist_requires":
367-
requires = dist_requires(argv[2])
368-
if requires:
369-
print("\n".join(requires))
370-
sys.exit(0)
371-
else:
372-
sys.exit(1)
373-
if len(argv) >= 3 and argv[1] == "get_package_info":
374-
import json
375-
376-
app = get_application(argv[2])
377-
if app:
378-
print(json.dumps(app.get_package_info(argv[3] if len(argv) > 3 else ""), indent=2))
379-
380344
holoscan_init_content_txt = """
381345
# SPDX-FileCopyrightText: Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
382346
# SPDX-License-Identifier: Apache-2.0
@@ -435,9 +399,56 @@ def __getattr__(name):
435399
def fix_holoscan_import():
436400
"""Fix holoscan __init__ to enable lazy load for avoiding failure on loading low level libs."""
437401

438-
holoscan_package_name = "holoscan"
439-
holoscan_package_path = dist_module_path(holoscan_package_name)
440-
holoscan_core_init_path = Path(holoscan_package_path) / holoscan_package_name / "__init__.py"
402+
try:
403+
project_name = "holoscan"
404+
holoscan_init_path = Path(dist_module_path(project_name)) / project_name / "__ini__.py"
405+
406+
with open(str(holoscan_init_path), "w") as f_w:
407+
f_w.write(holoscan_init_content_txt)
408+
return str(holoscan_init_path)
409+
except Exception as ex:
410+
return ex
411+
441412

442-
with open(holoscan_core_init_path, "w") as f_w:
443-
f_w.write(holoscan_init_content_txt)
413+
if __name__ == "__main__":
414+
"""Utility functions that can be used in the command line."""
415+
416+
argv = sys.argv
417+
if len(argv) == 2 and argv[1] == "fix_holoscan_import":
418+
file_path = fix_holoscan_import()
419+
if file_path:
420+
print(file_path)
421+
sys.exit(0)
422+
else:
423+
sys.exit(1)
424+
if len(argv) == 3 and argv[1] == "is_dist_editable":
425+
if is_dist_editable(argv[2]):
426+
sys.exit(0)
427+
else:
428+
sys.exit(1)
429+
if len(argv) == 3 and argv[1] == "dist_module_path":
430+
module_path = dist_module_path(argv[2])
431+
if module_path:
432+
print(module_path)
433+
sys.exit(0)
434+
else:
435+
sys.exit(1)
436+
if len(argv) == 3 and argv[1] == "is_module_installed":
437+
is_installed = is_module_installed(argv[2])
438+
if is_installed:
439+
sys.exit(0)
440+
else:
441+
sys.exit(1)
442+
if len(argv) == 3 and argv[1] == "dist_requires":
443+
requires = dist_requires(argv[2])
444+
if requires:
445+
print("\n".join(requires))
446+
sys.exit(0)
447+
else:
448+
sys.exit(1)
449+
if len(argv) >= 3 and argv[1] == "get_package_info":
450+
import json
451+
452+
app = get_application(argv[2])
453+
if app:
454+
print(json.dumps(app.get_package_info(argv[3] if len(argv) > 3 else ""), indent=2))

run

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,18 +325,17 @@ install_python_dev_deps() {
325325
exit 1
326326
fi
327327

328-
install_edit_mode
329-
330328
# Adding temp fix to address the issue of holoscan sdk dragging in low level dependencies, e.g. libcuda.so
331329
fix_holoscan_import
330+
331+
install_edit_mode
332332
}
333333

334334
fix_holoscan_import() {
335335
local holoscan_package_path=$(${MONAI_PY_EXE} $TOP/monai/deploy/utils/importutil.py dist_module_path holoscan)
336336
c_echo b "holoscan_package_path : " Z "${holoscan_package_path}"
337-
c_echo b "fixing holoscan package module import..."
338-
${MONAI_PY_EXE} $TOP/monai/deploy/utils/importutil.py fix_holoscan_import
339-
c_echo b "done fixing."
337+
init_file_path=$(${MONAI_PY_EXE} $TOP/monai/deploy/utils/importutil.py fix_holoscan_import)
338+
c_echo b "done fixing file: " Z "${init_file_path}"
340339
}
341340

342341
install_edit_mode() {

0 commit comments

Comments
 (0)