Skip to content

Commit

Permalink
Implement verdi config (#2354)
Browse files Browse the repository at this point in the history
The new command `verdi config` replaces the various commands under
`verdi devel` that were used to list, get, set and unset configuration
options, that were used to be called "properties". Since the term
"property" is a reserved keyword, it was decided to rename them to
"options", which is also the term used by "git". The interface of
`verdi config` also mirrors that of `git config`. That is to say
to get the value of an option simply call `git config <option_name>`
and to set it `git config <option_name> <option_value>`. To unset
it, the `--unset` flag can be used. Finally, the getting, setting
or unsetting can be applied to a certain "scope", meaning to be
configuration wide or profile specific.

To make the implementation of this command simple and clean, the
bulk of the work was in refactoring the definition, construction and
operation on the configuration of an AiiDA instance. This is now
represented by the `Config` class, through which these configuration
options can be set or unset as well as retrieved.
  • Loading branch information
sphuber authored Dec 18, 2018
1 parent 1e7e25e commit 14ecf15
Show file tree
Hide file tree
Showing 78 changed files with 1,514 additions and 1,179 deletions.
2 changes: 1 addition & 1 deletion .ci/setup_profiles.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ then
verdi profile setdefault $TEST_AIIDA_BACKEND

# Set the polling interval to 0 otherwise the tests take too long
verdi devel setproperty runner.poll.interval 0
verdi config runner.poll.interval 0
fi
14 changes: 0 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
(?x)^(
docs/.*|
examples/.*|
aiida/backends/djsite/db/admin.py|
aiida/backends/djsite/db/__init__.py|
aiida/backends/djsite/db/management/__init__.py|
aiida/backends/djsite/db/migrations/0001_initial.py|
aiida/backends/djsite/db/migrations/0002_db_state_change.py|
aiida/backends/djsite/db/migrations/0003_add_link_type.py|
Expand All @@ -32,13 +30,11 @@
aiida/backends/djsite/db/migrations/0017_drop_dbcalcstate.py|
aiida/backends/djsite/db/migrations/__init__.py|
aiida/backends/djsite/db/models.py|
aiida/backends/djsite/db/subtests/djangomigrations.py|
aiida/backends/djsite/db/subtests/migrations.py|
aiida/backends/djsite/db/subtests/generic.py|
aiida/backends/djsite/db/subtests/__init__.py|
aiida/backends/djsite/db/subtests/nodes.py|
aiida/backends/djsite/db/subtests/query.py|
aiida/backends/djsite/db/views.py|
aiida/backends/djsite/globalsettings.py|
aiida/backends/djsite/__init__.py|
aiida/backends/djsite/manage.py|
Expand Down Expand Up @@ -103,22 +99,12 @@
aiida/backends/tests/cmdline/commands/test_comment.py|
aiida/backends/tests/cmdline/commands/test_computer.py|
aiida/backends/tests/cmdline/commands/test_data.py|
aiida/backends/tests/cmdline/commands/test_devel.py|
aiida/backends/tests/cmdline/commands/test_export.py|
aiida/backends/tests/cmdline/commands/test_group.py|
aiida/backends/tests/cmdline/commands/test_node.py|
aiida/backends/tests/cmdline/commands/test_user.py|
aiida/backends/tests/cmdline/commands/test_work.py|
aiida/backends/tests/cmdline/commands/test_workflow.py|
aiida/backends/tests/cmdline/params/types/test_calculation.py|
aiida/backends/tests/cmdline/params/types/test_code.py|
aiida/backends/tests/cmdline/params/types/test_computer.py|
aiida/backends/tests/cmdline/params/types/test_data.py|
aiida/backends/tests/cmdline/params/types/test_group.py|
aiida/backends/tests/cmdline/params/types/test_identifier.py|
aiida/backends/tests/cmdline/params/types/test_node.py|
aiida/backends/tests/cmdline/params/types/test_plugin.py|
aiida/backends/tests/cmdline/params/types/test_workflow.py|
aiida/backends/tests/common/test_datastructures.py|
aiida/backends/tests/computer.py|
aiida/backends/tests/control/test_computer_ctrl.py|
Expand Down
22 changes: 11 additions & 11 deletions aiida/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,18 @@
from __future__ import division
from __future__ import print_function
from __future__ import absolute_import

import warnings

from aiida.common.log import configure_logging
from aiida.common.setup import get_property
import aiida.common.warnings
from aiida.common.log import configure_logging
from aiida.manage import get_config_option

__copyright__ = (u"Copyright (c), This file is part of the AiiDA platform. "
u"For further information please visit http://www.aiida.net/. All rights reserved.")
__license__ = "MIT license, see LICENSE.txt file."
__version__ = "1.0.0a4"
__authors__ = "The AiiDA team."
__copyright__ = (u'Copyright (c), This file is part of the AiiDA platform. '
u'For further information please visit http://www.aiida.net/. All rights reserved.')
__license__ = 'MIT license, see LICENSE.txt file.'
__version__ = '1.0.0a4'
__authors__ = 'The AiiDA team.'
__paper__ = (u'G. Pizzi, A. Cepellotti, R. Sabatini, N. Marzari, and B. Kozinsky,'
u'"AiiDA: automated interactive infrastructure and database for computational science", '
u'Comp. Mat. Sci 111, 218-230 (2016); http://dx.doi.org/10.1016/j.commatsci.2015.09.013 '
Expand All @@ -43,10 +44,9 @@
# Configure the default logging
configure_logging()

if get_property("warnings.showdeprecations"):
# If the user does not want to get AiiDA deprecation warnings,
# we disable them - this can be achieved with::
# verdi devel setproperty warnings.showdeprecations False
if get_config_option('warnings.showdeprecations'):
# If the user does not want to get AiiDA deprecation warnings, we disable them - this can be achieved with::
# verdi config warnings.showdeprecations False
# Note that the AiidaDeprecationWarning does NOT inherit from DeprecationWarning
warnings.simplefilter('default', aiida.common.warnings.AiidaDeprecationWarning) # pylint: disable=no-member
# This should default to 'once', i.e. once per different message
Expand Down
4 changes: 2 additions & 2 deletions aiida/backends/djsite/settings/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from aiida.backends import settings
from aiida.common.setup import parse_repository_uri
from aiida.manage import load_config
from aiida.manage import get_config
from aiida.utils.timezone import get_current_timezone

# Assumes that parent directory of aiida is root for
Expand All @@ -31,7 +31,7 @@
sys.path = [BASE_DIR] + sys.path

try:
CONFIG = load_config()
CONFIG = get_config()
except MissingConfigurationError:
raise MissingConfigurationError("Please run the AiiDA Installation, no config found")

Expand Down
4 changes: 2 additions & 2 deletions aiida/backends/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ def load_profile(profile=None):
Load the profile. This function is called by load_dbenv and SHOULD NOT
be called by the user by hand.
"""
from aiida.manage import load_config
from aiida.manage import get_config

if settings.LOAD_PROFILE_CALLED:
raise InvalidOperation('You cannot call load_profile multiple times!')

config = load_config()
config = get_config()

settings.LOAD_PROFILE_CALLED = True

Expand Down
14 changes: 4 additions & 10 deletions aiida/backends/sqlalchemy/tests/migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,22 @@
# For further information on the license, see the LICENSE.txt file #
# For further information please visit http://www.aiida.net #
###########################################################################

from __future__ import division
from __future__ import absolute_import
from __future__ import print_function
import copy
import unittest

import os
import unittest

from alembic import command
from alembic.config import Config

from aiida.backends import sqlalchemy as sa
from aiida.backends.sqlalchemy import utils
from aiida.backends.sqlalchemy.models.base import Base
from aiida.backends.sqlalchemy.utils import (get_migration_head,
get_db_schema_version)
from aiida.backends.testbase import AiidaTestCase
from aiida.common.setup import set_property, get_property

from aiida.backends.sqlalchemy.tests.utils import new_database
from aiida.backends.sqlalchemy.utils import get_migration_head, get_db_schema_version
from aiida.backends.testbase import AiidaTestCase


alembic_root = os.path.join(os.path.dirname(__file__), 'migrations', 'alembic')
Expand Down Expand Up @@ -146,8 +142,6 @@ def test_migrations_forward_backward(self):
alemb_table_names)
# Delete only the tables that exist
for table in tables_to_drop:
from psycopg2 import ProgrammingError
from sqlalchemy.orm import sessionmaker, scoped_session
try:
with sa.engine.begin() as connection:
connection.execute('DROP TABLE {};'.format(table))
Expand Down
4 changes: 2 additions & 2 deletions aiida/backends/sqlalchemy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ def _load_dbenv_noschemacheck(profile=None, connection=None):
"""
Load the SQLAlchemy database.
"""
from aiida.manage import load_config
from aiida.manage import get_config

config = load_config()
config = get_config()
profile = config.current_profile
reset_session(profile.dictionary)

Expand Down
15 changes: 9 additions & 6 deletions aiida/backends/testbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,19 @@
from __future__ import division
from __future__ import absolute_import
from __future__ import print_function

import os
import sys
import unittest
from unittest import (
TestSuite, defaultTestLoader as test_loader)
import traceback

from tornado import ioloop
import traceback

from aiida.backends import settings
from aiida.backends.tests import get_db_test_list
from aiida.common.exceptions import ConfigurationError, TestsNotAllowedError, InternalError
from aiida.common.utils import classproperty
from aiida.manage import get_manager, reset_manager
from aiida.manage import reset_manager


def check_if_tests_can_run():
Expand Down Expand Up @@ -164,6 +163,10 @@ def tearDownClass(cls, *args, **kwargs):
cls.clean_db()
cls.__backend_instance.tearDownClass_method(*args, **kwargs)

def assertClickSuccess(self, cli_result):
self.assertEqual(cli_result.exit_code, 0)
self.assertClickResultNoException(cli_result)

def assertClickResultNoException(self, cli_result):
self.assertIsNone(cli_result.exception, ''.join(traceback.format_exception(*cli_result.exc_info)))

Expand All @@ -174,7 +177,7 @@ def run_aiida_db_tests(tests_to_run, verbose=False):
Return the list of test results.
"""
# Empty test suite that will be populated
test_suite = TestSuite()
test_suite = unittest.TestSuite()

actually_run_tests = []
num_tests_expected = 0
Expand All @@ -196,7 +199,7 @@ def run_aiida_db_tests(tests_to_run, verbose=False):
for modulename in modulenames:
if modulename not in found_modulenames:
try:
test_suite.addTest(test_loader.loadTestsFromName(modulename))
test_suite.addTest(unittest.defaultTestLoader.loadTestsFromName(modulename))
except AttributeError as exception:
try:
import importlib
Expand Down
6 changes: 4 additions & 2 deletions aiida/backends/testimplbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

from aiida.common.exceptions import InternalError
from aiida import orm
from aiida.manage import get_manager


@six.add_metaclass(ABCMeta)
Expand Down Expand Up @@ -77,6 +76,8 @@ def insert_data(self):
"""
This method inserts default data into the database.
"""
from aiida.manage import get_config

self.computer = orm.Computer(
name='localhost',
hostname='localhost',
Expand All @@ -86,7 +87,8 @@ def insert_data(self):
backend=self.backend
).store()

email = get_manager().get_profile().default_user_email
config = get_config()
email = config.current_profile.default_user_email
self.user = orm.User(email=email).store()
self.user_email = email

Expand Down
5 changes: 4 additions & 1 deletion aiida/backends/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
'cmdline.commands.code': ['aiida.backends.tests.cmdline.commands.test_code'],
'cmdline.commands.comment': ['aiida.backends.tests.cmdline.commands.test_comment'],
'cmdline.commands.computer': ['aiida.backends.tests.cmdline.commands.test_computer'],
'cmdline.commands.config': ['aiida.backends.tests.cmdline.commands.test_config'],
'cmdline.commands.data': ['aiida.backends.tests.cmdline.commands.test_data'],
'cmdline.commands.database': ['aiida.backends.tests.cmdline.commands.test_database'],
'cmdline.commands.devel': ['aiida.backends.tests.cmdline.commands.test_devel'],
'cmdline.commands.export': ['aiida.backends.tests.cmdline.commands.test_export'],
'cmdline.commands.graph': ['aiida.backends.tests.cmdline.commands.test_graph'],
'cmdline.commands.group': ['aiida.backends.tests.cmdline.commands.test_group'],
Expand All @@ -80,7 +80,10 @@
'common.archive': ['aiida.backends.tests.common.test_archive'],
'common.datastructures': ['aiida.backends.tests.common.test_datastructures'],
'daemon.client': ['aiida.backends.tests.daemon.test_client'],
'manage.configuration.config.': ['aiida.backends.tests.manage.configuration.test_config'],
'manage.configuration.migrations.': ['aiida.backends.tests.manage.configuration.migrations.test_migrations'],
'manage.configuration.options.': ['aiida.backends.tests.manage.configuration.test_options'],
'manage.configuration.profile.': ['aiida.backends.tests.manage.configuration.test_profile'],
'orm.authinfo': ['aiida.backends.tests.orm.authinfo'],
'orm.comments': ['aiida.backends.tests.orm.comments'],
'orm.computer': ['aiida.backends.tests.computer'],
Expand Down
Loading

0 comments on commit 14ecf15

Please sign in to comment.