Skip to content

Commit

Permalink
Merge branch 'main' into fix/hq_cpu_memory
Browse files Browse the repository at this point in the history
  • Loading branch information
superstar54 authored Jan 14, 2025
2 parents c9ea81d + 969ba0e commit 381ea42
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ aiidalab_qe.app.parameters = qeapp.yaml
aiidalab_qe.app.static.styles = *.css
aiidalab_qe.app.static.templates = *.jinja
aiidalab_qe.app.structure.examples = *
aiidalab_qe.app.result.components.summary = schema.json
aiidalab_qe.plugins.xas = pseudo_toc.yaml
aiidalab_qe.plugins.xps.structure_examples = *
aiidalab_qe.plugins.xas.structure_examples = *
Expand Down
46 changes: 37 additions & 9 deletions src/aiidalab_qe/setup/codes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import subprocess
from pathlib import Path
from shutil import which
Expand Down Expand Up @@ -44,18 +45,45 @@ def get_qe_env():


def qe_installed():
import json
"""Check if Quantum Espresso (QE) is installed in the specified conda environment.
env_exist = get_qe_env().exists()
proc = subprocess.run(
["conda", "list", "-n", f"{get_qe_env().name}", "--json", "--full-name", "qe"],
check=True,
capture_output=True,
)
Returns:
bool: True if the environment exists and QE is installed; False otherwise.
"""
try:
# Verify if the specified conda environment exists
env_exist = get_qe_env().exists()

if not env_exist:
return False

# Run the conda list command to check for the QE package
proc = subprocess.run(
[
"conda",
"list",
"-n",
f"{get_qe_env().name}",
"--json",
"--full-name",
"qe",
],
check=True,
capture_output=True,
)

info = json.loads(str(proc.stdout.decode()))[0]
# Load and interpret the JSON output
info = json.loads(proc.stdout.decode())

return env_exist and "qe" == info["name"]
# Check if 'qe' is listed in the environment
for package in info:
if package.get("name") == "qe":
return True
return False # noqa: TRY300
except Exception as error:
raise RuntimeError(
"Failed to check if Quantum Espresso is installed."
) from error


def install_qe():
Expand Down

0 comments on commit 381ea42

Please sign in to comment.