/
__init__.py
218 lines (186 loc) · 6.92 KB
/
__init__.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# -*- coding: utf-8 -*-
#
# Copyright 2017-2021 - 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.
r"""The base command for interacting with the Renku platform.
``renku`` (base command)
------------------------
To list the available commands, either run ``renku`` with no parameters or
execute ``renku help``:
.. code-block:: console
$ renku help
Usage: renku [OPTIONS] COMMAND [ARGS]...
Check common Renku commands used in various situations.
Options:
--version Print version number.
--global-config-path Print global application's config path.
--install-completion Install completion for the current shell.
--path <path> Location of a Renku repository.
[default: (dynamic)]
--external-storage / -S, --no-external-storage
Use an external file storage service.
-h, --help Show this message and exit.
Commands:
# [...]
Configuration files
~~~~~~~~~~~~~~~~~~~
Depending on your system, you may find the configuration files used by Renku
command line in a different folder. By default, the following rules are used:
MacOS:
``~/Library/Application Support/Renku``
Unix:
``~/.config/renku``
Windows:
``C:\Users\<user>\AppData\Roaming\Renku``
If in doubt where to look for the configuration file, you can display its path
by running ``renku --global-config-path``.
"""
import os
import sys
import uuid
from pathlib import Path
import click
import click_completion
import yaml
from click_plugins import with_plugins
from pkg_resources import iter_entry_points
from renku.cli.clone import clone
from renku.cli.config import config
from renku.cli.dataset import dataset
from renku.cli.doctor import doctor
from renku.cli.exception_handler import IssueFromTraceback
from renku.cli.githooks import githooks as githooks_command
from renku.cli.graph import graph
from renku.cli.init import init as init_command
from renku.cli.login import login, logout, token
from renku.cli.migrate import check_immutable_template_files, migrate, migrationscheck
from renku.cli.move import move
from renku.cli.project import project
from renku.cli.remove import remove
from renku.cli.rerun import rerun
from renku.cli.run import run
from renku.cli.save import save
from renku.cli.service import service
from renku.cli.show import show
from renku.cli.status import status
from renku.cli.storage import storage
from renku.cli.update import update
from renku.cli.workflow import workflow
from renku.core.commands.echo import WARNING
from renku.core.commands.options import install_completion, option_external_storage_requested
from renku.core.commands.version import check_version, print_version
from renku.core.errors import UsageError
from renku.core.management.client import LocalClient
from renku.core.management.config import RENKU_HOME, ConfigManagerMixin
from renku.core.management.repository import default_path
#: Monkeypatch Click application.
click_completion.init()
WARNING_UNPROTECTED_COMMANDS = ["clone", "init", "help", "login", "logout", "service"]
def _uuid_representer(dumper, data):
"""Add UUID serializer for YAML."""
return dumper.represent_str(str(data))
yaml.add_representer(uuid.UUID, _uuid_representer)
def print_global_config_path(ctx, param, value):
"""Print global application's config path."""
if not value or ctx.resilient_parsing:
return
click.echo(ConfigManagerMixin().global_config_path)
ctx.exit()
def is_allowed_command(ctx):
"""Check if invoked command contains help command."""
return ctx.invoked_subcommand in WARNING_UNPROTECTED_COMMANDS or "-h" in sys.argv or "--help" in sys.argv
@with_plugins(iter_entry_points("renku.cli_plugins"))
@click.group(
cls=IssueFromTraceback, context_settings={"auto_envvar_prefix": "RENKU", "help_option_names": ["-h", "--help"]}
)
@click.option(
"--version", is_flag=True, callback=print_version, expose_value=False, is_eager=True, help=print_version.__doc__
)
@click.option(
"--global-config-path",
is_flag=True,
callback=print_global_config_path,
expose_value=False,
is_eager=True,
help=print_global_config_path.__doc__,
)
@click.option(
"--install-completion",
is_flag=True,
callback=install_completion,
expose_value=False,
is_eager=True,
help=install_completion.__doc__,
)
@click.option(
"--path", show_default=True, metavar="<path>", default=default_path, help="Location of a Renku repository."
)
@option_external_storage_requested
@click.option(
"--disable-version-check",
envvar="RENKU_DISABLE_VERSION_CHECK",
is_flag=True,
default=False,
callback=check_version,
expose_value=False,
help="Do not periodically check PyPI for a new version of renku.",
)
@click.pass_context
def cli(ctx, path, external_storage_requested):
"""Check common Renku commands used in various situations."""
renku_path = Path(path) / RENKU_HOME
if not renku_path.exists() and not is_allowed_command(ctx):
raise UsageError(
(
"`{0}` is not a renku repository.\n"
"To initialize this as a renku "
"repository use: `renku init`".format(path)
)
)
ctx.obj = LocalClient(path=path, external_storage_requested=external_storage_requested)
if path != os.getcwd() and ctx.invoked_subcommand not in WARNING_UNPROTECTED_COMMANDS:
click.secho(WARNING + "Run CLI commands only from project's root directory.\n", err=True)
@cli.command()
@click.pass_context
def help(ctx):
"""Show help message and exit."""
click.echo(ctx.parent.get_help())
# Register subcommands:
cli.add_command(clone)
cli.add_command(config)
cli.add_command(dataset)
cli.add_command(doctor)
cli.add_command(githooks_command)
cli.add_command(graph)
cli.add_command(init_command)
cli.add_command(login)
cli.add_command(logout)
cli.add_command(migrate)
cli.add_command(migrationscheck)
cli.add_command(check_immutable_template_files)
cli.add_command(move)
cli.add_command(project)
cli.add_command(remove)
cli.add_command(rerun)
cli.add_command(run)
cli.add_command(save)
cli.add_command(show)
cli.add_command(status)
cli.add_command(storage)
cli.add_command(token)
cli.add_command(update)
cli.add_command(workflow)
cli.add_command(service)