Skip to content

Commit

Permalink
refactor(core): remove LocalClient (#3139)
Browse files Browse the repository at this point in the history
  • Loading branch information
m-alisafaee committed Oct 7, 2022
1 parent a46450d commit f8184bd
Show file tree
Hide file tree
Showing 175 changed files with 2,930 additions and 3,628 deletions.
3 changes: 0 additions & 3 deletions docs/cheatsheet/conf.py
Expand Up @@ -190,16 +190,13 @@
("py:class", "DiGraph"),
("py:class", "DynamicProxy"),
("py:class", "IActivityGateway"),
("py:class", "IClientDispatcher"),
("py:class", "IDatasetGateway"),
("py:class", "IPlanGateway"),
("py:class", "LocalClient"),
("py:class", "NoValueType"),
("py:class", "OID_TYPE"),
("py:class", "Path"),
("py:class", "Persistent"),
("py:class", "optional"),
("py:class", '"LocalClient"'),
("py:class", '"ValueResolver"'),
("py:exc", "errors.ParameterError"),
]
Expand Down
3 changes: 0 additions & 3 deletions docs/conf.py
Expand Up @@ -355,17 +355,14 @@
("py:class", "DiGraph"),
("py:class", "DynamicProxy"),
("py:class", "IActivityGateway"),
("py:class", "IClientDispatcher"),
("py:class", "IDatasetGateway"),
("py:class", "IPlanGateway"),
("py:class", "IStorageFactory"),
("py:class", "LocalClient"),
("py:class", "NoValueType"),
("py:class", "OID_TYPE"),
("py:class", "Path"),
("py:class", "Persistent"),
("py:class", "optional"),
("py:class", '"LocalClient"'),
("py:class", '"ValueResolver"'),
("py:exc", "errors.ParameterError"),
]
Expand Down
4 changes: 0 additions & 4 deletions docs/reference/gateways.rst
Expand Up @@ -31,10 +31,6 @@ Interfaces that the Gateways implement.
:members:
:show-inheritance:

.. automodule:: renku.core.interface.client_dispatcher
:members:
:show-inheritance:

.. automodule:: renku.core.interface.database_gateway
:members:
:show-inheritance:
Expand Down
4 changes: 2 additions & 2 deletions renku/command/checks/activities.py
Expand Up @@ -22,14 +22,14 @@
import click

from renku.command.command_builder import inject
from renku.command.echo import WARNING
from renku.command.util import WARNING
from renku.core.interface.activity_gateway import IActivityGateway
from renku.core.util import communication
from renku.domain_model.project_context import project_context


@inject.autoparams("activity_gateway")
def check_migrated_activity_ids(client, fix, activity_gateway: IActivityGateway, **kwargs):
def check_migrated_activity_ids(fix, activity_gateway: IActivityGateway, **_):
"""Check that activity ids were correctly migrated in the past."""
activities = activity_gateway.get_all_activities(include_deleted=True)

Expand Down
22 changes: 9 additions & 13 deletions renku/command/checks/datasets.py
Expand Up @@ -23,7 +23,7 @@
import click

from renku.command.command_builder import inject
from renku.command.echo import WARNING
from renku.command.util import WARNING
from renku.core import errors
from renku.core.dataset.dataset_add import add_to_dataset
from renku.core.interface.dataset_gateway import IDatasetGateway
Expand All @@ -33,12 +33,11 @@
from renku.domain_model.project_context import project_context


def check_dataset_old_metadata_location(client, **kwargs):
def check_dataset_old_metadata_location(**_):
"""Check location of dataset metadata.
Args:
client: ``LocalClient``.
kwargs: keyword arguments.
_: keyword arguments.
Returns:
Tuple of whether dataset metadata location is valid and string of found problems.
Expand All @@ -59,13 +58,12 @@ def check_dataset_old_metadata_location(client, **kwargs):


@inject.autoparams("dataset_gateway")
def check_missing_files(client, dataset_gateway: IDatasetGateway, **kwargs):
def check_missing_files(dataset_gateway: IDatasetGateway, **_):
"""Find missing files listed in datasets.
Args:
client: ``LocalClient``.
dataset_gateway(IDatasetGateway): the dataset gateway.
kwargs: keyword arguments.
_: keyword arguments.
Returns:
Tuple of whether all dataset files are there and string of found problems.
Expand Down Expand Up @@ -96,14 +94,13 @@ def check_missing_files(client, dataset_gateway: IDatasetGateway, **kwargs):


