Skip to content

Commit

Permalink
verdi run: Do not add pathlib.Path instance to sys.path (#5810)
Browse files Browse the repository at this point in the history
The `verdi run` command updates `sys.path` to include the current
working directory such that modules in it can be imported by the script
being run. However, it was using `pathlib` to get the CWD and was adding
a `Path` instance to the path, which should only contain `str`
instances. This was uncovered by trying to import `tensorflow` which
also manipulates the `sys.path` and was raising an error since it was
trying to iterate over all elements and `pathlib.Path` is not iterable,
unlike `str`.
  • Loading branch information
sphuber authored Dec 6, 2022
1 parent 7aa183b commit b8ae8e8
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 2 deletions.
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ repos:
aiida/cmdline/commands/cmd_devel.py|
aiida/cmdline/commands/cmd_group.py|
aiida/cmdline/commands/cmd_node.py|
aiida/cmdline/commands/cmd_run.py|
aiida/cmdline/commands/cmd_shell.py|
aiida/cmdline/commands/cmd_storage.py|
aiida/cmdline/groups/dynamic.py|
Expand Down
2 changes: 1 addition & 1 deletion aiida/cmdline/commands/cmd_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def update_environment(argv):
_argv = sys.argv[:]

# Add the current working directory to the path, such that local modules can be imported
sys.path.append(pathlib.Path.cwd().resolve())
sys.path.append(str(pathlib.Path.cwd().resolve()))
sys.argv = argv[:]
yield
finally:
Expand Down

0 comments on commit b8ae8e8

Please sign in to comment.