• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SwissDataScienceCenter / renku-python / 5948296099

23 Aug 2023 07:23AM UTC coverage: 85.801% (+0.04%) from 85.766%
5948296099

Pull #3601

github-actions

olevski
chore: run poetry lock
Pull Request #3601: hotfix: v2.6.1

40 of 48 new or added lines in 10 files covered. (83.33%)

285 existing lines in 25 files now uncovered.

25875 of 30157 relevant lines covered (85.8%)

4.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.9
/renku/ui/cli/__init__.py
1
#
2
# Copyright 2017-2023 - Swiss Data Science Center (SDSC)
3
# A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and
4
# Eidgenössische Technische Hochschule Zürich (ETHZ).
5
#
6
# Licensed under the Apache License, Version 2.0 (the "License");
7
# you may not use this file except in compliance with the License.
8
# You may obtain a copy of the License at
9
#
10
#     http://www.apache.org/licenses/LICENSE-2.0
11
#
12
# Unless required by applicable law or agreed to in writing, software
13
# distributed under the License is distributed on an "AS IS" BASIS,
14
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
# See the License for the specific language governing permissions and
16
# limitations under the License.
17
r"""The base command for interacting with the Renku platform.
11✔
18

19
renku (base command)
20
********************
21

22
To list the available commands, either run ``renku`` with no parameters or
23
execute ``renku help``:
24

25
.. code-block:: console
26

27
    $ renku help
28
    Usage: renku [OPTIONS] COMMAND [ARGS]...
29

30
    Check common Renku commands used in various situations.
31

32

33
    Options:
34
      --version                       Print version number.
35
      --global-config-path            Print global application's config path.
36
      --path <path>                   Location of a Renku repository.
37
                                      [default: (dynamic)]
38
      --external-storage / -S, --no-external-storage
39
                                      Use an external file storage service.
40
      -h, --help                      Show this message and exit.
41

42
    Commands:
43
      # [...]
44

45
Configuration files
46
~~~~~~~~~~~~~~~~~~~
47

48
Depending on your system, you may find the configuration files used by Renku
49
command line in a different folder. By default, the following rules are used:
50

51
MacOS:
52
  ``~/Library/Application Support/Renku``
53
Unix:
54
  ``~/.config/renku``
55
Windows:
56
  ``C:\Users\<user>\AppData\Roaming\Renku``
57

58
If in doubt where to look for the configuration file, you can display its path
59
by running ``renku --global-config-path``.
60

61
.. cheatsheet::
62
   :group: Typical Workflow
63
   :command: $ git status
64
   :description: Take a look at what you have done since the last save.
65
   :target: ui,rp
66

67
.. cheatsheet::
68
   :group: Typical Workflow
69
   :command: $ renku save -m <msg>
70
   :description: Save your latest work, providing a message explaining what you have done.
71
   :target: ui,rp
72

73
.. cheatsheet::
74
   :group: Typical Workflow
75
   :command: $ renku run …
76
   :description: Run your code, capturing lineage of the inputs and outputs using Renku.
77
   :target: ui,rp
78

79
"""
80
import os
11✔
81
import sys
11✔
82
import uuid
11✔
83
from pathlib import Path
11✔
84

85
import click
11✔
86
import yaml
11✔
87
from click_plugins import with_plugins
11✔
88