@inject.autoparams("dataset_gateway")
def check_invalid_datasets_derivation(client, fix, dataset_gateway: IDatasetGateway, **kwargs):
def check_invalid_datasets_derivation(fix, dataset_gateway: IDatasetGateway, **_):
"""Remove ``derived_from`` from import datasets.
Args:
client: ``LocalClient``.
fix: Whether to fix found issues.
dataset_gateway(IDatasetGateway): the dataset gateway.
kwargs: keyword arguments.
_: keyword arguments.
Returns:
Tuple of whether dataset derivations are valid and string of found problems.
Expand Down Expand Up @@ -146,14 +143,13 @@ def fix_or_report(dataset):


@inject.autoparams("dataset_gateway")
def check_dataset_files_outside_datadir(client, fix, dataset_gateway: IDatasetGateway, **kwargs):
def check_dataset_files_outside_datadir(fix, dataset_gateway: IDatasetGateway, **_):
"""Check for dataset files that are not inside a dataset's datadir.
Args:
client: ``LocalClient``.
fix: Whether to fix found issues.
dataset_gateway(IDatasetGateway): the dataset gateway.
kwargs: keyword arguments.
_: keyword arguments.
Returns:
Tuple of whether there are no dataset files outside of its datadir and string of found problems.
Expand Down
18 changes: 6 additions & 12 deletions renku/command/checks/external.py
Expand Up @@ -16,22 +16,20 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Checks for external files."""
import click

from renku.command.command_builder import inject
from renku.command.echo import WARNING
from renku.command.util import WARNING, red_text, yellow_text
from renku.core.interface.dataset_gateway import IDatasetGateway
from renku.domain_model.project_context import project_context


@inject.autoparams("dataset_gateway")
def check_missing_external_files(client, dataset_gateway: IDatasetGateway, **kwargs):
def check_missing_external_files(dataset_gateway: IDatasetGateway, **_):
"""Find external files that are missing.
Args:
client: ``LocalClient``.
dataset_gateway(IDatasetGateway): The injected dataset gateway.
kwargs: keyword arguments.
_: keyword arguments.
Returns:
Tuple of whether no external files are missing and string of found problems.
Expand All @@ -48,13 +46,9 @@ def check_missing_external_files(client, dataset_gateway: IDatasetGateway, **kwa
if not missing:
return True, None

missing_str = "\n\t".join(f"{yellow_text(path)} -> {red_text(target)}" for path, target in missing)
problems = (
"\n" + WARNING + "There are missing external files.\n"
" (make sure that external paths are accessible)"
+ "\n\n\t"
+ "\n\t".join(
click.style(path, fg="yellow") + " -> " + click.style(target, fg="red") for path, target in missing
)
+ "\n"
f"\n{WARNING}There are missing external files.\n (make sure that external paths are accessible)"
f"\n\n\t{missing_str}\n"
)
return False, problems
11 changes: 5 additions & 6 deletions renku/command/checks/githooks.py
Expand Up @@ -19,7 +19,7 @@

from io import StringIO

from renku.command.echo import WARNING
from renku.command.util import WARNING
from renku.core.githooks import HOOKS
from renku.core.util.git import get_hook_path
from renku.domain_model.project_context import project_context
Expand All @@ -30,12 +30,11 @@
import importlib.resources as importlib_resources # type: ignore


def check_git_hooks_installed(client, **kwargs):
def check_git_hooks_installed(**_):
"""Checks if all necessary hooks are installed.
Args:
client: ``LocalClient``.
kwargs: keyword arguments.
_: keyword arguments.
Returns:
Tuple of whether git hooks are valid and string of found problems.
Expand Down Expand Up @@ -65,8 +64,8 @@ def check_git_hooks_installed(client, **kwargs):
return True, None


def _extract_renku_hook(file_):
lines = [line.strip() for line in file_ if line.strip()]
def _extract_renku_hook(file):
lines = [line.strip() for line in file if line.strip()]
start = end = -1
for index, line in enumerate(lines):
if line.startswith("# RENKU HOOK."):
Expand Down
10 changes: 5 additions & 5 deletions renku/command/checks/migration.py
Expand Up @@ -16,16 +16,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Warn if migration is required."""
from renku.command.echo import ERROR, WARNING
from renku.core.management.migrate import is_migration_required, is_project_unsupported

from renku.command.util import ERROR, WARNING
from renku.core.migration.migrate import is_migration_required, is_project_unsupported

def check_migration(client, **kwargs):

def check_migration(**_):
"""Check for project version.
Args:
client: ``LocalClient``.
kwargs: keyword arguments.
_: keyword arguments.
Returns:
Tuple of whether project metadata is up to date and string of found problems.
Expand Down
12 changes: 7 additions & 5 deletions renku/command/checks/project.py
Expand Up @@ -18,28 +18,30 @@
"""Checks needed to determine integrity of the project."""

from renku.command.command_builder import inject
from renku.command.echo import WARNING
from renku.command.util import WARNING
from renku.core.interface.project_gateway import IProjectGateway
from renku.core.util import communication
from renku.domain_model.project import Project
from renku.domain_model.project_context import project_context


@inject.autoparams("project_gateway")
def check_project_id_group(client, fix, project_gateway: IProjectGateway, **kwargs):
def check_project_id_group(fix, project_gateway: IProjectGateway, **_):
"""Check that projects in groups have the correct id set.
Args:
client: ``LocalClient``.
fix: Whether to fix found issues.
project_gateway: Injected project gateway.
kwargs: keyword arguments.
_: keyword arguments.
Returns:
Tuple of whether project id is valid.
"""
current_project = project_gateway.get_project()

namespace, name = Project.get_namespace_and_name(use_project_context=True)
namespace, name = Project.get_namespace_and_name(
remote=project_context.remote, repository=project_context.repository
)

if namespace is None or name is None:
return True, None
Expand Down
7 changes: 3 additions & 4 deletions renku/command/checks/storage.py
Expand Up @@ -17,16 +17,15 @@
# limitations under the License.
"""Check for large files in Git history."""

from renku.command.echo import WARNING
from renku.command.util import WARNING
from renku.core.storage import check_external_storage, check_lfs_migrate_info


def check_lfs_info(client, **kwargs):
def check_lfs_info(**_):
"""Checks if files in history should be in LFS.
Args:
client: ``LocalClient``
kwargs: keyword arguments.
_: keyword arguments.
Returns:
Tuple of whether project structure is valid and string of found problems.
Expand Down
21 changes: 10 additions & 11 deletions renku/command/checks/validate_shacl.py
Expand Up @@ -16,13 +16,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Check KG structure using SHACL."""

import pyld
import yaml

from renku.command.command_builder import inject
from renku.command.echo import WARNING
from renku.command.schema.dataset import dump_dataset_as_jsonld
from renku.command.schema.project import ProjectSchema
from renku.command.util import WARNING
from renku.core.interface.dataset_gateway import IDatasetGateway
from renku.core.util.shacl import validate_graph
from renku.core.util.yaml import NoDatesSafeLoader
Expand Down Expand Up @@ -53,24 +54,23 @@ def _shacl_graph_to_string(graph):
message = "{0}: {1}".format(path, res)
else:
kind = graph.value(result, sh.sourceConstraintComponent)
focusNode = graph.value(result, sh.focusNode)
focus_node = graph.value(result, sh.focusNode)

if isinstance(focusNode, BNode):
focusNode = "<Anonymous>"
if isinstance(focus_node, BNode):
focus_node = "<Anonymous>"

message = "{0}: Type: {1}, Node ID: {2}".format(path, kind, focusNode)
message = "{0}: Type: {1}, Node ID: {2}".format(path, kind, focus_node)

problems.append(message)

return "\n\t".join(problems)


def check_project_structure(client, **kwargs):
def check_project_structure(**_):
"""Validate project metadata against SHACL.
Args:
client: ``LocalClient``.
kwargs: keyword arguments.
_: keyword arguments.
Returns:
Tuple of whether project structure is valid and string of found problems.
Expand All @@ -88,13 +88,12 @@ def check_project_structure(client, **kwargs):


@inject.autoparams("dataset_gateway")
def check_datasets_structure(client, dataset_gateway: IDatasetGateway, **kwargs):
def check_datasets_structure(dataset_gateway: IDatasetGateway, **_):
"""Validate dataset metadata against SHACL.
Args:
client: The ``LocalClient``.
dataset_gateway(IDatasetGateway): The injected dataset gateway.
kwargs: keyword arguments.
_: keyword arguments.
Returns:
Tuple[bool, str]: Tuple of whether structure is valid and of problems that might have been found.
Expand Down
7 changes: 3 additions & 4 deletions renku/command/checks/workflow.py
Expand Up @@ -19,20 +19,19 @@

from typing import Optional, Tuple

from renku.command.echo import WARNING
from renku.command.util import WARNING
from renku.core.util import communication
from renku.domain_model.project_context import project_context
from renku.infrastructure.gateway.activity_gateway import reindex_catalog


def check_activity_catalog(client, fix, force, **kwargs) -> Tuple[bool, Optional[str]]:
def check_activity_catalog(fix, force, **_) -> Tuple[bool, Optional[str]]:
"""Check if the activity-catalog needs to be rebuilt.
Args:
client: ``LocalClient``.
fix: Whether to fix found issues.
force: Whether to force rebuild the activity catalog.
kwargs: keyword arguments.
_: keyword arguments.
Returns:
Tuple of whether the activity-catalog needs to be rebuilt and a string of found problems.
Expand Down

0 comments on commit f8184bd

Please sign in to comment.