Skip to content

Commit 7537693

Browse files
authored
Merge branch 'master' into 755-kg-validation
2 parents 35296da + ab65fa6 commit 7537693

19 files changed

+887
-723
lines changed

CHANGES.rst

+54-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,60 @@
1818
Changes
1919
=======
2020

21+
22+
`0.8.0 <https://github.com/SwissDataScienceCenter/renku-python/compare/v0.7.0...v0.8.0>`__ (2019-11-21)
23+
-------------------------------------------------------------------------------------------------------
24+
25+
Bug Fixes
26+
~~~~~~~~~
27+
28+
- addressed CI problems with git submodules
29+
(`#783 <https://github.com/SwissDataScienceCenter/renku-python/issues/783>`__)
30+
(`0d3eeb7 <https://github.com/SwissDataScienceCenter/renku-python/commit/0d3eeb7>`__)
31+
- adds simple check on empty filename
32+
(`#786 <https://github.com/SwissDataScienceCenter/renku-python/issues/786>`__)
33+
(`8cd061b <https://github.com/SwissDataScienceCenter/renku-python/commit/8cd061b>`__)
34+
- ensure all Person instances have valid ids
35+
(`4f80efc <https://github.com/SwissDataScienceCenter/renku-python/commit/4f80efc>`__),
36+
closes
37+
`#812 <https://github.com/SwissDataScienceCenter/renku-python/issues/812>`__
38+
- Fixes jsonld issue when importing from dataverse
39+
(`#759 <https://github.com/SwissDataScienceCenter/renku-python/issues/759>`__)
40+
(`ffe36c6 <https://github.com/SwissDataScienceCenter/renku-python/commit/ffe36c6>`__)
41+
- fixes nested type scoped handling if a class only has a single class
42+
(`#804 <https://github.com/SwissDataScienceCenter/renku-python/issues/804>`__)
43+
(`16d03b6 <https://github.com/SwissDataScienceCenter/renku-python/commit/16d03b6>`__)
44+
- ignore deleted paths in generated entities
45+
(`86fedaf <https://github.com/SwissDataScienceCenter/renku-python/commit/86fedaf>`__),
46+
closes
47+
`#806 <https://github.com/SwissDataScienceCenter/renku-python/issues/806>`__
48+
- integration tests
49+
(`#831 <https://github.com/SwissDataScienceCenter/renku-python/issues/831>`__)
50+
(`a4ad7f9 <https://github.com/SwissDataScienceCenter/renku-python/commit/a4ad7f9>`__)
51+
- make Creator a subclass of Person
52+
(`ac9bac3 <https://github.com/SwissDataScienceCenter/renku-python/commit/ac9bac3>`__),
53+
closes
54+
`#793 <https://github.com/SwissDataScienceCenter/renku-python/issues/793>`__
55+
- Redesign scoped context in jsonld
56+
(`#750 <https://github.com/SwissDataScienceCenter/renku-python/issues/750>`__)
57+
(`2b1948d <https://github.com/SwissDataScienceCenter/renku-python/commit/2b1948d>`__)
58+
59+
Features
60+
~~~~~~~~
61+
62+
- avoid creation of nested datasets
63+
(`#796 <https://github.com/SwissDataScienceCenter/renku-python/issues/796>`__)
64+
(`6084c87 <https://github.com/SwissDataScienceCenter/renku-python/commit/6084c87>`__)
65+
- do not create dataset implicitly
66+
(`#779 <https://github.com/SwissDataScienceCenter/renku-python/issues/779>`__)
67+
(`84e59d0 <https://github.com/SwissDataScienceCenter/renku-python/commit/84e59d0>`__)
68+
- local git repo not treated as remote
69+
(`8cc2834 <https://github.com/SwissDataScienceCenter/renku-python/commit/8cc2834>`__)
70+
- renku clone command
71+
(`#828 <https://github.com/SwissDataScienceCenter/renku-python/issues/828>`__)
72+
(`4b3b615 <https://github.com/SwissDataScienceCenter/renku-python/commit/4b3b615>`__)
73+
74+
2175
`0.7.0 <https://github.com/SwissDataScienceCenter/renku-python/compare/v0.6.0...v0.6.1>`__ (2019-10-15)
2276
-------------------------------------------------------------------------------------------------------
2377

@@ -26,13 +80,10 @@ Bug Fixes
2680

2781
- use UI-resolved project path as project ID (`#701`_) (`dfcc9e6`_)
2882

29-
.. _section-1:
3083

