[ARVADOS] updated: 2.1.0-1984-gb6ffac07e

Git user git at public.arvados.org
Wed Mar 2 19:08:54 UTC 2022


Summary of changes:
 doc/sdk/python/cookbook.html.textile.liquid | 30 +++++++++++++++++++++++++++++
 sdk/python/arvados/vocabulary.py            |  4 ++--
 sdk/python/tests/test_vocabulary.py         |  1 +
 3 files changed, 33 insertions(+), 2 deletions(-)

       via  b6ffac07e22120b0d15d2d16fd13e2899192084b (commit)
       via  dd012fa790bc506895dc8e47496c3e8a537d1400 (commit)
      from  a480283b6fe33bd0df12d879c835427e1b71489a (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit b6ffac07e22120b0d15d2d16fd13e2899192084b
Author: Lucas Di Pentima <lucas.dipentima at curii.com>
Date:   Wed Mar 2 16:08:18 2022 -0300

    18574: Adds some documentation's cookbook examples.
    
    Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas.dipentima at curii.com>

diff --git a/doc/sdk/python/cookbook.html.textile.liquid b/doc/sdk/python/cookbook.html.textile.liquid
index eda6563d7..cce25f1a3 100644
--- a/doc/sdk/python/cookbook.html.textile.liquid
+++ b/doc/sdk/python/cookbook.html.textile.liquid
@@ -298,3 +298,33 @@ api = arvados.api()
 for c in arvados.util.keyset_list_all(api.collections().list, filters=[["name", "like", "%sample123%"]]):
     print("got collection " + c["uuid"])
 {% endcodeblock %}
+
+h2. Querying the vocabulary definition
+
+The Python SDK provides facilities to interact with the "active metadata vocabulary":{{ site.baseurl }}/admin/metadata-vocabulary.html in the system. The developer can do key and value lookups in a case-insensitive manner:
+
+{% codeblock as python %}
+>>> from arvados import api, vocabulary
+>>> voc = vocabulary.load_vocabulary(api('v1'))
+>>> [k.identifier for k in set(voc.key_aliases.values())]
+['IDTAGCOLORS', 'IDTAGFRUITS', 'IDTAGCOMMENT', 'IDTAGIMPORTANCES', 'IDTAGCATEGORIES', 'IDTAGSIZES', 'IDTAGANIMALS']
+>>> voc['IDTAGSIZES'].preferred_label
+'Size'
+>>> [v.preferred_label for v in set(voc['size'].value_aliases.values())]
+['S', 'M', 'L', 'XL', 'XS']
+>>> voc['size']['s'].aliases
+['S', 'small']
+>>> voc['size']['Small'].identifier
+'IDVALSIZES2'
+{% endcodeblock %}
+
+h2. Translating between vocabulary identifiers and labels
+
+Client software might need to present properties to the user in a human-readable form or take input from the user without requiring them to remember identifiers. For these cases, there're a couple of conversion methods that take a dictionary as input like this:
+
+{% codeblock as python %}
+>>> voc.convert_to_labels({'IDTAGIMPORTANCES': 'IDVALIMPORTANCES1'})
+{'Importance': 'Critical'}
+>>> voc.convert_to_identifiers({'creature': 'elephant'})
+{'IDTAGANIMALS': 'IDVALANIMALS3'}
+{% endcodeblock %}
\ No newline at end of file

commit dd012fa790bc506895dc8e47496c3e8a537d1400
Author: Lucas Di Pentima <lucas.dipentima at curii.com>
Date:   Wed Mar 2 15:22:28 2022 -0300

    18574: Fixes bug for keys without values.
    
    It turns out that:
    
    {}.get('something', {}) != {'something':None}.get('something', {})
    
    ...and when there's no values member on any given vocabulary key, the
    controller fill it with null, so we have to handle the explicit case
    of having {value: None} on the exported vocabulary.
    
    Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas.dipentima at curii.com>

diff --git a/sdk/python/arvados/vocabulary.py b/sdk/python/arvados/vocabulary.py
index ae03ef42d..89698e20a 100644
--- a/sdk/python/arvados/vocabulary.py
+++ b/sdk/python/arvados/vocabulary.py
@@ -20,11 +20,11 @@ class Vocabulary(object):
         self.strict_keys = voc_definition.get('strict_tags', False)
         self.key_aliases = {}
 
-        for key_id, val in voc_definition.get('tags', {}).items():
+        for key_id, val in (voc_definition.get('tags') or {}).items():
             strict = val.get('strict', False)
             key_labels = [l['label'] for l in val.get('labels', [])]
             values = {}
-            for v_id, v_val in val.get('values', {}).items():
+            for v_id, v_val in (val.get('values') or {}).items():
                 labels = [l['label'] for l in v_val.get('labels', [])]
                 values[v_id] = VocabularyValue(v_id, labels)
             vk = VocabularyKey(key_id, key_labels, values, strict)
diff --git a/sdk/python/tests/test_vocabulary.py b/sdk/python/tests/test_vocabulary.py
index 56647e824..cce2ec623 100644
--- a/sdk/python/tests/test_vocabulary.py
+++ b/sdk/python/tests/test_vocabulary.py
@@ -65,6 +65,7 @@ class VocabularyTest(unittest.TestCase):
                     {'label': 'Comment'},
                     {'label': 'Notes'},
                 ],
+                'values': None,
             },
         },
     }

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list