Skip to content

Commit f2983a5

Browse files
qianl15devhawk
andauthored
ensure entrypoint parent folder is in the module search path (#374) (#375)
[This SO answer](https://stackoverflow.com/a/62923810) provides good detail about the difference between launching a python file (aka `python app/main.py`) and launching a python module (aka `python -m widget_store.main`). In particular for this PR, launching a file automatically adds the file's parent directory to `sys.path` while launching a module adds the current directory. `dbos debug` was always ensuring the current directory (represented by empty string) was in `sys.path`, so it was failing when attempting to debug a file in a subdirectory. This code fixes that + isolates the change to `sys.path` to only happen for file launch. Module launch does not require `sys.path` changes because `dbos debug` is already launching in the debugger as a module so the current directory will already be on the path Co-authored-by: Harry Pierson <[email protected]>
1 parent 712285e commit f2983a5

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

dbos/_debug.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ def __init__(self, module_name: str):
1515

1616

1717
def debug_workflow(workflow_id: str, entrypoint: Union[str, PythonModule]) -> None:
18-
# include the current directory (represented by empty string) in the search path
19-
# if it not already included
20-
if "" not in sys.path:
21-
sys.path.insert(0, "")
2218
if isinstance(entrypoint, str):
19+
# ensure the entrypoint parent directory is in sys.path
20+
parent = str(Path(entrypoint).parent)
21+
if parent not in sys.path:
22+
sys.path.insert(0, parent)
2323
runpy.run_path(entrypoint)
2424
elif isinstance(entrypoint, PythonModule):
2525
runpy.run_module(entrypoint.module_name)

0 commit comments

Comments
 (0)