3184
`0.6.1 <https://github.com/SwissDataScienceCenter/renku-python/compare/v0.6.0...v0.6.1>`__ (2019-10-10)
3285
-------------------------------------------------------------------------------------------------------
3386

34-
.. _bug-fixes-1:
35-
3687
Bug Fixes
3788
~~~~~~~~~
3889

renku/cli/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
import click_completion
7070
import yaml
7171

72+
from renku.cli.clone import clone
7273
from renku.cli.config import config
7374
from renku.cli.dataset import dataset
7475
from renku.cli.doctor import doctor
@@ -187,6 +188,7 @@ def help(ctx):
187188

188189

189190
# Register subcommands:
191+
cli.add_command(clone)
190192
cli.add_command(config)
191193
cli.add_command(dataset)
192194
cli.add_command(doctor)

renku/cli/clone.py

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Copyright 2018-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+
"""Clone a Renku project.
19+
20+
Cloning a Renku project
21+
~~~~~~~~~~~~~~~~~~~~~~~
22+
23+
To clone a Renku project and set up required Git hooks and Git LFS use
24+
``renku clone`` command.
25+
26+
.. code-block:: console
27+
28+
$ renku clone git+ssh://host.io/namespace/project.git
29+
<destination-directory>
30+
31+
"""
32+
33+
import click
34+
35+
from renku.core.commands.clone import renku_clone
36+
from renku.core.commands.echo import GitProgress
37+
38+
39+
@click.command()
40+
@click.option(
41+
'--pull-data', is_flag=True, help='Pull data from Git-LFS.', default=False
42+
)
43+
@click.argument('url')
44+
@click.argument('path', required=False, default=None)
45+
def clone(pull_data, url, path):
46+
"""Clone a Renku repository."""
47+
click.echo('Cloning {} ...'.format(url))
48+
49+
skip_smudge = not pull_data
50+
renku_clone(
51+
url=url, path=path, skip_smudge=skip_smudge, progress=GitProgress()
52+
)
53+
click.secho('OK', fg='green')

