/
project.py
66 lines (55 loc) · 2.39 KB
/
project.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Copyright 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.
"""Checks needed to determine integrity of the project."""
from renku.command.command_builder import inject
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(fix, project_gateway: IProjectGateway, **_):
"""Check that projects in groups have the correct id set.
Args:
fix: Whether to fix found issues.
project_gateway: Injected project gateway.
_: keyword arguments.
Returns:
Tuple of whether project id is valid, if an automated fix is available and string of found problems.
"""
current_project = project_gateway.get_project()
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, False, None
generated_id = Project.generate_id(namespace=namespace, name=name)
if generated_id == current_project.id:
return True, False, None
if fix:
communication.info(f"Fixing project id '{current_project.id}' -> '{generated_id}'")
current_project.id = generated_id
project_gateway.update_project(current_project)
return True, False, None
return (
False,
True,
(
WARNING
+ "Project id doesn't match id based on the current Git remote (use 'renku doctor --fix' to fix it):"
f"\n\t'{current_project.id}' -> '{generated_id}'"
),
)