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

Check pyiron installation #1131

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyiron_base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
80 changes: 80 additions & 0 deletions pyiron_base/state/check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
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 = {
"atomicrex": "atomicrex",
"cp2k": "cp2k",
"damask": "damask",
"mlip": "mlip",
"lammps": "lammps",
"quantumespresso": "qe",
"randspg": "randspg",
"runner": "runner",
"sphinx": "sphinxdft",
}


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")
Copy link
Member

Choose a reason for hiding this comment

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

This feels very fragile. It looks to me like this requires all executables to be at exactly the third level of depth. This may be the case right now, but so we specify or document this anywhere? Do we anticipate other sh files appearing here, or is it safe to run an endswith command recursively inside the resource path instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

Right now it needs to be exactly at the third level because the expected structure is /$resources/$module_name/bin/$exe.sh. The documentation for this is here, though it could be more explicit.

I have a little class that codifies this in tinybase which could be moved to base. Replacing this everywhere might be a bit more effort, so imo it's ok to do it in a separate PR.

Copy link
Member

Choose a reason for hiding this comment

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

I'm ok with codefying it as long as we're sufficiently explicit. One option I see is to search for scripts at exactly three levels deep and also searching for them anywhere in the resource tree, then giving the user a warning if the lists aren't the same.

Actually, I think I really like that, and it should be straightforward to make a test setup in static to make sure both aspects work.

Similarly we should also be checking if non-supported codes have directories. I'm on mobile so I can't easily bail on this comment to check if that's already done, but this would be another nice thing to give a warning about.

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()),
}
)