renku/cli/dataset.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,10 @@ def edit(dataset_id):
410410
'--force', is_flag=True, help='Allow adding otherwise ignored files.'
411411
)
412412
@click.option(
413-
'--create', is_flag=True, help='Create dataset if it does not exist.'
413+
'-c',
414+
'--create',
415+
is_flag=True,
416+
help='Create dataset if it does not exist.'
414417
)
415418
@click.option(
416419
'-s',

renku/cli/githooks.py

+7-40
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,9 @@
3838
3939
"""
4040

41-
import stat
42-
from pathlib import Path
43-
4441
import click
4542

46-
from renku.core.commands.client import pass_local_client
47-
48-
HOOKS = ('pre-commit', )
43+
from renku.core.commands.githooks import install_githooks, uninstall_githooks
4944

5045

5146
@click.group()
@@ -55,42 +50,14 @@ def githooks():
5550

5651
@githooks.command()
5752
@click.option('--force', is_flag=True, help='Override existing hooks.')
58-
@pass_local_client
59-
def install(client, force):
53+
def install(force):
6054
"""Install Git hooks."""
61-
import pkg_resources
62-
from git.index.fun import hook_path as get_hook_path
63-
64-
for hook in HOOKS:
65-
hook_path = Path(get_hook_path(hook, client.repo.git_dir))
66-
if hook_path.exists():
67-
if not force:
68-
click.echo(
69-
'Hook already exists. Skipping {0}'.format(str(hook_path)),
70-
err=True
71-
)
72-
continue
73-
else:
74-
hook_path.unlink()
75-
76-
# Make sure the hooks directory exists.
77-
hook_path.parent.mkdir(parents=True, exist_ok=True)
78-
79-
Path(hook_path).write_bytes(
80-
pkg_resources.resource_string(
81-
'renku.data', '{hook}.sh'.format(hook=hook)
82-
)
83-
)
84-
hook_path.chmod(hook_path.stat().st_mode | stat.S_IEXEC)
55+
install_githooks(force)
56+
click.secho('OK', fg='green')
8557

8658

8759
@githooks.command()
88-
@pass_local_client
89-
def uninstall(client):
60+
def uninstall():
9061
"""Uninstall Git hooks."""
91-
from git.index.fun import hook_path as get_hook_path
92-
93-
for hook in HOOKS:
94-
hook_path = Path(get_hook_path(hook, client.repo.git_dir))
95-
if hook_path.exists():
96-
hook_path.unlink()
62+
uninstall_githooks()
63+
click.secho('OK', fg='green')

renku/core/commands/clone.py

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# Copyright 2018-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+
"""Clone a Renku repo along with all Renku-specific initializations."""
19+
20+
from renku.core.management.clone import clone
21+
22+
from .client import pass_local_client
23+
24+
25+
@pass_local_client
26+
def renku_clone(
27+
client,
28+
url,
29+
path=None,
30+
install_githooks=True,
31+
skip_smudge=True,
32+
progress=None
33+
):
34+
"""Clone Renku project repo, install Git hooks and LFS."""
35+
install_lfs = client.use_external_storage
36+
clone(
37+
url=url,
38+
path=path,
39+
install_githooks=install_githooks,
40+
install_lfs=install_lfs,
41+
skip_smudge=skip_smudge,
42+
progress=progress
43+
)

renku/core/commands/dataset.py

+15-8
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
from renku.core.models.refs import LinkReference
4848
from renku.core.models.tabulate import tabulate
4949
from renku.core.utils.doi import extract_doi
50+
from renku.core.utils.urls import remove_credentials
5051

5152
from .client import pass_local_client
5253
from .echo import WARNING
@@ -131,6 +132,8 @@ def edit_dataset(client, dataset_id, transform_fn):
131132
clean=False,
132133
commit=True,
133134
commit_only=COMMIT_DIFF_STRATEGY,
135+
commit_empty=False,
136+
raise_if_empty=True
134137
)
135138
def add_file(
136139
client,
@@ -166,13 +169,12 @@ def add_to_dataset(
166169
urlscontext=contextlib.nullcontext
167170
):
168171
"""Add data to a dataset."""
169-
if sources or destination:
170-
if len(urls) == 0:
171-
raise UsageError('No URL is specified')
172-
elif len(urls) > 1:
173-
raise UsageError(
174-
'Cannot add multiple URLs with --source or --destination'
175-
)
172+
if len(urls) == 0:
173+
raise UsageError('No URL is specified')
174+
if (sources or destination) and len(urls) > 1:
175+
raise UsageError(
176+
'Cannot add multiple URLs with --source or --destination'
177+
)
176178

177179
# check for identifier before creating the dataset
178180
identifier = extract_doi(
@@ -183,7 +185,7 @@ def add_to_dataset(
183185
name=name, identifier=identifier, create=create
184186
) as dataset:
185187
with urlscontext(urls) as bar:
186-
client.add_data_to_dataset(
188+
warning_message = client.add_data_to_dataset(
187189
dataset,
188190
bar,
189191
link=link,
@@ -193,6 +195,9 @@ def add_to_dataset(
193195
ref=ref
194196
)
195197

198+
if warning_message:
199+
click.echo(WARNING + warning_message)
200+
196201
if with_metadata:
197202
for file_ in with_metadata.files:
198203
for added_ in dataset.files:
@@ -202,6 +207,7 @@ def add_to_dataset(
202207
file_.url = file_.url.geturl()
203208

204209
file_.path = added_.path
210+
file_.url = remove_credentials(file_.url)
205211
file_.creator = with_metadata.creator
206212
file_._label = added_._label
207213
file_.commit = added_.commit
@@ -501,6 +507,7 @@ def import_dataset(
501507
pool.close()
502508

503509
dataset_name = name or dataset.display_name
510+
dataset.url = remove_credentials(dataset.url)
504511
add_to_dataset(
505512
client,
506513
urls=[str(p) for p in Path(data_folder).glob('*')],

renku/core/commands/echo.py

+21
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import os
2222

2323
import click
24+
from git.remote import RemoteProgress
2425

2526
WARNING = click.style('Warning: ', bold=True, fg='yellow')
2627

@@ -45,3 +46,23 @@ def echo_via_pager(*args, **kwargs):
4546
show_pos=True,
4647
item_show_func=lambda x: x,
4748
)
49+
50+
51+
class GitProgress(RemoteProgress):
52+
"""Progress printing for GitPython."""
53+
54+
def __init__(self):
55+
"""Initialize a Git progress printer."""
56+
super().__init__()
57+
self._previous_line_length = 0
58+
59+
def update(self, op_code, cur_count, max_count=None, message=''):
60+
"""Callback for printing Git operation status."""
61+
self._clear_line()
62+
print(self._cur_line, end='\r')
63+
self._previous_line_length = len(self._cur_line)
64+
if (op_code & RemoteProgress.END) != 0:
65+
print()
66+
67+
def _clear_line(self):
68+
print(self._previous_line_length * ' ', end='\r')

0 commit comments

Comments
 (0)