From 749955462d0a2922634bb3aa3c029b4ffb8b2135 Mon Sep 17 00:00:00 2001 From: Koen Van Daele Date: Sun, 16 Feb 2020 23:38:10 +0100 Subject: [PATCH 1/4] Fix dict_to_thing (#81) Fixed an error in dict_to_thing that caused this provider not to follow the skosprovider interface. Refs #80 --- CHANGES.rst | 6 ++++++ setup.py | 2 +- skosprovider_atramhasis/utils.py | 22 ++++++++++------------ tests/test_providers.py | 3 +++ 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index ac127ef..87c5d23 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,9 @@ +0.3.1 (2020-02-??) +------------------ + +- Fix a bug in `dict_to_thing` that resulted in the provider exposing objects + in stead of id's in relations. (#80) + 0.3.0 (2020-01-24) ------------------ diff --git a/setup.py b/setup.py index 1f0b7ed..6723b15 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ ] setup( name='skosprovider_atramhasis', - version='0.3.0', + version='0.3.1', description='Skosprovider implementation of Atramhasis Vocabularies', long_description=README, long_description_content_type='text/x-rst', diff --git a/skosprovider_atramhasis/utils.py b/skosprovider_atramhasis/utils.py index afa9ed3..8fff603 100644 --- a/skosprovider_atramhasis/utils.py +++ b/skosprovider_atramhasis/utils.py @@ -32,10 +32,10 @@ def text_(s, encoding='latin-1', errors='strict'): def dict_to_thing(dict): ''' Transform a dict into a - :class:`Concept` or :class:`Collection` . + :class:`skosprovider.skos.Concept` or :class:`skosprovider.skos.Collection` . - If the argument passed is already a :class:`Concept` or :class:`Collection`, this method just - returns the argument. + If the argument passed is already a :class:`skosprovider.skos.Concept` or + :class:`skosprovider.skos.Collection`, this method just returns the argument. ''' if isinstance(dict, Concept) or isinstance(dict, Collection): return dict @@ -53,7 +53,7 @@ def dict_to_thing(dict): if type == 'concept': thing = Concept(id) if 'subordinate_arrays' in dict: - thing.subordinate_arrays = [(dict_to_thing(n)) for n in dict['subordinate_arrays']] + thing.subordinate_arrays = [n['id'] for n in dict['subordinate_arrays']] if 'matches' in dict: matches = dict['matches'] for match_type in thing.matchtypes: @@ -62,9 +62,9 @@ def dict_to_thing(dict): elif type == 'collection': thing = Collection(id) if 'superordinates' in dict: - thing.superordinates = [(dict_to_thing(n)) for n in dict['superordinates']] + thing.superordinates = [n['id'] for n in dict['superordinates']] if 'members' in dict: - thing.members = [(dict_to_thing(n)) for n in dict['members']] + thing.members = [n['id'] for n in dict['members']] else: raise ValueError("type: type is not valid ('concept', 'collection') in dict") thing.type = type @@ -77,13 +77,11 @@ def dict_to_thing(dict): if 'sources' in dict: thing.sources = [(dict_to_source(n)) for n in dict['sources']] if 'narrower' in dict: - thing.narrower = [(dict_to_thing(n)) for n in dict['narrower']] + thing.narrower = [n['id'] for n in dict['narrower']] if 'broader' in dict: - thing.broader = [(dict_to_thing(n)) for n in dict['broader']] + thing.broader = [n['id'] for n in dict['broader']] if 'related' in dict: - thing.related = [(dict_to_thing(n)) for n in dict['related']] + thing.related = [n['id'] for n in dict['related']] if 'member_of' in dict: - thing.member_of = [(dict_to_thing(n)) for n in dict['member_of']] + thing.member_of = [n['id'] for n in dict['member_of']] return thing - - diff --git a/tests/test_providers.py b/tests/test_providers.py index fbd70e1..3a986b5 100644 --- a/tests/test_providers.py +++ b/tests/test_providers.py @@ -221,6 +221,8 @@ def test_get_by_id_concept(self): assert concept.type == 'concept' assert len(concept.labels) > 0 assert 'traditioneel' in [l.label for l in concept.labels if l.type == 'prefLabel'] + assert 2 in concept.narrower + assert 60 in concept.member_of @responses.activate def test_get_by_id_concept_matches(self): @@ -234,6 +236,7 @@ def test_get_by_id_concept_matches(self): assert concept.type == 'concept' assert len(concept.labels) > 0 assert 'The Chestnut' in [l.label for l in concept.labels if l.type == 'prefLabel'] + assert 3 in concept.member_of @responses.activate def test_get_by_id_nonexistant_id(self): From 75763e27e2b245c504c1758916a9cd4f2081edef Mon Sep 17 00:00:00 2001 From: Koen Van Daele Date: Wed, 19 Feb 2020 21:57:15 +0100 Subject: [PATCH 2/4] Update docs to version 0.3.1 --- docs/source/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index bc5e4d9..9685754 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -59,7 +59,7 @@ # The short X.Y version. version = '0.3' # The full version, including alpha/beta/rc tags. -release = '0.3.0' +release = '0.3.1' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. From 5f0ea3dcc21d2ffccdf2e1d8bba32a5f5678f9d1 Mon Sep 17 00:00:00 2001 From: Koen Van Daele Date: Wed, 19 Feb 2020 22:07:07 +0100 Subject: [PATCH 3/4] Update requirements. --- CHANGES.rst | 4 ++-- requirements-dev.txt | 12 ++++++------ requirements.txt | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 87c5d23..6312834 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,8 +1,8 @@ -0.3.1 (2020-02-??) +0.3.1 (2020-02-19) ------------------ - Fix a bug in `dict_to_thing` that resulted in the provider exposing objects - in stead of id's in relations. (#80) + instead of id's in relations. (#80) 0.3.0 (2020-01-24) ------------------ diff --git a/requirements-dev.txt b/requirements-dev.txt index bc8e643..eccd0bf 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -3,12 +3,12 @@ # Documentation Sphinx==1.8.5 ; python_version < '3.5' -Sphinx==2.2.0 ; python_version >= '3.5' +Sphinx==2.4.2 ; python_version >= '3.5' # Unit testing -tox==3.14.0 -pytest==4.6.6 ; python_version < '3.0' -pytest==5.2.1 ; python_version >= '3.0' -responses==0.10.6 +tox==3.14.5 +pytest==4.6.9 ; python_version < '3.0' +pytest==5.3.5 ; python_version >= '3.0' +responses==0.10.9 pytest-cov==2.8.1 -coveralls==1.8.2 +coveralls==1.11.1 diff --git a/requirements.txt b/requirements.txt index bc34dd9..5269725 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -requests==2.22.0 +requests==2.23.0 skosprovider==0.7.0 # -e git+https://github.com/koenedaele/skosprovider.git@DEV_0.7.0#egg=skosprovider dogpile.cache==0.9.0 From c168a04f987fd3cfaaabafbf3d1c67bea7c05866 Mon Sep 17 00:00:00 2001 From: Koen Van Daele Date: Wed, 19 Feb 2020 22:22:41 +0100 Subject: [PATCH 4/4] Update docs. --- docs/source/api.rst | 6 ++++++ skosprovider_atramhasis/cache_utils.py | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/docs/source/api.rst b/docs/source/api.rst index e6054af..568f55f 100644 --- a/docs/source/api.rst +++ b/docs/source/api.rst @@ -15,3 +15,9 @@ Utils module .. automodule:: skosprovider_atramhasis.utils :members: + +Cache_utils module +------------------ + +.. automodule:: skosprovider_atramhasis.cache_utils + :members: diff --git a/skosprovider_atramhasis/cache_utils.py b/skosprovider_atramhasis/cache_utils.py index 940bb7f..ea24269 100644 --- a/skosprovider_atramhasis/cache_utils.py +++ b/skosprovider_atramhasis/cache_utils.py @@ -1,3 +1,8 @@ +# -*- coding: utf-8 -*- +''' +Utility functions for chaching in :mod:`skosprovider_atramhasis`. +''' + import functools import json