From dbe768a7877fe65739b3a412f7ee9db1617919ce Mon Sep 17 00:00:00 2001 From: Uche Ogbuji Date: Wed, 13 Nov 2019 08:40:02 -0700 Subject: [PATCH] Fix bug importing librarylink.site --- pylib/site.py | 13 ++++++------- pylib/util.py | 2 -- pylib/version.py | 2 +- setup.py | 2 +- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/pylib/site.py b/pylib/site.py index af39c05..1ef9132 100644 --- a/pylib/site.py +++ b/pylib/site.py @@ -140,13 +140,13 @@ def all_sites(sitemap_url='http://library.link/harvest/sitemap.xml', plus_list=N >>> denversite.host 'link.denverlibrary.org' ''' - global CACHEDIR import requests try: from cachecontrol import CacheControl from cachecontrol.caches.file_cache import FileCache - CACHEDIR = '.web_cache' + cachedir = getattr(all_sites, 'cachedir', '@UNKNOWN') except ImportError: + cachedir = None pass #FIXME: Avoid accumulating all the nodes, which will require improvements to xml.treesequence @@ -168,8 +168,10 @@ def sink(accumulator): nodes = [] ts = xmliter.sender(('sitemapindex', 'sitemap'), sink(nodes)) - if hasattr (all_sites, 'cachedir'): - sess = CacheControl(requests.Session(), cache=FileCache(all_sites.cachedir)) + if cachedir == '@UNKNOWN': + sess = CacheControl(requests.Session(), cache=FileCache('.web_cache')) + elif cachedir: + sess = CacheControl(requests.Session(), cache=FileCache(cachedir)) else: sess = CacheControl(requests.Session()) result = sess.get(sitemap_url) @@ -183,6 +185,3 @@ def sink(accumulator): nodes.append(s) yield from nodes - -if CACHEDIR: all_sites.cachedir = '.web_cache' - diff --git a/pylib/util.py b/pylib/util.py index fd87959..2439834 100644 --- a/pylib/util.py +++ b/pylib/util.py @@ -9,8 +9,6 @@ from itertools import * import collections.abc -CACHEDIR = None - from versa.driver import memory from versa import I, VERSA_BASEIRI, ORIGIN, RELATIONSHIP, TARGET, ATTRIBUTES from versa.reader import rdfalite diff --git a/pylib/version.py b/pylib/version.py index c6cd192..954e327 100644 --- a/pylib/version.py +++ b/pylib/version.py @@ -1,2 +1,2 @@ #http://legacy.python.org/dev/peps/pep-0440/ -version_info = ('0', '5', '0') +version_info = ('0', '5', '1') diff --git a/setup.py b/setup.py index 78e6ee7..108b163 100755 --- a/setup.py +++ b/setup.py @@ -82,7 +82,7 @@ liblink_resource_summary "http://link.houstonlibrary.org/portal/Half-of-a-yellow-sun-Chimamanda-Ngozi/n7KqqbZFJuM/" ''' -LONGDESC_CTYPE = 'text/markdown', +LONGDESC_CTYPE = 'text/markdown' setup( name=PROJECT_NAME,