dtool-annotation 0.2.0__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_annotation/__init__.py +9 -0
- dtool_annotation/cli.py +146 -0
- dtool_annotation-0.2.0.dist-info/METADATA +80 -0
- dtool_annotation-0.2.0.dist-info/RECORD +7 -0
- dtool_annotation-0.2.0.dist-info/WHEEL +4 -0
- dtool_annotation-0.2.0.dist-info/entry_points.txt +2 -0
- dtool_annotation-0.2.0.dist-info/licenses/LICENSE.rst +22 -0
dtool_annotation/cli.py
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"""dtool annotation CLI commands."""
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
import dtoolcore
|
|
6
|
+
import click
|
|
7
|
+
import json
|
|
8
|
+
|
|
9
|
+
from dtool_cli.cli import base_dataset_uri_argument
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _force_bool(s):
|
|
13
|
+
s = s.strip().lower()
|
|
14
|
+
if s == "0" or s == "false" or s == "f":
|
|
15
|
+
return False
|
|
16
|
+
return True
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _force_json(s):
|
|
20
|
+
return json.loads(s)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
TYPE_CHOICES = ["str", "int", "float", "bool", "json"]
|
|
24
|
+
TYPE_FUNCTION_LOOKUP = {
|
|
25
|
+
"str": str,
|
|
26
|
+
"int": int,
|
|
27
|
+
"float": float,
|
|
28
|
+
"bool": _force_bool,
|
|
29
|
+
"json": _force_json
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _validate_name(name):
|
|
34
|
+
if not dtoolcore.utils.name_is_valid(name):
|
|
35
|
+
click.secho("Invalid annotation name '{}'".format(name), fg="red")
|
|
36
|
+
click.secho(
|
|
37
|
+
"Name must be 80 characters or less",
|
|
38
|
+
)
|
|
39
|
+
click.secho(
|
|
40
|
+
"Names may only contain the characters: {}".format(
|
|
41
|
+
" ".join(dtoolcore.utils.NAME_VALID_CHARS_LIST)
|
|
42
|
+
),
|
|
43
|
+
)
|
|
44
|
+
click.secho("Example: citation-index")
|
|
45
|
+
sys.exit(400)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@click.group()
|
|
49
|
+
def annotation():
|
|
50
|
+
"""Annotations provide per dataset key/value metadata."""
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@annotation.command(name="set")
|
|
54
|
+
@base_dataset_uri_argument
|
|
55
|
+
@click.argument("key")
|
|
56
|
+
@click.argument("value")
|
|
57
|
+
@click.option(
|
|
58
|
+
"-t",
|
|
59
|
+
"--type",
|
|
60
|
+
type=click.Choice(TYPE_CHOICES),
|
|
61
|
+
default="str"
|
|
62
|
+
)
|
|
63
|
+
def set_annotation(dataset_uri, key, value, type):
|
|
64
|
+
"""Set dataset annotation (key/value pair)."""
|
|
65
|
+
try:
|
|
66
|
+
dataset = dtoolcore.ProtoDataSet.from_uri(
|
|
67
|
+
uri=dataset_uri,
|
|
68
|
+
config_path=dtoolcore.utils.DEFAULT_CONFIG_PATH
|
|
69
|
+
)
|
|
70
|
+
except dtoolcore.DtoolCoreTypeError:
|
|
71
|
+
dataset = dtoolcore.DataSet.from_uri(
|
|
72
|
+
uri=dataset_uri,
|
|
73
|
+
config_path=dtoolcore.utils.DEFAULT_CONFIG_PATH
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
_validate_name(key)
|
|
77
|
+
|
|
78
|
+
try:
|
|
79
|
+
value = TYPE_FUNCTION_LOOKUP[type](value)
|
|
80
|
+
except ValueError as e:
|
|
81
|
+
click.secho(str(e).capitalize(), err=True, fg="red")
|
|
82
|
+
sys.exit(402)
|
|
83
|
+
dataset.put_annotation(key, value)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
@annotation.command(name="get")
|
|
87
|
+
@base_dataset_uri_argument
|
|
88
|
+
@click.argument("key")
|
|
89
|
+
def get_annotation(dataset_uri, key):
|
|
90
|
+
"""Get dataset annotation (value associated with the input key)."""
|
|
91
|
+
try:
|
|
92
|
+
dataset = dtoolcore.ProtoDataSet.from_uri(
|
|
93
|
+
uri=dataset_uri,
|
|
94
|
+
config_path=dtoolcore.utils.DEFAULT_CONFIG_PATH
|
|
95
|
+
)
|
|
96
|
+
except dtoolcore.DtoolCoreTypeError:
|
|
97
|
+
dataset = dtoolcore.DataSet.from_uri(
|
|
98
|
+
uri=dataset_uri,
|
|
99
|
+
config_path=dtoolcore.utils.DEFAULT_CONFIG_PATH
|
|
100
|
+
)
|
|
101
|
+
try:
|
|
102
|
+
click.secho(str(dataset.get_annotation(key)))
|
|
103
|
+
except dtoolcore.DtoolCoreKeyError:
|
|
104
|
+
click.secho(
|
|
105
|
+
"No annotation named: '{}'".format(key),
|
|
106
|
+
err=True,
|
|
107
|
+
fg="red"
|
|
108
|
+
)
|
|
109
|
+
sys.exit(401)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
@annotation.command(name="ls")
|
|
113
|
+
@base_dataset_uri_argument
|
|
114
|
+
def list_annotations(dataset_uri):
|
|
115
|
+
"""List the dataset annotations."""
|
|
116
|
+
try:
|
|
117
|
+
dataset = dtoolcore.ProtoDataSet.from_uri(
|
|
118
|
+
uri=dataset_uri,
|
|
119
|
+
config_path=dtoolcore.utils.DEFAULT_CONFIG_PATH
|
|
120
|
+
)
|
|
121
|
+
except dtoolcore.DtoolCoreTypeError:
|
|
122
|
+
dataset = dtoolcore.DataSet.from_uri(
|
|
123
|
+
uri=dataset_uri,
|
|
124
|
+
config_path=dtoolcore.utils.DEFAULT_CONFIG_PATH
|
|
125
|
+
)
|
|
126
|
+
for name in sorted(dataset.list_annotation_names()):
|
|
127
|
+
value = str(dataset.get_annotation(name))
|
|
128
|
+
click.secho("{}\t{}".format(name, value))
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
@annotation.command(name="delete")
|
|
132
|
+
@base_dataset_uri_argument
|
|
133
|
+
@click.argument("key")
|
|
134
|
+
def delete_annotation(dataset_uri, key):
|
|
135
|
+
"""Delete dataset annotation."""
|
|
136
|
+
try:
|
|
137
|
+
dataset = dtoolcore.ProtoDataSet.from_uri(
|
|
138
|
+
uri=dataset_uri,
|
|
139
|
+
config_path=dtoolcore.utils.DEFAULT_CONFIG_PATH
|
|
140
|
+
)
|
|
141
|
+
except dtoolcore.DtoolCoreTypeError:
|
|
142
|
+
dataset = dtoolcore.DataSet.from_uri(
|
|
143
|
+
uri=dataset_uri,
|
|
144
|
+
config_path=dtoolcore.utils.DEFAULT_CONFIG_PATH
|
|
145
|
+
)
|
|
146
|
+
dataset.delete_annotation(key)
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: dtool-annotation
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Add ability to annotate datasets using the dtool CLI
|
|
5
|
+
Project-URL: Repository, https://github.com/jic-dtool/dtool-annotation
|
|
6
|
+
Author-email: Tjelvar Olsson <tjelvar.olsson@gmail.com>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE.rst
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Requires-Dist: click
|
|
11
|
+
Requires-Dist: dtool-cli>=0.7.2
|
|
12
|
+
Requires-Dist: dtoolcore>=3.19.0
|
|
13
|
+
Description-Content-Type: text/x-rst
|
|
14
|
+
|
|
15
|
+
dtool CLI commands for working with per dataset metadata (annotations)
|
|
16
|
+
======================================================================
|
|
17
|
+
|
|
18
|
+
.. image:: https://badge.fury.io/py/dtool-annotation.svg
|
|
19
|
+
:target: http://badge.fury.io/py/dtool-annotation
|
|
20
|
+
:alt: PyPi package
|
|
21
|
+
|
|
22
|
+
.. image:: https://github.com/jic-dtool/dtool-annotation/actions/workflows/test.yml/badge.svg?branch=main
|
|
23
|
+
:target: https://github.com/jic-dtool/dtool-annotation/actions/workflows/test.yml
|
|
24
|
+
:alt: Tests
|
|
25
|
+
|
|
26
|
+
.. image:: https://codecov.io/github/jic-dtool/dtool-annotation/coverage.svg?branch=main
|
|
27
|
+
:target: https://codecov.io/github/jic-dtool/dtool-annotation?branch=main
|
|
28
|
+
:alt: Code Coverage
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
Installation
|
|
32
|
+
------------
|
|
33
|
+
|
|
34
|
+
::
|
|
35
|
+
|
|
36
|
+
$ pip install dtool-annotation
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
Example usage
|
|
40
|
+
-------------
|
|
41
|
+
|
|
42
|
+
Get a dataset to play with::
|
|
43
|
+
|
|
44
|
+
$ LOCAL_DS_URI=$(dtool cp -q http://bit.ly/Ecoli-ref-genome .)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
Add an annotation::
|
|
48
|
+
|
|
49
|
+
$ dtool annotation set $LOCAL_DS_URI project dtool-demo
|
|
50
|
+
|
|
51
|
+
Get an annotation::
|
|
52
|
+
|
|
53
|
+
$ dtool annotation get $LOCAL_DS_URI project
|
|
54
|
+
dtool-demo
|
|
55
|
+
|
|
56
|
+
Add an annotation forcing a specific type::
|
|
57
|
+
|
|
58
|
+
$ dtool annotation set --type int $LOCAL_DS_URI stars 3
|
|
59
|
+
|
|
60
|
+
List all annotations::
|
|
61
|
+
|
|
62
|
+
$ dtool annotation ls $LOCAL_DS_URI
|
|
63
|
+
project dtool-demo
|
|
64
|
+
stars 3
|
|
65
|
+
|
|
66
|
+
Delete an annotation::
|
|
67
|
+
|
|
68
|
+
$ dtool annotation delete $LOCAL_DS_URI stars
|
|
69
|
+
$ dtool annotation ls $LOCAL_DS_URI
|
|
70
|
+
project dtool-demo
|
|
71
|
+
|
|
72
|
+
For more information see the `dtool documentation <https://dtool.readthedocs.io>`_.
|
|
73
|
+
|
|
74
|
+
Related packages
|
|
75
|
+
----------------
|
|
76
|
+
|
|
77
|
+
- `dtoolcore <https://github.com/jic-dtool/dtoolcore>`_
|
|
78
|
+
- `dtool-cli <https://github.com/jic-dtool/dtool-cli>`_
|
|
79
|
+
- `dtool-create <https://github.com/jic-dtool/dtool-create>`_
|
|
80
|
+
- `dtool-overlay <https://github.com/jic-dtool/dtool-overlay>`_
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
dtool_annotation/__init__.py,sha256=wHB3-UA7FVtOOlMU9UiOvtteD3yGHAazNtsYhH2TrZE,235
|
|
2
|
+
dtool_annotation/cli.py,sha256=zUzBx0X6I2yKiEfH_6hE9Hss-Xu14wVDPd_SSShchVU,3939
|
|
3
|
+
dtool_annotation-0.2.0.dist-info/METADATA,sha256=cmJfUCMW76LDr8c9-vmWsSVzW9isa_WrIjWzu-06t-0,2189
|
|
4
|
+
dtool_annotation-0.2.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
5
|
+
dtool_annotation-0.2.0.dist-info/entry_points.txt,sha256=QmwXESzuegQoR2BpHGWKRLdUIx9Ui3-ooULAB4Wn8nE,57
|
|
6
|
+
dtool_annotation-0.2.0.dist-info/licenses/LICENSE.rst,sha256=3wTaQ15u0aBGHi11jgv7TVKeFDmJBRUWd53t79rsUhs,1083
|
|
7
|
+
dtool_annotation-0.2.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
===========
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2019 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.
|