dtool-cli 0.7.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
dtool_cli/__init__.py
ADDED
dtool_cli/cli.py
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"""Skeleton defining the dtool plugin entry points."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import logging
|
|
5
|
+
|
|
6
|
+
from importlib.metadata import entry_points
|
|
7
|
+
|
|
8
|
+
import click
|
|
9
|
+
from click_plugins import with_plugins
|
|
10
|
+
|
|
11
|
+
import dtoolcore
|
|
12
|
+
import dtoolcore.utils
|
|
13
|
+
|
|
14
|
+
try:
|
|
15
|
+
from dtool import __version__ as dtool_version
|
|
16
|
+
except ImportError:
|
|
17
|
+
dtool_version = ""
|
|
18
|
+
|
|
19
|
+
from . import __version__
|
|
20
|
+
|
|
21
|
+
_CLICK_CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
|
|
22
|
+
CONFIG_PATH = os.path.expanduser("~/.config/dtool/dtool.json")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def iter_entry_points(group):
|
|
26
|
+
"""Yield the entry points registered under ``group``."""
|
|
27
|
+
return entry_points(group=group)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def storagebroker_validation(ctx, param, value):
|
|
31
|
+
storage_broker_lookup = dtoolcore._generate_storage_broker_lookup()
|
|
32
|
+
if value not in storage_broker_lookup:
|
|
33
|
+
raise click.BadParameter(
|
|
34
|
+
"'{}' not in {}".format(value, storage_broker_lookup.keys()))
|
|
35
|
+
return value
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def base_dataset_uri_validation(ctx, param, value):
|
|
39
|
+
value = dtoolcore.utils.sanitise_uri(value)
|
|
40
|
+
if not dtoolcore._is_dataset(value, config_path=CONFIG_PATH):
|
|
41
|
+
raise click.BadParameter(
|
|
42
|
+
"URI is not a dataset: {}".format(value))
|
|
43
|
+
return value
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def proto_dataset_uri_validation(ctx, param, value):
|
|
47
|
+
value = base_dataset_uri_validation(ctx, param, value)
|
|
48
|
+
admin_metadata = dtoolcore._admin_metadata_from_uri(
|
|
49
|
+
uri=value,
|
|
50
|
+
config_path=CONFIG_PATH
|
|
51
|
+
)
|
|
52
|
+
if admin_metadata["type"] != "protodataset":
|
|
53
|
+
message_lines = [
|
|
54
|
+
"\nURI is not a proto dataset: {}".format(value),
|
|
55
|
+
"It looks like a frozen dataset",
|
|
56
|
+
]
|
|
57
|
+
raise click.BadParameter("\n".join(message_lines))
|
|
58
|
+
return value
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def dataset_uri_validation(ctx, param, value):
|
|
62
|
+
value = base_dataset_uri_validation(ctx, param, value)
|
|
63
|
+
admin_metadata = dtoolcore._admin_metadata_from_uri(
|
|
64
|
+
uri=value,
|
|
65
|
+
config_path=CONFIG_PATH
|
|
66
|
+
)
|
|
67
|
+
if admin_metadata["type"] != "dataset":
|
|
68
|
+
message_lines = [
|
|
69
|
+
"\nURI is not a frozen dataset: {}".format(value),
|
|
70
|
+
"It looks like a proto dataset",
|
|
71
|
+
]
|
|
72
|
+
raise click.BadParameter("\n".join(message_lines))
|
|
73
|
+
return value
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
base_dataset_uri_argument = click.argument(
|
|
77
|
+
"dataset_uri",
|
|
78
|
+
callback=base_dataset_uri_validation
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
proto_dataset_uri_argument = click.argument(
|
|
83
|
+
"proto_dataset_uri",
|
|
84
|
+
callback=proto_dataset_uri_validation
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
dataset_uri_argument = click.argument(
|
|
89
|
+
"dataset_uri",
|
|
90
|
+
callback=dataset_uri_validation
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def _package_version(package):
|
|
95
|
+
"""Return the ``__version__`` of ``package``, or "unknown".
|
|
96
|
+
|
|
97
|
+
A plugin that cannot be imported or that lacks ``__version__`` must not
|
|
98
|
+
break the version listing.
|
|
99
|
+
"""
|
|
100
|
+
try:
|
|
101
|
+
return __import__(package).__version__
|
|
102
|
+
except Exception:
|
|
103
|
+
return "unknown"
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def _storage_broker_key(ep):
|
|
107
|
+
"""Return the key of the storage broker behind entry point ``ep``."""
|
|
108
|
+
try:
|
|
109
|
+
return ep.load().key
|
|
110
|
+
except Exception:
|
|
111
|
+
return ep.name
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def pretty_version_text():
|
|
115
|
+
"""Return pretty version text listing all plugins."""
|
|
116
|
+
version_lines = ["dtool, version {}".format(dtool_version)]
|
|
117
|
+
version_lines.append("\nBase:")
|
|
118
|
+
version_lines.append("dtoolcore, version {}".format(dtoolcore.__version__))
|
|
119
|
+
version_lines.append("dtool-cli, version {}".format(__version__))
|
|
120
|
+
|
|
121
|
+
# List the storage broker packages.
|
|
122
|
+
version_lines.append("\nStorage brokers:")
|
|
123
|
+
for ep in iter_entry_points("dtool.storage_brokers"):
|
|
124
|
+
package = ep.module.split(".")[0]
|
|
125
|
+
version_lines.append(
|
|
126
|
+
"{}, {}, version {}".format(
|
|
127
|
+
_storage_broker_key(ep),
|
|
128
|
+
package.replace("_", "-"),
|
|
129
|
+
_package_version(package)))
|
|
130
|
+
|
|
131
|
+
# List the plugin packages.
|
|
132
|
+
modules = [ep.module for ep in iter_entry_points("dtool.cli")]
|
|
133
|
+
packages = set([m.split(".")[0] for m in modules])
|
|
134
|
+
version_lines.append("\nPlugins:")
|
|
135
|
+
for p in packages:
|
|
136
|
+
version_lines.append(
|
|
137
|
+
"{}, version {}".format(
|
|
138
|
+
p.replace("_", "-"),
|
|
139
|
+
_package_version(p)))
|
|
140
|
+
|
|
141
|
+
return "\n".join(version_lines)
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _print_version(ctx, param, value):
|
|
145
|
+
"""Print the version of dtool and its plugins, then exit.
|
|
146
|
+
|
|
147
|
+
The text is only built when ``--version`` is given: building it imports
|
|
148
|
+
every plugin, which should neither slow down nor be able to break other
|
|
149
|
+
invocations of ``dtool``.
|
|
150
|
+
"""
|
|
151
|
+
if not value or ctx.resilient_parsing:
|
|
152
|
+
return
|
|
153
|
+
click.echo(pretty_version_text())
|
|
154
|
+
ctx.exit()
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
@with_plugins(iter_entry_points("dtool.cli"))
|
|
158
|
+
@click.group(context_settings=_CLICK_CONTEXT_SETTINGS)
|
|
159
|
+
@click.option("--version", is_flag=True, expose_value=False, is_eager=True,
|
|
160
|
+
callback=_print_version, help="Show the version and exit.")
|
|
161
|
+
@click.option("--debug", is_flag=True, help="Turn on debugging output.")
|
|
162
|
+
def dtool(debug):
|
|
163
|
+
"""Tool to work with datasets."""
|
|
164
|
+
level = logging.WARNING
|
|
165
|
+
if debug:
|
|
166
|
+
level = logging.DEBUG
|
|
167
|
+
logging.basicConfig(
|
|
168
|
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
|
169
|
+
level=level)
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: dtool-cli
|
|
3
|
+
Version: 0.7.2
|
|
4
|
+
Summary: Data management command line tool: dtool.
|
|
5
|
+
Project-URL: Repository, https://github.com/jic-dtool/dtool-cli
|
|
6
|
+
Author-email: Tjelvar Olsson <tjelvar.olsson@gmail.com>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE.rst
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Requires-Dist: click
|
|
16
|
+
Requires-Dist: click-plugins
|
|
17
|
+
Requires-Dist: dtoolcore>=2
|
|
18
|
+
Description-Content-Type: text/x-rst
|
|
19
|
+
|
|
20
|
+
README
|
|
21
|
+
======
|
|
22
|
+
|
|
23
|
+
Data management command line tool: dtool.
|
|
24
|
+
|
|
25
|
+
Overview
|
|
26
|
+
--------
|
|
27
|
+
|
|
28
|
+
The ``dtool-cli`` python package provides a skeleton command line interface to
|
|
29
|
+
dtool that other "dtool" command line packages can be plugged into.
|
|
30
|
+
|
|
31
|
+
It makes use of `click <https://github.com/pallets/click>`_ and `click-plugins
|
|
32
|
+
<https://github.com/click-contrib/click-plugins>`_.
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
Creating a plugin
|
|
36
|
+
-----------------
|
|
37
|
+
|
|
38
|
+
The ``dtool-cli`` plug-in system exposes name space ``dtool.cli`` for
|
|
39
|
+
registering commands.
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
To create a ``dtool-cli`` plug-in, create a Python package and register the
|
|
43
|
+
click commands of interest as entry points in its ``pyproject.toml`` file.
|
|
44
|
+
Below is the content of a hypothetical ``dtool_create/__init__.py`` file::
|
|
45
|
+
|
|
46
|
+
import click
|
|
47
|
+
|
|
48
|
+
@click.command()
|
|
49
|
+
def create():
|
|
50
|
+
print("Creating dataset...")
|
|
51
|
+
|
|
52
|
+
@click.command()
|
|
53
|
+
def freeze():
|
|
54
|
+
print("Freezing dataset...")
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
To create entry points for these commands add the below to the
|
|
58
|
+
``pyproject.toml``::
|
|
59
|
+
|
|
60
|
+
[project.entry-points."dtool.cli"]
|
|
61
|
+
create = "dtool_create:create"
|
|
62
|
+
freeze = "dtool_create:freeze"
|
|
63
|
+
|
|
64
|
+
The entry points must refer to click commands (or groups). Plain functions,
|
|
65
|
+
e.g. ``argparse`` based scripts, belong under ``[project.scripts]`` instead.
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
Installation
|
|
70
|
+
------------
|
|
71
|
+
|
|
72
|
+
To install the dtool-cli package.
|
|
73
|
+
|
|
74
|
+
.. code-block:: bash
|
|
75
|
+
|
|
76
|
+
cd dtool-cli
|
|
77
|
+
pip install .
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
dtool_cli/__init__.py,sha256=9vDVw_knv2SefGlw-QJ1pVy9ABRT5BtCDo_RxKoFtfA,220
|
|
2
|
+
dtool_cli/cli.py,sha256=afgw0DLYBbEe0FXpqLVUL_ayzFMj2b096msyMpc_nb8,5077
|
|
3
|
+
dtool_cli-0.7.2.dist-info/METADATA,sha256=lh9MLykFUMEWkaBG0SIaTnXM0zqPwQCZXT7N4yinRo8,2028
|
|
4
|
+
dtool_cli-0.7.2.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
5
|
+
dtool_cli-0.7.2.dist-info/entry_points.txt,sha256=psKGeW12vAnHWmOZYscpXx91D5vEzivCzvtT8ag7k2o,46
|
|
6
|
+
dtool_cli-0.7.2.dist-info/licenses/LICENSE.rst,sha256=86aJiAkXSLnTuXcSVW8_TVdYTbp2of-veyzp3a3A3uA,1083
|
|
7
|
+
dtool_cli-0.7.2.dist-info/RECORD,,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
===========
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2017 Tjelvar Olsson
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|