Skip to content

Commit b063d26

Browse files
committed
asdf
1 parent 02db127 commit b063d26

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ jobs:
131131
mamba list
132132
python -c "import qcelemental as q;print(q.__file__, q.__version__)"
133133
python -c "import qcengine as q;print(q.__file__, q.__version__)"
134+
git describe
134135
135136
- name: QCEngineRecords
136137
run: |

qcengine/programs/psi4.py

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,31 +51,46 @@ def found(raise_error: bool = False) -> bool:
5151
"""
5252
psithon = which("psi4", return_bool=True)
5353
psiapi = which_import("psi4", return_bool=True)
54+
error_msg = ""
55+
error_which = which
5456

5557
if psithon and not psiapi:
5658
with popen([which("psi4"), "--module"]) as exc:
5759
exc["proc"].wait(timeout=30)
5860
if "module does not exist" in exc["stderr"]:
59-
pass # --module argument only in Psi4 DDD branch
61+
psiapi = True # --module argument only in Psi4 DDD branch (or >=1.6) so grandfathered in
6062
else:
61-
sys.path.append(exc["stdout"].split()[-1])
63+
so, se = exc["stdout"], exc["stderr"]
64+
error_msg = f" In particular, psi4 command found but unable to load psi4 module into sys.path. stdout: {so}, stderr: {se}"
65+
error_which = which_import
66+
if (so) and (not se) and (exc["proc"].returncode == 0):
67+
psimod = Path(so.rstrip()) # stdout is string & Path is tolerant, so safe op
68+
if psimod.exists():
69+
sys.path.append(str(psimod))
70+
psiapi = which_import("psi4", return_bool=True)
6271

6372
if psiapi and not psithon:
64-
psiimport = str(Path(which_import("psi4")).parent.parent)
65-
env = os.environ.copy()
66-
env["PYTHONPATH"] = psiimport
67-
with popen(["python", "-c", "import psi4; print(psi4.executable[:-5])"], popen_kwargs={"env": env}) as exc:
73+
with popen(["python", "-c", "import psi4; print(psi4.executable)"]) as exc:
6874
exc["proc"].wait(timeout=30)
69-
os.environ["PATH"] += os.pathsep + exc["stdout"].split()[-1]
70-
71-
if psithon or psiapi:
75+
so, se = exc["stdout"], exc["stderr"]
76+
error_msg = f" In particular, psi4 module found but unable to load psi4 command into PATH. stdout: {so}, stderr: {se}"
77+
# yes, everthing up to here could be got from `import psi4; psiexe = psi4.executable`. but, we try not to
78+
# load programs/modules in the `def found` fns.
79+
if (so) and (not se) and (exc["proc"].returncode == 0):
80+
psiexe = Path(so.rstrip()) # stdout is string & Path is tolerant, so safe op
81+
if psiexe.exists():
82+
os.environ["PATH"] += os.pathsep + str(psiexe.parent)
83+
psithon = which("psi4", return_bool=True)
84+
85+
if psithon and psiapi:
7286
return True
7387

74-
return which(
88+
return error_which(
7589
"psi4",
7690
return_bool=True,
7791
raise_error=raise_error,
78-
raise_msg="Please install via `conda install psi4 -c psi4`. Check it's in your PATH with `which psi4`.",
92+
raise_msg="Please install via `conda install psi4 -c conda-forge/label/libint_dev -c conda-forge`. Check it's in your PATH with `which psi4`."
93+
+ error_msg,
7994
)
8095

8196
def get_version(self) -> str:
@@ -85,7 +100,9 @@ def get_version(self) -> str:
85100
if which_prog not in self.version_cache:
86101
with popen([which_prog, "--version"]) as exc:
87102
exc["proc"].wait(timeout=30)
88-
self.version_cache[which_prog] = safe_version(exc["stdout"].split()[-1])
103+
if (exc["proc"].returncode != 0) or exc["stderr"]:
104+
raise TypeError(f"Error {exc['proc'].returncode} retrieving Psi4 version: " + exc["stderr"])
105+
self.version_cache[which_prog] = safe_version(exc["stdout"].rstrip())
89106

90107
candidate_version = self.version_cache[which_prog]
91108

0 commit comments

Comments
 (0)