Skip to content

Commit 9a373da

Browse files
committed
fix(cli): add check of missing references
1 parent f24e21e commit 9a373da

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

renku/cli/_checks/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919

2020
from .files_in_datasets import check_missing_files
2121
from .location_datasets import check_dataset_metadata
22+
from .references import check_missing_references
2223

2324
# Checks will be executed in the order as they are listed in __all__
2425
__all__ = (
2526
'check_dataset_metadata',
2627
'check_missing_files',
28+
'check_missing_references',
2729
)

renku/cli/_checks/references.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Copyright 2019 - Swiss Data Science Center (SDSC)
4+
# A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and
5+
# Eidgenössische Technische Hochschule Zürich (ETHZ).
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
"""Check missing references."""
19+
20+
import click
21+
22+
from .._echo import WARNING
23+
24+
25+
def check_missing_references(client):
26+
"""Find missing references."""
27+
from renku.models.refs import LinkReference
28+
29+
missing = [
30+
ref for ref in LinkReference.iter_items(client)
31+
if not ref.reference.exists()
32+
]
33+
34+
if not missing:
35+
return True
36+
37+
click.secho(
38+
WARNING + 'There are missing references.'
39+
'\n (use "git rm <name>" to clean them)\n\n\t' + '\n\t '.join(
40+
click.style(str(ref.path), fg='yellow') + ' -> ' +
41+
click.style(str(ref.reference), fg='red') for ref in missing
42+
) + '\n'
43+
)
44+
return False

renku/models/refs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ def iter_items(cls, client, common_path=None):
9494
path = path / common_path
9595

9696
for name in path.rglob('*'):
97+
if name.is_dir():
98+
continue
9799
yield cls(client=client, name=str(name.relative_to(refs_path)))
98100

99101
@classmethod

0 commit comments

Comments
 (0)