From 1052daada7770a3974f0fccbe95bec9fe0e7cce7 Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Tue, 13 Jun 2023 17:38:37 -0600 Subject: [PATCH 1/3] Check pyiron installation Current checks implemented: - executable bit is set for shell scripts - conda package is installed These can be executed using: ``` import pyiron_base pyiron_base.check_executables_status() ``` Which returns a pandas dataframe with all executables pyiron found. --- pyiron_base/__init__.py | 1 + pyiron_base/state/check.py | 70 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 pyiron_base/state/check.py diff --git a/pyiron_base/__init__.py b/pyiron_base/__init__.py index 7407b524f..13b9159b2 100644 --- a/pyiron_base/__init__.py +++ b/pyiron_base/__init__.py @@ -39,6 +39,7 @@ from pyiron_base.jobs.job.extension.server.queuestatus import validate_que_request from pyiron_base.state.settings import Settings from pyiron_base.state.install import install_dialog +from pyiron_base.state.check import check_executables_status from pyiron_base.jobs.datamining import PyironTable, TableJob from pyiron_base.interfaces.object import HasDatabase, HasStorage, PyironObject from pyiron_base.database.performance import get_database_statistics diff --git a/pyiron_base/state/check.py b/pyiron_base/state/check.py new file mode 100644 index 000000000..38a40b45c --- /dev/null +++ b/pyiron_base/state/check.py @@ -0,0 +1,70 @@ +import os +import stat +import glob +import pandas + +try: + from conda.cli import python_api + conda_imported_successful = True +except ImportError: + conda_imported_successful = False + +from pyiron_base import state + +conda_package_dict = { + "mlip": "mlip", + "atomicrex": "atomicrex", + "damask": "damask", + "runner": "runner", + "randspg": "randspg", + "sphinx": "sphinxdft", + "lammps": "lammps" +} + + +def check_for_conda_package(name): + lst = [l for l in python_api.run_command("list")[0].split("\n") if name + " " in l] + if len(lst) == 0: + return False + else: + return True + + +def check_executable_bit(resource_paths): + def check_bit(script_path): + filemode = os.stat(script_path).st_mode + return bool(filemode & stat.S_IXUSR or filemode & stat.S_IXGRP or filemode & stat.S_IXOTH) + + path_lst = [] + for res_path in resource_paths: + path_lst += glob.glob(res_path + "/*/*/*.sh") + return {p: check_bit(script_path=p) for p in path_lst} + + +def check_executables_status(): + executables_dict = check_executable_bit( + resource_paths=state.settings.configuration['resource_paths'] + ) + if conda_imported_successful: + conda_lst = [ + check_for_conda_package(name=conda_package_dict[f]) + if f is not None and f in conda_package_dict.keys() + else False + for f in [ + p.split("/")[-3] + if "/share/pyiron/" in p else None + for p in executables_dict.keys() + ] + ] + return pandas.DataFrame({ + "name": [p.split("/")[-3] for p in executables_dict.keys()], + "path": list(executables_dict.keys()), + "executable_bit": list(executables_dict.values()), + "conda_package_installed": conda_lst, + }) + else: + return pandas.DataFrame({ + "name": [p.split("/")[-3] for p in executables_dict.keys()], + "path": list(executables_dict.keys()), + "executable_bit": list(executables_dict.values()), + }) From 9eab3282bbc61b8a64f6feec407e66cb19e9dcab Mon Sep 17 00:00:00 2001 From: pyiron-runner Date: Tue, 13 Jun 2023 23:41:10 +0000 Subject: [PATCH 2/3] Format black --- pyiron_base/state/check.py | 40 +++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/pyiron_base/state/check.py b/pyiron_base/state/check.py index 38a40b45c..859cb0d83 100644 --- a/pyiron_base/state/check.py +++ b/pyiron_base/state/check.py @@ -5,6 +5,7 @@ try: from conda.cli import python_api + conda_imported_successful = True except ImportError: conda_imported_successful = False @@ -18,7 +19,7 @@ "runner": "runner", "randspg": "randspg", "sphinx": "sphinxdft", - "lammps": "lammps" + "lammps": "lammps", } @@ -33,7 +34,11 @@ def check_for_conda_package(name): def check_executable_bit(resource_paths): def check_bit(script_path): filemode = os.stat(script_path).st_mode - return bool(filemode & stat.S_IXUSR or filemode & stat.S_IXGRP or filemode & stat.S_IXOTH) + return bool( + filemode & stat.S_IXUSR + or filemode & stat.S_IXGRP + or filemode & stat.S_IXOTH + ) path_lst = [] for res_path in resource_paths: @@ -43,7 +48,7 @@ def check_bit(script_path): def check_executables_status(): executables_dict = check_executable_bit( - resource_paths=state.settings.configuration['resource_paths'] + resource_paths=state.settings.configuration["resource_paths"] ) if conda_imported_successful: conda_lst = [ @@ -51,20 +56,23 @@ def check_executables_status(): if f is not None and f in conda_package_dict.keys() else False for f in [ - p.split("/")[-3] - if "/share/pyiron/" in p else None + p.split("/")[-3] if "/share/pyiron/" in p else None for p in executables_dict.keys() ] ] - return pandas.DataFrame({ - "name": [p.split("/")[-3] for p in executables_dict.keys()], - "path": list(executables_dict.keys()), - "executable_bit": list(executables_dict.values()), - "conda_package_installed": conda_lst, - }) + return pandas.DataFrame( + { + "name": [p.split("/")[-3] for p in executables_dict.keys()], + "path": list(executables_dict.keys()), + "executable_bit": list(executables_dict.values()), + "conda_package_installed": conda_lst, + } + ) else: - return pandas.DataFrame({ - "name": [p.split("/")[-3] for p in executables_dict.keys()], - "path": list(executables_dict.keys()), - "executable_bit": list(executables_dict.values()), - }) + return pandas.DataFrame( + { + "name": [p.split("/")[-3] for p in executables_dict.keys()], + "path": list(executables_dict.keys()), + "executable_bit": list(executables_dict.values()), + } + ) From 2fcb3461546dbc82306519420ffceecebb092229 Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Tue, 13 Jun 2023 17:47:26 -0600 Subject: [PATCH 3/3] Add support for cp2k and quantum espresso checks --- pyiron_base/state/check.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pyiron_base/state/check.py b/pyiron_base/state/check.py index 859cb0d83..6266f643e 100644 --- a/pyiron_base/state/check.py +++ b/pyiron_base/state/check.py @@ -13,13 +13,15 @@ from pyiron_base import state conda_package_dict = { - "mlip": "mlip", "atomicrex": "atomicrex", + "cp2k": "cp2k", "damask": "damask", - "runner": "runner", + "mlip": "mlip", + "lammps": "lammps", + "quantumespresso": "qe", "randspg": "randspg", + "runner": "runner", "sphinx": "sphinxdft", - "lammps": "lammps", }