-
Notifications
You must be signed in to change notification settings - Fork 24
feat: adds renku clone command #828
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0e7fa2b
refactor: move githooks functionality to commands
mohammad-alisafaee d058f0b
feat: renku clone command
mohammad-alisafaee e214932
refactor: use Renku clone instead of Git clone
mohammad-alisafaee e938da5
review: apply comments
mohammad-alisafaee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # | ||
| # Copyright 2018-2019- 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. | ||
| """Clone a Renku project. | ||
|
|
||
| Cloning a Renku project | ||
| ~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| To clone a Renku project and set up required Git hooks and Git LFS use | ||
| ``renku clone`` command. | ||
|
|
||
| .. code-block:: console | ||
|
|
||
| $ renku clone git+ssh://host.io/namespace/project.git | ||
| <destination-directory> | ||
|
|
||
| """ | ||
|
|
||
| import click | ||
|
|
||
| from renku.core.commands.clone import renku_clone | ||
| from renku.core.commands.echo import GitProgress | ||
|
|
||
|
|
||
| @click.command() | ||
| @click.option( | ||
| '--pull-data', is_flag=True, help='Pull data from Git-LFS.', default=False | ||
| ) | ||
| @click.argument('url') | ||
| @click.argument('path', required=False, default=None) | ||
| def clone(pull_data, url, path): | ||
| """Clone a Renku repository.""" | ||
| click.echo('Cloning {} ...'.format(url)) | ||
|
|
||
| skip_smudge = not pull_data | ||
| renku_clone( | ||
| url=url, path=path, skip_smudge=skip_smudge, progress=GitProgress() | ||
| ) | ||
| click.secho('OK', fg='green') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # | ||
| # Copyright 2018-2019- 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. | ||
| """Clone a Renku repo along with all Renku-specific initializations.""" | ||
|
|
||
| from renku.core.management.clone import clone | ||
|
|
||
| from .client import pass_local_client | ||
|
|
||
|
|
||
| @pass_local_client | ||
| def renku_clone( | ||
| client, | ||
| url, | ||
| path=None, | ||
| install_githooks=True, | ||
| skip_smudge=True, | ||
| progress=None | ||
| ): | ||
| """Clone Renku project repo, install Git hooks and LFS.""" | ||
| install_lfs = client.use_external_storage | ||
| clone( | ||
| url=url, | ||
| path=path, | ||
| install_githooks=install_githooks, | ||
| install_lfs=install_lfs, | ||
| skip_smudge=skip_smudge, | ||
| progress=progress | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # | ||
| # Copyright 2018-2019- 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. | ||
| """Install and uninstall Git hooks.""" | ||
|
|
||
| import click | ||
|
|
||
| from renku.core.management.githooks import install, uninstall | ||
|
|
||
| from .client import pass_local_client | ||
| from .echo import WARNING | ||
|
|
||
|
|
||
| @pass_local_client | ||
| def install_githooks(client, force): | ||
| """Install Git hooks.""" | ||
| warning_messages = install(client=client, force=force) | ||
| if warning_messages: | ||
| for message in warning_messages: | ||
| click.echo(WARNING + message) | ||
|
|
||
|
|
||
| @pass_local_client | ||
| def uninstall_githooks(client): | ||
| """Uninstall Git hooks.""" | ||
| uninstall(client=client) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # | ||
| # Copyright 2018-2019- 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. | ||
| """Clone a Renku repo along with all Renku-specific initializations.""" | ||
|
|
||
| import os | ||
|
|
||
| from git import GitCommandError, Repo | ||
|
|
||
| from renku.core import errors | ||
| from renku.core.management.githooks import install | ||
|
|
||
|
|
||
| def clone( | ||
| url, | ||
| path=None, | ||
| install_githooks=True, | ||
| install_lfs=True, | ||
| skip_smudge=True, | ||
| recursive=True, | ||
| depth=None, | ||
| progress=None | ||
| ): | ||
| """Clone Renku project repo, install Git hooks and LFS.""" | ||
| from renku.core.management.client import LocalClient | ||
|
|
||
| path = path or '.' | ||
| # Clone the project | ||
| if skip_smudge: | ||
| os.environ['GIT_LFS_SKIP_SMUDGE'] = '1' | ||
| try: | ||
| repo = Repo.clone_from( | ||
| url, path, recursive=recursive, depth=depth, progress=progress | ||
| ) | ||
| except GitCommandError as e: | ||
| raise errors.GitError( | ||
| 'Cannot clone remote Renku project: {}'.format(url) | ||
| ) from e | ||
|
|
||
| client = LocalClient(path) | ||
|
|
||
| if install_githooks: | ||
| install(client=client, force=True) | ||
|
|
||
| if install_lfs: | ||
| command = ['git', 'lfs', 'install', '--local', '--force'] | ||
| if skip_smudge: | ||
| command += ['--skip-smudge'] | ||
| try: | ||
| repo.git.execute(command=command, with_exceptions=True) | ||
| except GitCommandError as e: | ||
| raise errors.GitError('Cannot install Git LFS') from e | ||
mohammad-alisafaee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return repo | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.