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

AiiDA temp profile in shell and Jupyter-notebook #6070

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 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
21 changes: 17 additions & 4 deletions aiida/cmdline/commands/cmd_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
import click

from aiida.cmdline.commands.cmd_verdi import verdi
from aiida.cmdline.utils import decorators, echo
from aiida.cmdline.utils import echo
from aiida.cmdline.utils.shell import AVAILABLE_SHELLS, run_shell


@verdi.command('shell')
@decorators.with_dbenv()
# @decorators.with_dbenv()
@click.option('--plain', is_flag=True, help='Use a plain Python shell.')
@click.option('--standalone', is_flag=True, help='Use the services-free standalone option.')
Copy link
Member

Choose a reason for hiding this comment

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

as discussed, standalone may be a bit unclear on its behaviour and/or at least the help message should be improved

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks! I changed it to temp and updated the help message.

@click.option(
'--no-startup',
is_flag=True,
Expand All @@ -32,14 +33,26 @@
type=click.Choice(AVAILABLE_SHELLS.keys()),
help='Specify an interactive interpreter interface.'
)
def shell(plain, no_startup, interface):
def shell(plain, standalone, no_startup, interface):
"""Start a python shell with preloaded AiiDA environment."""

try:
if plain:
# Don't bother loading IPython, because the user wants plain Python.
raise ImportError

if standalone:
from aiida import get_profile, load_profile, manage
from aiida.storage.sqlite_temp import SqliteTempBackend
profile = get_profile()
if not profile or profile.name != 'standalone':
profile = SqliteTempBackend.create_profile(
'standalone',
options={'runner.poll.interval': 1},
)
load_profile(profile, allow_switch=True)
config = manage.get_config()
config.add_profile(profile)

# If a non-plain python interpreter is requested, check that there is at least one type of shell available
if not AVAILABLE_SHELLS:
echo.echo_critical('No shells are available')
Expand Down
18 changes: 15 additions & 3 deletions aiida/tools/ipython/ipython_magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import json
import shlex

from IPython import get_ipython, version_info # type: ignore[attr-defined]
from IPython import get_ipython, version_info
from IPython.core import magic


Expand Down Expand Up @@ -136,11 +136,23 @@ def aiida(self, line='', local_ns=None):
"""
# pylint: disable=unused-argument,attribute-defined-outside-init
from aiida.cmdline.utils.shell import get_start_namespace
from aiida.manage.configuration import load_profile
from aiida.manage.configuration import get_config, load_profile
from aiida.storage.sqlite_temp import SqliteTempBackend

self.is_warning = False
lcontent = line.strip()
if lcontent:
if lcontent == 'standalone':
profile = SqliteTempBackend.create_profile(
'standalone', options={
'warnings.development_version': False,
'runner.poll.interval': 1
}, debug=False
)
config = get_config()
config.add_profile(profile)
config.set_default_profile(profile.name)
profile = load_profile(profile.name, allow_switch=True)
elif lcontent:
profile = load_profile(lcontent)
else:
profile = load_profile()
Expand Down
1 change: 1 addition & 0 deletions docs/source/reference/command_line.rst
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ Below is a list with all available subcommands.

Options:
--plain Use a plain Python shell.
--standalone Use the services-free standalone option.
--no-startup When using plain Python, ignore the PYTHONSTARTUP
environment variable and ~/.pythonrc.py script.
-i, --interface [ipython|bpython]
Expand Down