89
from renku.command.options import option_external_storage_requested
11✔
90
from renku.command.util import WARNING
11✔
91
from renku.command.version import print_version
11✔
92
from renku.core import errors
11✔
93
from renku.core.constant import DATABASE_PATH
11✔
94
from renku.core.util.git import get_git_path
11✔
95
from renku.domain_model.project_context import project_context
11✔
96
from renku.ui.cli.clone import clone
11✔
97
from renku.ui.cli.config import config
11✔
98
from renku.ui.cli.dataset import dataset
11✔
99
from renku.ui.cli.doctor import doctor
11✔
100
from renku.ui.cli.env import env
11✔
101
from renku.ui.cli.exception_handler import IssueFromTraceback
11✔
102
from renku.ui.cli.gc import gc
11✔
103
from renku.ui.cli.githooks import githooks as githooks_command
11✔
104
from renku.ui.cli.graph import graph
11✔
105
from renku.ui.cli.init import init
11✔
106
from renku.ui.cli.log import log
11✔
107
from renku.ui.cli.login import credentials, login, logout
11✔
108
from renku.ui.cli.mergetool import mergetool
11✔
109
from renku.ui.cli.migrate import check_immutable_template_files, migrate, migrationscheck
11✔
110
from renku.ui.cli.move import move
11✔
111
from renku.ui.cli.project import project
11✔
112
from renku.ui.cli.remove import remove
11✔
113
from renku.ui.cli.rerun import rerun
11✔
114
from renku.ui.cli.rollback import rollback
11✔
115
from renku.ui.cli.run import run
11✔
116
from renku.ui.cli.save import save
11✔
117
from renku.ui.cli.service import service
11✔
118
from renku.ui.cli.session import session
11✔
119
from renku.ui.cli.status import status
11✔
120
from renku.ui.cli.storage import storage
11✔
121
from renku.ui.cli.template import template
11✔
122
from renku.ui.cli.update import update
11✔
123
from renku.ui.cli.workflow import workflow
11✔
124

125
try:
11✔
126
    from importlib.metadata import entry_points
11✔
127
except ImportError:
×
128
    from importlib_metadata import entry_points  # type: ignore
×
129

130

131
def get_entry_points(name: str):
11✔
132
    """Get entry points from importlib."""
133
    all_entry_points = entry_points()
11✔
134

135
    if hasattr(all_entry_points, "select"):
11✔
136
        return all_entry_points.select(group=name)  # type: ignore
11✔
137
    else:
138
        # Prior to Python 3.10, this returns a dict instead of the selection interface, which is slightly slower
UNCOV
139
        return all_entry_points.get(name, [])
×
140

141

142
WARNING_UNPROTECTED_COMMANDS = ["clone", "credentials", "env", "help", "init", "login", "logout", "service", "template"]
11✔
143

144
WARNING_UNPROTECTED_SUBCOMMANDS = {"template": ["ls", "show", "validate"]}
11✔
145

146

147
def _uuid_representer(dumper, data):
11✔
148
    """Add UUID serializer for YAML."""
149
    return dumper.represent_str(str(data))
×
150

151

152
def _is_renku_project(path: Path) -> bool:
11✔
153
    """Check if a path is a renku project."""
154
    from renku.core.constant import RENKU_HOME
9✔
155
    from renku.core.migration.utils import OLD_METADATA_PATH
9✔
156
    from renku.infrastructure.database import Database
9✔
157

158
    metadata_path = Path(path) / RENKU_HOME
9✔
159
    old_metadata = metadata_path / OLD_METADATA_PATH
9✔
160
    new_metadata = metadata_path / DATABASE_PATH / Database.ROOT_OID
9✔
161

162
    return old_metadata.exists() or new_metadata.exists()
9✔
163

164

165
yaml.add_representer(uuid.UUID, _uuid_representer)
11✔
166

167

168
def print_global_config_path(ctx, _, value):
11✔
169
    """Print global application's config path."""
170
    if not value or ctx.resilient_parsing:
9✔
171
        return
9✔
172

173
    click.echo(project_context.global_config_path)
2✔
174
    ctx.exit()
2✔
175

176

177
def is_allowed_subcommand(ctx):
11✔
178
    """Called from subcommands to check if their sub-subcommand is allowed.
179

180
    Subcommands where some sub-subcommands are allowed should be added to ``WARNING_UNPROTECTED_COMMANDS`` so they pass
181
    through the parent check and then added to ``WARNING_UNPROTECTED_SUBCOMMANDS`` so they get checked here.
182
    """
183
    from renku.domain_model.project_context import project_context
4✔
184

