diff --git a/docs/source/installation.rst b/docs/source/installation.rst index e6dbdad67..b08094919 100644 --- a/docs/source/installation.rst +++ b/docs/source/installation.rst @@ -97,6 +97,7 @@ After the installation of pyiron we need to configure pyiron. The default config .. code-block:: python > import pyiron + > pyiron.install() >>> It appears that pyiron is not yet configured, do you want to create a default start configuration (recommended: yes). [yes/no]: > yes > exit() diff --git a/pyiron/__init__.py b/pyiron/__init__.py index 85294f0fc..be8b69934 100644 --- a/pyiron/__init__.py +++ b/pyiron/__init__.py @@ -4,8 +4,13 @@ from pyiron.project import Project from pyiron.atomistics.structure.atoms import ase_to_pyiron, pyiron_to_ase, Atoms from pyiron.base.job.script import Notebook +from pyiron.base.settings.install import install_dialog from ._version import get_versions __version__ = get_versions()["version"] del get_versions + + +def install(): + install_dialog() diff --git a/pyiron/base/settings/generic.py b/pyiron/base/settings/generic.py index 7df0a3fa1..e193fea3d 100644 --- a/pyiron/base/settings/generic.py +++ b/pyiron/base/settings/generic.py @@ -98,8 +98,9 @@ def __init__(self, config=None): config=self._configuration ) else: - self._install_dialog(config_file=config_file) - self._config_parse_file(config_file=config_file) + print("Fall back to default configuration: " + "{'resource_paths': ['~/pyiron/resources'], " + "'project_paths': ['~/pyiron/projects']}") # Take dictionary as primary source - overwrite everything self._read_external_config(config=config) @@ -497,24 +498,6 @@ def _read_external_config(self, config): "Config dictionary parameter type not recognized ", key, value ) - @staticmethod - def _install_dialog(config_file): - user_input = None - while user_input not in ["yes", "no"]: - user_input = input( - "It appears that pyiron is not yet configured, do you want to create a default start configuration (recommended: yes). [yes/no]:" - ) - if user_input.lower() == "yes" or user_input.lower() == "y": - install_pyiron( - config_file_name=config_file, - zip_file="resources.zip", - resource_directory="~/pyiron/resources", - giturl_for_zip_file="https://github.com/pyiron/pyiron-resources/archive/master.zip", - git_folder_name="pyiron-resources-master", - ) - else: - raise ValueError("pyiron was not installed!") - @staticmethod def get_config_from_environment(environment, config): env_key_mapping = { diff --git a/pyiron/base/settings/install.py b/pyiron/base/settings/install.py index 520ddc54a..12c9cbf28 100644 --- a/pyiron/base/settings/install.py +++ b/pyiron/base/settings/install.py @@ -46,6 +46,8 @@ def _download_resources( user_directory = os.path.normpath( os.path.abspath(os.path.expanduser(resource_directory)) ) + if os.path.exists(user_directory) and not os.listdir(user_directory): + os.rmdir(user_directory) temp_directory = tempfile.gettempdir() temp_zip_file = os.path.join(temp_directory, zip_file) temp_extract_folder = os.path.join(temp_directory, git_folder_name) @@ -98,6 +100,31 @@ def _write_config_file( os.makedirs(project_path) +def install_dialog(): + user_input = None + if "PYIRONCONFIG" in os.environ.keys(): + config_file = os.environ["PYIRONCONFIG"] + else: + config_file = "~/.pyiron" + if not os.path.exists(os.path.expanduser(config_file)): + while user_input not in ["yes", "no"]: + user_input = input( + "It appears that pyiron is not yet configured, do you want to create a default start configuration (recommended: yes). [yes/no]:" + ) + if user_input.lower() == "yes" or user_input.lower() == "y": + install_pyiron( + config_file_name="~/.pyiron", + zip_file="resources.zip", + resource_directory="~/pyiron/resources", + giturl_for_zip_file="https://github.com/pyiron/pyiron-resources/archive/master.zip", + git_folder_name="pyiron-resources-master", + ) + else: + raise ValueError("pyiron was not installed!") + else: + print("pyiron is already installed.") + + def install_pyiron( config_file_name="~/.pyiron", zip_file="resources.zip",