Skip to content

Commit cbec059

Browse files
authored
Fix psi4 windows version detection (#426)
* print * split version * collapse * reset timeout * fix again * invert for consistency * Update docs/source/changelog.rst
1 parent 1a36ef7 commit cbec059

2 files changed

Lines changed: 20 additions & 9 deletions

File tree

docs/source/changelog.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ Changelog
2929
.. - UNSOLVED (:issue:`397`) extras failed
3030
3131
32+
v0.28.1 / 2023-08-18
33+
--------------------
34+
35+
Bug Fixes
36+
+++++++++
37+
- (:pr:`426`) Psi4 - fix ``get_version`` on Windows where whole path and command were getting passed to version parser. @loriab
38+
39+
3240
v0.28.0 / 2023-08-15
3341
--------------------
3442

qcengine/programs/psi4.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,24 +63,24 @@ def found(raise_error: bool = False) -> bool:
6363
if "module does not exist" in exc["stderr"]:
6464
psiapi = True # --module argument only in Psi4 DDD branch (or >=1.6) so grandfathered in
6565
else:
66-
so, se = exc["stdout"], exc["stderr"]
66+
so, se, rc = exc["stdout"].strip(), exc["stderr"], exc["proc"].returncode
6767
error_msg = f" In particular, psi4 command found but unable to load psi4 module into sys.path. stdout: {so}, stderr: {se}"
6868
error_which = which_import
69-
if (so) and (not se) and (exc["proc"].returncode == 0):
70-
psimod = Path(so.rstrip()) # stdout is string & Path is tolerant, so safe op
69+
if (so) and (not se) and (rc == 0):
70+
psimod = Path(so)
7171
if psimod.exists():
7272
sys.path.append(str(psimod))
7373
psiapi = which_import("psi4", return_bool=True)
7474

7575
if psiapi and not psithon:
7676
with popen(["python", "-c", "import psi4; print(psi4.executable)"]) as exc:
7777
exc["proc"].wait(timeout=30)
78-
so, se = exc["stdout"], exc["stderr"]
78+
so, se, rc = exc["stdout"].strip(), exc["stderr"], exc["proc"].returncode
7979
error_msg = f" In particular, psi4 module found but unable to load psi4 command into PATH. stdout: {so}, stderr: {se}"
8080
# yes, everthing up to here could be got from `import psi4; psiexe = psi4.executable`. but, we try not to
8181
# load programs/modules in the `def found` fns.
82-
if (so) and (not se) and (exc["proc"].returncode == 0):
83-
psiexe = Path(so.rstrip()) # stdout is string & Path is tolerant, so safe op
82+
if (so) and (not se) and (rc == 0):
83+
psiexe = Path(so)
8484
if psiexe.exists():
8585
os.environ["PATH"] += os.pathsep + str(psiexe.parent)
8686
psithon = which("psi4", return_bool=True)
@@ -103,9 +103,12 @@ def get_version(self) -> str:
103103
if which_prog not in self.version_cache:
104104
with popen([which_prog, "--version"]) as exc:
105105
exc["proc"].wait(timeout=30)
106-
if (exc["proc"].returncode != 0) or exc["stderr"]:
107-
raise TypeError(f"Error {exc['proc'].returncode} retrieving Psi4 version: " + exc["stderr"])
108-
self.version_cache[which_prog] = safe_version(exc["stdout"].rstrip())
106+
so, se, rc = exc["stdout"].strip(), exc["stderr"], exc["proc"].returncode
107+
if (so) and (not se) and (rc == 0):
108+
# Windows echos the command, so split stdout to collect response
109+
self.version_cache[which_prog] = safe_version(so.split()[-1])
110+
else:
111+
raise TypeError(f"Error {rc} retrieving Psi4 version: stdout: {so}, stderr: {se}")
109112

110113
candidate_version = self.version_cache[which_prog]
111114

0 commit comments

Comments
 (0)