185
    if not _is_renku_project(project_context.path) and (
4✔
186
        not WARNING_UNPROTECTED_SUBCOMMANDS.get(ctx.command.name, False)
187
        or ctx.invoked_subcommand not in WARNING_UNPROTECTED_SUBCOMMANDS[ctx.command.name]
188
    ):
189
        raise errors.UsageError(
2✔
190
            f"{project_context.path} is not a renku repository.\n"
191
            "To initialize this as a renku repository use: 'renku init'"
192
        )
193

194

195
def is_allowed_command(ctx):
11✔
196
    """Check if invoked command contains help command."""
197

198
    return ctx.invoked_subcommand in WARNING_UNPROTECTED_COMMANDS or "-h" in sys.argv or "--help" in sys.argv
9✔
199

200

201
@with_plugins(get_entry_points("renku.cli_plugins"))
11✔
202
@click.group(
11✔
203
    cls=IssueFromTraceback, context_settings={"auto_envvar_prefix": "RENKU", "help_option_names": ["-h", "--help"]}
204
)
205
@click.option(
11✔
206
    "--version", is_flag=True, callback=print_version, expose_value=False, is_eager=True, help=print_version.__doc__
207
)
208
@click.option(
11✔
209
    "--global-config-path",
210
    is_flag=True,
211
    callback=print_global_config_path,
212
    expose_value=False,
213
    is_eager=True,
214
    help=print_global_config_path.__doc__,
215
)
216
@click.option(
11✔
217
    "--path", show_default=True, metavar="<path>", default=get_git_path, help="Location of a Renku repository."
218
)
219
@option_external_storage_requested
11✔
220
@click.pass_context
11✔
221
def cli(ctx, path, external_storage_requested):
11✔
222
    """Check common Renku commands used in various situations."""
223
    from renku.domain_model.project_context import project_context
9✔
224

225
    path = Path(path)
9✔
226

227
    is_command_allowed = is_allowed_command(ctx)
9✔
228
    is_renku_project = _is_renku_project(path)
9✔
229

230
    if not is_renku_project and not is_command_allowed:
9✔
231
        raise errors.UsageError(
2✔
232
            f"{path} is not a renku repository.\n" "To initialize this as a renku repository use: 'renku init'"
233
        )
234

235
    project_context.push_path(path)
9✔
236
    project_context.external_storage_requested = external_storage_requested
9✔
237

238
    if is_renku_project and path != Path(os.getcwd()) and not is_command_allowed:
9✔
239
        click.secho(WARNING + "Run CLI commands only from project's root directory.\n", err=True)
4✔
240

241

242
@cli.command()
11✔
243
@click.pass_context
11✔
244
def help(ctx):
11✔
245
    """Show help message and exit."""
246
    click.echo(ctx.parent.get_help())
4✔
247

248

249
# Register subcommands:
250
cli.add_command(check_immutable_template_files)
11✔
251
cli.add_command(clone)
11✔
252
cli.add_command(config)
11✔
253
cli.add_command(credentials)
11✔
254
cli.add_command(dataset)
11✔
255
cli.add_command(doctor)
11✔
256
cli.add_command(env)
11✔
257
cli.add_command(gc)
11✔
258
cli.add_command(githooks_command)
11✔
259
cli.add_command(graph)
11✔
260
cli.add_command(init)
11✔
261
cli.add_command(log)
11✔
262
cli.add_command(login)
11✔
263
cli.add_command(logout)
11✔
264
cli.add_command(mergetool)
11✔
265
cli.add_command(migrate)
11✔
266
cli.add_command(migrationscheck)
11✔
267
cli.add_command(move)
11✔
268
cli.add_command(project)
11✔
269
cli.add_command(remove)
11✔
270
cli.add_command(rerun)
11✔
271
cli.add_command(rollback)
11✔
272
cli.add_command(run)
11✔
273
cli.add_command(save)
11✔
274
cli.add_command(service)
11✔
275
cli.add_command(session)
11✔
276
cli.add_command(status)
11✔
277
cli.add_command(storage)
11✔
278
cli.add_command(template)
11✔
279
cli.add_command(update)
11✔
280
cli.add_command(workflow)
11✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc