Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

verdi run: Do not add pathlib.Path instance to sys.path #5810

Merged
merged 1 commit into from
Dec 6, 2022

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented Nov 30, 2022

Fixes #5809

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.

Copy link
Member

@chrisjsewell chrisjsewell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also remove aiida/cmdline/commands/cmd_run.py from the mypy exclude list,
since the only error is:

mypy.....................................................................Failed
- hook id: mypy
- exit code: 1

aiida/cmdline/commands/cmd_run.py:31: error: Argument 1 to "append" of "list" has incompatible type "Path"; expected "str"  [arg-type]

A very good example of why to use type checking 😄

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`.
@sphuber sphuber merged commit b8ae8e8 into aiidateam:main Dec 6, 2022
@sphuber sphuber deleted the fix/5809/verdi-run-sys-path branch December 6, 2022 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Running script that imports tensorflow with verdi run excepts
2 participants