Skip to content

Commit

Permalink
Merge pull request #420 from pyiron/install
Browse files Browse the repository at this point in the history
Implement pyiron.install()
  • Loading branch information
jan-janssen committed Sep 28, 2019
2 parents 688b0ed + d00b991 commit f6cf2c4
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 20 deletions.
1 change: 1 addition & 0 deletions docs/source/installation.rst
Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions pyiron/__init__.py
Expand Up @@ -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()
23 changes: 3 additions & 20 deletions pyiron/base/settings/generic.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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 = {
Expand Down
27 changes: 27 additions & 0 deletions pyiron/base/settings/install.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit f6cf2c4

Please sign in to comment.