Skip to content

Commit

Permalink
address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Panaetius committed Feb 4, 2021
1 parent cc67f80 commit fa85546
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 26 deletions.
2 changes: 1 addition & 1 deletion conftest.py
Expand Up @@ -359,7 +359,7 @@ def project_metadata(project):
def client(project):
"""Return a Renku repository."""
from renku.core.management import LocalClient
from renku.core.management.config import ConfigFilter
from renku.core.models.enums import ConfigFilter

original_get_value = LocalClient.get_value

Expand Down
3 changes: 2 additions & 1 deletion renku/cli/config.py
Expand Up @@ -104,7 +104,8 @@
import click

from renku.cli.utils.click import MutuallyExclusiveOption
from renku.core.commands.config import ConfigFilter, read_config, update_config
from renku.core.commands.config import read_config, update_config
from renku.core.models.enums import ConfigFilter


@click.group()
Expand Down
4 changes: 2 additions & 2 deletions renku/cli/utils/click.py
Expand Up @@ -50,10 +50,10 @@ def __init__(self, *args, **kwargs):
self.mutually_exclusive.add(mutex)
self.mutually_exclusive_names.append(mutex)

help = kwargs.get("help", "")
_help = kwargs.get("help", "")
if self.mutually_exclusive:
ex_str = ", ".join(self.mutually_exclusive_names)
kwargs["help"] = help + (" NOTE: This argument is mutually exclusive with " " arguments: [" + ex_str + "].")
kwargs["help"] = f"{_help} NOTE: This argument is mutually exclusive with arguments: [{ex_str}]."
super(MutuallyExclusiveOption, self).__init__(*args, **kwargs)

def handle_parse_result(self, ctx, opts, args):
Expand Down
3 changes: 2 additions & 1 deletion renku/core/commands/config.py
Expand Up @@ -18,7 +18,8 @@
"""Get and set Renku repository or global options."""
from renku.core import errors
from renku.core.incubation.command import Command
from renku.core.management.config import CONFIG_LOCAL_PATH, ConfigFilter
from renku.core.management.config import CONFIG_LOCAL_PATH
from renku.core.models.enums import ConfigFilter


def _split_section_and_key(key):
Expand Down
22 changes: 8 additions & 14 deletions renku/core/management/config.py
Expand Up @@ -27,6 +27,8 @@
import filelock
from pkg_resources import resource_filename

from renku.core.models.enums import ConfigFilter

APP_NAME = "Renku"
"""Application name for storing configuration."""

Expand All @@ -39,15 +41,6 @@ def _get_global_config_dir():
return click.get_app_dir(APP_NAME, force_posix=True)


class ConfigFilter(Enum):
"""Enum of filters over which config files to load. Note: Defaulta always get applied."""

ALL = 1
LOCAL_ONLY = 2
GLOBAL_ONLY = 3
DEFAULT_ONLY = 4


@attr.s
class ConfigManagerMixin:
"""Client for handling global configuration."""
Expand Down Expand Up @@ -106,13 +99,14 @@ def load_config(self, config_filter=ConfigFilter.ALL):
else:
config.read(config_files)

# transform config section for backwards compatibility
for s in config.sections():
if not s.startswith('renku "'):
# NOTE: transform config section for backwards compatibility. Changes section names like
# 'renku "interactive"' to just 'interactive' to be in line with python config conventions.
for section in config.sections():
if not section.startswith('renku "'):
continue

config[s[7:-1]] = dict(config.items(s))
config.pop(s)
config[section[7:-1]] = dict(config.items(section)) # NOTE: Drop first 7 and last char
config.pop(section)

return config

Expand Down
3 changes: 2 additions & 1 deletion renku/core/management/repository.py
Expand Up @@ -34,7 +34,8 @@

from renku.core import errors
from renku.core.compat import Path
from renku.core.management.config import RENKU_HOME, ConfigFilter
from renku.core.management.config import RENKU_HOME
from renku.core.models.enums import ConfigFilter
from renku.core.models.projects import Project
from renku.core.models.provenance.activity import ActivityCollection
from renku.core.models.provenance.provenance_graph import ProvenanceGraph
Expand Down
27 changes: 27 additions & 0 deletions renku/core/models/enums.py
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
#
# Copyright 2018-2020- Swiss Data Science Center (SDSC)
# A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and
# Eidgenössische Technische Hochschule Zürich (ETHZ).
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Enums used in renku."""


class ConfigFilter(Enum):
"""Enum of filters over which config files to load. Note: Default always gets applied."""

ALL = 1
LOCAL_ONLY = 2
GLOBAL_ONLY = 3
DEFAULT_ONLY = 4
6 changes: 3 additions & 3 deletions renku/service/controllers/config_set.py
Expand Up @@ -18,12 +18,12 @@
"""Renku service cache list cached projects controller."""
from renku.core.commands.config import update_multiple_config
from renku.service.controllers.api.abstract import ServiceCtrl
from renku.service.controllers.api.mixins import ReadOperationMixin
from renku.service.controllers.api.mixins import ReadWithSyncOperation
from renku.service.serializers.config import ConfigSetRequest, ConfigSetResponseRPC
from renku.service.views import result_response


class SetConfigCtrl(ServiceCtrl, ReadOperationMixin):
class SetConfigCtrl(ServiceCtrl, ReadWithSyncOperation):
"""Controller for listing cached projects endpoint."""

REQUEST_SERIALIZER = ConfigSetRequest()
Expand All @@ -48,4 +48,4 @@ def renku_op(self):

def to_response(self):
"""Execute controller flow and serialize to service response."""
return result_response(SetConfigCtrl.RESPONSE_SERIALIZER, self.execute_op())
return result_response(SetConfigCtrl.RESPONSE_SERIALIZER, self.execute_and_sync())
3 changes: 2 additions & 1 deletion renku/service/controllers/config_show.py
Expand Up @@ -16,7 +16,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Renku service cache list cached projects controller."""
from renku.core.commands.config import ConfigFilter, read_config
from renku.core.commands.config import read_config
from renku.core.models.enums import ConfigFilter
from renku.service.controllers.api.abstract import ServiceCtrl
from renku.service.controllers.api.mixins import ReadOperationMixin
from renku.service.serializers.config import ConfigShowRequest, ConfigShowResponseRPC
Expand Down
3 changes: 2 additions & 1 deletion renku/service/views/config.py
Expand Up @@ -32,6 +32,7 @@
accepts_json,
handle_common_except,
header_doc,
optional_identity,
requires_cache,
requires_identity,
)
Expand All @@ -48,7 +49,7 @@
)
@handle_common_except
@requires_cache
@requires_identity
@optional_identity
def show_config(user_data, cache):
"""Show renku config for a project."""
return ShowConfigCtrl(cache, user_data, dict(request.args)).to_response()
Expand Down
2 changes: 1 addition & 1 deletion tests/core/commands/test_cli.py
Expand Up @@ -33,9 +33,9 @@

from renku import __version__
from renku.cli import cli
from renku.core.management.config import ConfigFilter
from renku.core.management.repository import DEFAULT_DATA_DIR as DATA_DIR
from renku.core.management.storage import StorageApiMixin
from renku.core.models.enums import ConfigFilter
from renku.core.utils.contexts import chdir


Expand Down

0 comments on commit fa85546

Please sign in to comment.