[Python-modules-commits] [python-cachetools] 01/05: Import python-cachetools_1.1.6.orig.tar.gz

Christian Kastner ckk at moszumanska.debian.org
Tue Apr 19 20:07:04 UTC 2016


This is an automated email from the git hooks/post-receive script.

ckk pushed a commit to branch master
in repository python-cachetools.

commit db3722226fb8afcb18781cdf6809be19ac4b5b6b
Author: Christian Kastner <ckk at kvr.at>
Date:   Fri Apr 15 10:39:07 2016 +0200

    Import python-cachetools_1.1.6.orig.tar.gz
---
 .gitignore             |  42 ++-----
 .travis.yml            |  12 +-
 CHANGES.rst            |  17 +++
 MANIFEST.in            |   4 +
 README.rst             |   2 +-
 cachetools/__init__.py |   2 +-
 cachetools/abc.py      |  48 ++++++++
 cachetools/cache.py    |  36 ++----
 cachetools/lfu.py      |  12 +-
 cachetools/lru.py      |  98 ++++-------------
 cachetools/rr.py       |  15 +--
 cachetools/ttl.py      | 292 +++++++++++++++++++++----------------------------
 docs/conf.py           | 257 +++----------------------------------------
 docs/index.rst         |   4 +-
 setup.cfg              |  10 +-
 setup.py               |  25 +++--
 tests/__init__.py      |  12 ++
 tests/test_ttl.py      |  31 ++++--
 tox.ini                |  32 ++++++
 19 files changed, 356 insertions(+), 595 deletions(-)

diff --git a/.gitignore b/.gitignore
index ded6067..1a39b30 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,36 +1,10 @@
-*.py[cod]
-
-# C extensions
-*.so
-
-# Packages
-*.egg
 *.egg-info
-dist
-build
-eggs
-parts
-bin
-var
-sdist
-develop-eggs
-.installed.cfg
-lib
-lib64
-__pycache__
-
-# Installer logs
-pip-log.txt
-
-# Unit test / coverage reports
+*.pyc
+*.swp
+.cache/
 .coverage
-.tox
-nosetests.xml
-
-# Translations
-*.mo
-
-# Mr Developer
-.mr.developer.cfg
-.project
-.pydevproject
+.tox/
+MANIFEST
+build/
+dist/
+docs/_build/
diff --git a/.travis.yml b/.travis.yml
index ed67c83..ac1856c 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,15 +1,19 @@
 sudo: false
+
 language: python
+
 python:
 - 2.7
 - 3.2
 - 3.3
 - 3.4
-- 3.5-dev
+- 3.5
+
 install:
-- pip install . "coverage<4" coveralls flake8 flake8-import-order nose
+- pip install "coverage<4" coveralls tox "virtualenv<14.0.0"
+
 script:
-- flake8
-- nosetests
+- tox -e check-manifest,flake8,py
+
 after_success:
 - coveralls
diff --git a/CHANGES.rst b/CHANGES.rst
index dd8b751..e468c31 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -1,3 +1,20 @@
+v1.1.6 (2016-04-01)
+-------------------
+
+- Reimplement ``LRUCache`` and ``TTLCache`` using
+  ``collections.OrderedDict``.  Note that this will break pickle
+  compatibility with previous versions.
+
+- Fix ``TTLCache`` not calling ``__missing__()`` of derived classes.
+
+- Handle ``ValueError`` in ``Cache.__missing__()`` for consistency
+  with caching decorators.
+
+- Improve how ``TTLCache`` handles expired items.
+
+- Use ``Counter.most_common()`` for ``LFUCache.popitem()``.
+
+
 v1.1.5 (2015-10-25)
 -------------------
 
diff --git a/MANIFEST.in b/MANIFEST.in
index 8b3684f..de1c916 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -2,5 +2,9 @@ include CHANGES.rst
 include LICENSE
 include MANIFEST.in
 include README.rst
+include tox.ini
+
+recursive-include docs *
+prune docs/_build
 
 recursive-include tests *.py
diff --git a/README.rst b/README.rst
index 227e8a3..a5e62af 100644
--- a/README.rst
+++ b/README.rst
@@ -72,7 +72,7 @@ Project Resources
 License
 ------------------------------------------------------------------------
 
-Copyright (c) 2014, 2015 Thomas Kemmer.
+Copyright (c) 2014-2016 Thomas Kemmer.
 
 Licensed under the `MIT License`_.
 
diff --git a/cachetools/__init__.py b/cachetools/__init__.py
index 66d5735..0630970 100644
--- a/cachetools/__init__.py
+++ b/cachetools/__init__.py
@@ -18,7 +18,7 @@ __all__ = (
     'lfu_cache', 'lru_cache', 'rr_cache', 'ttl_cache',
 )
 
-__version__ = '1.1.5'
+__version__ = '1.1.6'
 
 _default = []  # evaluates to False
 
diff --git a/cachetools/abc.py b/cachetools/abc.py
new file mode 100644
index 0000000..41ad736
--- /dev/null
+++ b/cachetools/abc.py
@@ -0,0 +1,48 @@
+from __future__ import absolute_import
+
+import collections
+
+from abc import abstractmethod
+
+
+class DefaultMapping(collections.MutableMapping):
+
+    __slots__ = ()
+
+    @abstractmethod
+    def __contains__(self, key):  # pragma: nocover
+        return False
+
+    @abstractmethod
+    def __getitem__(self, key):  # pragma: nocover
+        if hasattr(self.__class__, '__missing__'):
+            return self.__class__.__missing__(self, key)
+        else:
+            raise KeyError(key)
+
+    def get(self, key, default=None):
+        if key in self:
+            return self[key]
+        else:
+            return default
+
+    __marker = object()
+
+    def pop(self, key, default=__marker):
+        if key in self:
+            value = self[key]
+            del self[key]
+        elif default is self.__marker:
+            raise KeyError(key)
+        else:
+            value = default
+        return value
+
+    def setdefault(self, key, default=None):
+        if key in self:
+            value = self[key]
+        else:
+            self[key] = value = default
+        return value
+
+DefaultMapping.register(dict)
diff --git a/cachetools/cache.py b/cachetools/cache.py
index fbebbbe..409a6b4 100644
--- a/cachetools/cache.py
+++ b/cachetools/cache.py
@@ -1,4 +1,4 @@
-import collections
+from .abc import DefaultMapping
 
 
 class _DefaultSize(object):
@@ -12,7 +12,7 @@ class _DefaultSize(object):
         return 1
 
 
-class Cache(collections.MutableMapping):
+class Cache(DefaultMapping):
     """Mutable mapping to serve as a simple cache or cache base class."""
 
     __size = _DefaultSize()
@@ -30,7 +30,7 @@ class Cache(collections.MutableMapping):
     def __repr__(self):
         return '%s(%r, maxsize=%d, currsize=%d)' % (
             self.__class__.__name__,
-            list(self.items()),
+            list(self.__data.items()),
             self.__maxsize,
             self.__currsize,
         )
@@ -67,7 +67,10 @@ class Cache(collections.MutableMapping):
 
     def __missing__(self, key):
         value = self.__missing(key)
-        self.__setitem__(key, value)
+        try:
+            self.__setitem__(key, value)
+        except ValueError:
+            pass  # value too large
         return value
 
     def __iter__(self):
@@ -97,28 +100,3 @@ class Cache(collections.MutableMapping):
     def getsizeof(self, value):
         """Return the size of a cache element's value."""
         return self.__getsizeof(value)
-
-    # collections.MutableMapping mixin methods do not handle __missing__
-
-    def get(self, key, default=None):
-        if key in self:
-            return self[key]
-        else:
-            return default
-
-    __marker = object()
-
-    def pop(self, key, default=__marker):
-        if key in self:
-            value = self[key]
-            del self[key]
-            return value
-        elif default is self.__marker:
-            raise KeyError(key)
-        else:
-            return default
-
-    def setdefault(self, key, default=None):
-        if key not in self:
-            self[key] = default
-        return self[key]
diff --git a/cachetools/lfu.py b/cachetools/lfu.py
index d163cba..160f537 100644
--- a/cachetools/lfu.py
+++ b/cachetools/lfu.py
@@ -1,5 +1,4 @@
 import collections
-import operator
 
 from .cache import Cache
 
@@ -13,12 +12,12 @@ class LFUCache(Cache):
 
     def __getitem__(self, key, cache_getitem=Cache.__getitem__):
         value = cache_getitem(self, key)
-        self.__counter[key] += 1
+        self.__counter[key] -= 1
         return value
 
     def __setitem__(self, key, value, cache_setitem=Cache.__setitem__):
         cache_setitem(self, key, value)
-        self.__counter[key] += 1
+        self.__counter[key] -= 1
 
     def __delitem__(self, key, cache_delitem=Cache.__delitem__):
         cache_delitem(self, key)
@@ -27,7 +26,8 @@ class LFUCache(Cache):
     def popitem(self):
         """Remove and return the `(key, value)` pair least frequently used."""
         try:
-            key = min(self.__counter.items(), key=operator.itemgetter(1))[0]
+            (key, _), = self.__counter.most_common(1)
         except ValueError:
-            raise KeyError('cache is empty')
-        return key, self.pop(key)
+            raise KeyError('%s is empty' % self.__class__.__name__)
+        else:
+            return (key, self.pop(key))
diff --git a/cachetools/lru.py b/cachetools/lru.py
index f18f0b2..525abd8 100644
--- a/cachetools/lru.py
+++ b/cachetools/lru.py
@@ -1,29 +1,6 @@
-from .cache import Cache
-
-
-class _Link(object):
-
-    __slots__ = 'key', 'prev', 'next'
-
-    def __getstate__(self):
-        if hasattr(self, 'key'):
-            return (self.key,)
-        else:
-            return None
-
-    def __setstate__(self, state):
-        self.key, = state
-
-    def insert(self, next):
-        self.next = next
-        self.prev = prev = next.prev
-        prev.next = next.prev = self
+import collections
 
-    def unlink(self):
-        next = self.next
-        prev = self.prev
-        prev.next = next
-        next.prev = prev
+from .cache import Cache
 
 
 class LRUCache(Cache):
@@ -31,66 +8,39 @@ class LRUCache(Cache):
 
     def __init__(self, maxsize, missing=None, getsizeof=None):
         Cache.__init__(self, maxsize, missing, getsizeof)
-        self.__root = root = _Link()
-        root.prev = root.next = root
-        self.__links = {}
-
-    def __repr__(self, cache_getitem=Cache.__getitem__):
-        # prevent item reordering
-        return '%s(%r, maxsize=%d, currsize=%d)' % (
-            self.__class__.__name__,
-            [(key, cache_getitem(self, key)) for key in self],
-            self.maxsize,
-            self.currsize,
-        )
+        self.__order = collections.OrderedDict()
 
     def __getitem__(self, key, cache_getitem=Cache.__getitem__):
         value = cache_getitem(self, key)
-        link = self.__links[key]
-        link.unlink()
-        link.insert(self.__root)
+        self.__update(key)
         return value
 
     def __setitem__(self, key, value, cache_setitem=Cache.__setitem__):
         cache_setitem(self, key, value)
-        try:
-            link = self.__links[key]
-        except KeyError:
-            link = self.__links[key] = _Link()
-        else:
-            link.unlink()
-        link.key = key
-        link.insert(self.__root)
+        self.__update(key)
 
     def __delitem__(self, key, cache_delitem=Cache.__delitem__):
         cache_delitem(self, key)
-        links = self.__links
-        links[key].unlink()
-        del links[key]
-
-    def __getstate__(self):
-        state = self.__dict__.copy()
-        root = self.__root
-        links = state['__links'] = [root]
-        link = root.next
-        while link is not root:
-            links.append(link)
-            link = link.next
-        return state
-
-    def __setstate__(self, state):
-        links = state.pop('__links')
-        count = len(links)
-        for index, link in enumerate(links):
-            link.prev = links[index - 1]
-            link.next = links[(index + 1) % count]
-        self.__dict__.update(state)
+        del self.__order[key]
 
     def popitem(self):
         """Remove and return the `(key, value)` pair least recently used."""
-        root = self.__root
-        link = root.next
-        if link is root:
+        try:
+            key = next(iter(self.__order))
+        except StopIteration:
             raise KeyError('%s is empty' % self.__class__.__name__)
-        key = link.key
-        return (key, self.pop(key))
+        else:
+            return (key, self.pop(key))
+
+    if hasattr(collections.OrderedDict, 'move_to_end'):
+        def __update(self, key):
+            try:
+                self.__order.move_to_end(key)
+            except KeyError:
+                self.__order[key] = None
+    else:
+        def __update(self, key):
+            try:
+                self.__order[key] = self.__order.pop(key)
+            except KeyError:
+                self.__order[key] = None
diff --git a/cachetools/rr.py b/cachetools/rr.py
index 143223b..c82919e 100644
--- a/cachetools/rr.py
+++ b/cachetools/rr.py
@@ -11,15 +11,16 @@ class RRCache(Cache):
         Cache.__init__(self, maxsize, missing, getsizeof)
         self.__choice = choice
 
+    @property
+    def choice(self):
+        """The `choice` function used by the cache."""
+        return self.__choice
+
     def popitem(self):
         """Remove and return a random `(key, value)` pair."""
         try:
             key = self.__choice(list(self))
         except IndexError:
-            raise KeyError('cache is empty')
-        return (key, self.pop(key))
-
-    @property
-    def choice(self):
-        """The `choice` function used by the cache."""
-        return self.__choice
+            raise KeyError('%s is empty' % self.__class__.__name__)
+        else:
+            return (key, self.pop(key))
diff --git a/cachetools/ttl.py b/cachetools/ttl.py
index 57c8f9c..04e9d85 100644
--- a/cachetools/ttl.py
+++ b/cachetools/ttl.py
@@ -1,4 +1,4 @@
-import functools
+import collections
 import time
 
 from .cache import Cache
@@ -6,82 +6,51 @@ from .cache import Cache
 
 class _Link(object):
 
-    __slots__ = (
-        'key', 'expire', 'size',
-        'ttl_prev', 'ttl_next',
-        'lru_prev', 'lru_next'
-    )
+    __slots__ = ('key', 'expire', 'next', 'prev')
 
-    def __getstate__(self):
-        if hasattr(self, 'key'):
-            return (self.key, self.expire, self.size)
-        else:
-            return None
+    def __init__(self, key=None, expire=None):
+        self.key = key
+        self.expire = expire
 
-    def __setstate__(self, state):
-        self.key, self.expire, self.size = state
-
-    def insert_lru(self, next):
-        self.lru_next = next
-        self.lru_prev = prev = next.lru_prev
-        prev.lru_next = next.lru_prev = self
-
-    def insert_ttl(self, next):
-        self.ttl_next = next
-        self.ttl_prev = prev = next.ttl_prev
-        prev.ttl_next = next.ttl_prev = self
-
-    def insert(self, next):
-        self.insert_lru(next)
-        self.insert_ttl(next)
-
-    def unlink_lru(self):
-        lru_next = self.lru_next
-        lru_prev = self.lru_prev
-        lru_prev.lru_next = lru_next
-        lru_next.lru_prev = lru_prev
-
-    def unlink_ttl(self):
-        ttl_next = self.ttl_next
-        ttl_prev = self.ttl_prev
-        ttl_prev.ttl_next = ttl_next
-        ttl_next.ttl_prev = ttl_prev
+    def __reduce__(self):
+        return _Link, (self.key, self.expire)
 
     def unlink(self):
-        self.unlink_lru()
-        self.unlink_ttl()
+        next = self.next
+        prev = self.prev
+        prev.next = next
+        next.prev = prev
 
 
-class _NestedTimer(object):
+class _Timer(object):
 
     def __init__(self, timer):
         self.__timer = timer
         self.__nesting = 0
 
+    def __call__(self):
+        if self.__nesting == 0:
+            return self.__timer()
+        else:
+            return self.__time
+
     def __enter__(self):
         if self.__nesting == 0:
-            self.__time = self.__timer()
+            self.__time = time = self.__timer()
+        else:
+            time = self.__time
         self.__nesting += 1
-        return self.__time
+        return time
 
     def __exit__(self, *exc):
         self.__nesting -= 1
 
-    def __call__(self):
-        if self.__nesting == 0:
-            return self.__timer()
-        else:
-            return self.__time
+    def __reduce__(self):
+        return _Timer, (self.__timer,)
 
     def __getattr__(self, name):
         return getattr(self.__timer, name)
 
-    def __getstate__(self):
-        return (self.__timer, self.__nesting)
-
-    def __setstate__(self, state):
-        self.__timer, self.__nesting = state
-
 
 class TTLCache(Cache):
     """LRU Cache implementation with per-item time-to-live (TTL) value."""
@@ -90,116 +59,93 @@ class TTLCache(Cache):
                  getsizeof=None):
         Cache.__init__(self, maxsize, missing, getsizeof)
         self.__root = root = _Link()
-        root.ttl_prev = root.ttl_next = root
-        root.lru_prev = root.lru_next = root
-        self.__links = {}
-        self.__timer = _NestedTimer(timer)
+        root.prev = root.next = root
+        self.__links = collections.OrderedDict()
+        self.__timer = _Timer(timer)
         self.__ttl = ttl
 
-    def __repr__(self, cache_getitem=Cache.__getitem__):
-        # prevent item reordering/expiration
-        return '%s(%r, maxsize=%d, currsize=%d)' % (
-            self.__class__.__name__,
-            [(key, cache_getitem(self, key)) for key in self],
-            self.maxsize,
-            self.currsize,
-        )
-
-    def __getitem__(self, key,
-                    cache_getitem=Cache.__getitem__,
-                    cache_missing=Cache.__missing__):
-        with self.__timer as time:
-            value = cache_getitem(self, key)
-            link = self.__links[key]
-            if link.expire < time:
-                return cache_missing(self, key)
-            link.unlink_lru()
-            link.insert_lru(self.__root)
-            return value
+    def __contains__(self, key):
+        try:
+            link = self.__links[key]  # no reordering
+        except KeyError:
+            return False
+        else:
+            return not (link.expire < self.__timer())
+
+    def __getitem__(self, key, cache_getitem=Cache.__getitem__):
+        try:
+            link = self.__getlink(key)
+        except KeyError:
+            expired = False
+        else:
+            expired = link.expire < self.__timer()
+        if expired:
+            return self.__missing__(key)
+        else:
+            return cache_getitem(self, key)
 
-    def __setitem__(self, key, value,
-                    cache_setitem=Cache.__setitem__,
-                    cache_getsizeof=Cache.getsizeof):
+    def __setitem__(self, key, value, cache_setitem=Cache.__setitem__):
         with self.__timer as time:
             self.expire(time)
             cache_setitem(self, key, value)
-            try:
-                link = self.__links[key]
-            except KeyError:
-                link = self.__links[key] = _Link()
-            else:
-                link.unlink()
-            link.key = key
-            link.expire = time + self.__ttl
-            link.size = cache_getsizeof(self, value)
-            link.insert(self.__root)
+        try:
+            link = self.__getlink(key)
+        except KeyError:
+            self.__links[key] = link = _Link(key)
+        else:
+            link.unlink()
+        link.expire = time + self.__ttl
+        link.next = root = self.__root
+        link.prev = prev = root.prev
+        prev.next = root.prev = link
 
     def __delitem__(self, key, cache_delitem=Cache.__delitem__):
-        with self.__timer as time:
-            self.expire(time)
-            cache_delitem(self, key)
-            links = self.__links
-            links[key].unlink()
-            del links[key]
-
-    def __contains__(self, key):
-        with self.__timer as time:
-            if key not in self.__links:
-                return False
-            elif self.__links[key].expire < time:
-                return False
-            else:
-                return True
+        cache_delitem(self, key)
+        link = self.__links.pop(key)
+        link.unlink()
+        if link.expire < self.__timer():
+            raise KeyError(key)
 
     def __iter__(self):
-        timer = self.__timer
         root = self.__root
-        curr = root.ttl_next
+        curr = root.next
         while curr is not root:
-            with timer as time:
+            # "freeze" time for iterator access
+            with self.__timer as time:
                 if not (curr.expire < time):
                     yield curr.key
-            curr = curr.ttl_next
+            curr = curr.next
 
-    def __len__(self, cache_len=Cache.__len__):
+    def __len__(self):
         root = self.__root
-        head = root.ttl_next
-        expired = 0
-        with self.__timer as time:
-            while head is not root and head.expire < time:
-                expired += 1
-                head = head.ttl_next
-        return cache_len(self) - expired
-
-    def __getstate__(self):
-        state = self.__dict__.copy()
-        root = self.__root
-        links = state['__links'] = [(root, root)]
-        lru, ttl = root.lru_next, root.ttl_next
-        while lru is not root:
-            links.append((lru, ttl))
-            lru = lru.lru_next
-            ttl = ttl.ttl_next
-        return state
+        curr = root.next
+        time = self.__timer()
+        count = len(self.__links)
+        while curr is not root and curr.expire < time:
+            count -= 1
+            curr = curr.next
+        return count
 
     def __setstate__(self, state):
-        links = state.pop('__links')
-        count = len(links)
-        for index, (lru, ttl) in enumerate(links):
-            lru.lru_prev, ttl.ttl_prev = links[index - 1]
-            lru.lru_next, ttl.ttl_next = links[(index + 1) % count]
         self.__dict__.update(state)
+        root = self.__root
+        root.prev = root.next = root
+        for link in sorted(self.__links.values(), key=lambda obj: obj.expire):
+            link.next = root
+            link.prev = prev = root.prev
+            prev.next = root.prev = link
+        self.expire(self.__timer())
+
+    def __repr__(self, cache_repr=Cache.__repr__):
+        with self.__timer as time:
+            self.expire(time)
+            return cache_repr(self)
 
     @property
     def currsize(self):
-        root = self.__root
-        head = root.ttl_next
-        expired = 0
         with self.__timer as time:
-            while head is not root and head.expire < time:
-                expired += head.size
-                head = head.ttl_next
-        return super(TTLCache, self).currsize - expired
+            self.expire(time)
+            return super(TTLCache, self).currsize
 
     @property
     def timer(self):
@@ -216,15 +162,32 @@ class TTLCache(Cache):
         if time is None:
             time = self.__timer()
         root = self.__root
-        head = root.ttl_next
+        curr = root.next
         links = self.__links
         cache_delitem = Cache.__delitem__
-        while head is not root and head.expire < time:
-            cache_delitem(self, head.key)
-            del links[head.key]
-            next = head.ttl_next
-            head.unlink()
-            head = next
+        while curr is not root and curr.expire < time:
+            cache_delitem(self, curr.key)
+            del links[curr.key]
+            next = curr.next
+            curr.unlink()
+            curr = next
+
+    def clear(self):
+        with self.__timer as time:
+            self.expire(time)
+            Cache.clear(self)
+
+    def get(self, *args, **kwargs):
+        with self.__timer:
+            return Cache.get(self, *args, **kwargs)
+
+    def pop(self, *args, **kwargs):
+        with self.__timer:
+            return Cache.pop(self, *args, **kwargs)
+
+    def setdefault(self, *args, **kwargs):
+        with self.__timer:
+            return Cache.setdefault(self, *args, **kwargs)
 
     def popitem(self):
         """Remove and return the `(key, value)` pair least recently used that
@@ -233,21 +196,20 @@ class TTLCache(Cache):
         """
         with self.__timer as time:
             self.expire(time)
-            root = self.__root
-            link = root.lru_next
-            if link is root:
+            try:
+                key = next(iter(self.__links))
+            except StopIteration:
                 raise KeyError('%s is empty' % self.__class__.__name__)
-            key = link.key
-            return (key, self.pop(key))
-
-    # mixin methods
-
-    def __nested(method):
-        def wrapper(self, *args, **kwargs):
-            with self.__timer:
-                return method(self, *args, **kwargs)
-        return functools.update_wrapper(wrapper, method)
+            else:
+                return (key, self.pop(key))
 
-    get = __nested(Cache.get)
-    pop = __nested(Cache.pop)
-    setdefault = __nested(Cache.setdefault)
+    if hasattr(collections.OrderedDict, 'move_to_end'):
+        def __getlink(self, key):
+            value = self.__links[key]
+            self.__links.move_to_end(key)
+            return value
+    else:
+        def __getlink(self, key):
+            value = self.__links.pop(key)
+            self.__links[key] = value
+            return value
diff --git a/docs/conf.py b/docs/conf.py
index d675a0f..d51f10b 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -1,245 +1,20 @@
-# -*- coding: utf-8 -*-
-#
-# cachetools documentation build configuration file, created by
-# sphinx-quickstart on Mon Feb 10 09:15:34 2014.
-#
-# This file is execfile()d with the current directory set to its containing dir.
-#
-# Note that not all possible configuration values are present in this
-# autogenerated file.
-#
-# All configuration values have a default; values that are commented out
-# serve to show the default.
-
-import sys
-import os
-
-# If extensions (or modules to document with autodoc) are in another directory,
-# add these directories to sys.path here. If the directory is relative to the
-# documentation root, use os.path.abspath to make it absolute, like shown here.
-#sys.path.insert(0, os.path.abspath('.'))
-sys.path.insert(0, os.path.abspath('..'))
-from cachetools import __version__
-
-# -- General configuration -----------------------------------------------------
-
-# If your documentation needs a minimal Sphinx version, state it here.
-#needs_sphinx = '1.0'
-
-# Add any Sphinx extension module names here, as strings. They can be extensions
-# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
-extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.todo', 'sphinx.ext.coverage']
-
-# Add any paths that contain templates here, relative to this directory.
-templates_path = ['_templates']
-
-# The suffix of source filenames.
-source_suffix = '.rst'
-
-# The encoding of source files.
-#source_encoding = 'utf-8-sig'
-
-# The master toctree document.
-master_doc = 'index'
-
-# General information about the project.
-project = u'cachetools'
-copyright = u'2014, 2015 Thomas Kemmer'
-
-# The version info for the project you're documenting, acts as replacement for
-# |version| and |release|, also used in various other places throughout the
-# built documents.
-#
-# The short X.Y version.
-version = __version__
-# The full version, including alpha/beta/rc tags.
+def get_version(filename):
+    from re import findall
+    with open(filename) as f:
+        metadata = dict(findall(r"__([a-z]+)__ = '([^']+)'", f.read()))
+    return metadata['version']
+
+project = 'cachetools'
+copyright = '2014-2016 Thomas Kemmer'
+version = get_version(b'../cachetools/__init__.py')
 release = version
 
-# The language for content autogenerated by Sphinx. Refer to documentation
-# for a list of supported languages.
-#language = None
-
-# There are two options for replacing |today|: either, you set today to some
-# non-false value, then it is used:
-#today = ''
-# Else, today_fmt is used as the format for a strftime call.
-#today_fmt = '%B %d, %Y'
-
-# List of patterns, relative to source directory, that match files and
-# directories to ignore when looking for source files.
+extensions = [
+    'sphinx.ext.autodoc',
+    'sphinx.ext.coverage',
+    'sphinx.ext.doctest',
+    'sphinx.ext.todo'
+]
 exclude_patterns = ['_build']
-
-# The reST default role (used for this markup: `text`) to use for all documents.
-#default_role = None
-
-# If true, '()' will be appended to :func: etc. cross-reference text.
-#add_function_parentheses = True
-
-# If true, the current module name will be prepended to all description
-# unit titles (such as .. function::).
-#add_module_names = True
-
-# If true, sectionauthor and moduleauthor directives will be shown in the
-# output. They are ignored by default.
-#show_authors = False
-
-# The name of the Pygments (syntax highlighting) style to use.
-pygments_style = 'sphinx'
-
-# A list of ignored prefixes for module index sorting.
-#modindex_common_prefix = []
-
-
-# -- Options for HTML output ---------------------------------------------------
-
-# The theme to use for HTML and HTML Help pages.  See the documentation for
-# a list of builtin themes.
+master_doc = 'index'
 html_theme = 'default'
-
-# Theme options are theme-specific and customize the look and feel of a theme
-# further.  For a list of options available for each theme, see the
-# documentation.
-#html_theme_options = {}
-
-# Add any paths that contain custom themes here, relative to this directory.
-#html_theme_path = []
-
-# The name for this set of Sphinx documents.  If None, it defaults to
-# "<project> v<release> documentation".
-#html_title = None
-
-# A shorter title for the navigation bar.  Default is the same as html_title.
-#html_short_title = None
-
-# The name of an image file (relative to this directory) to place at the top
-# of the sidebar.
-#html_logo = None
-
-# The name of an image file (within the static path) to use as favicon of the
-# docs.  This file should be a Windows icon file (.ico) being 16x16 or 32x32
-# pixels large.
-#html_favicon = None
-
-# Add any paths that contain custom static files (such as style sheets) here,
... 402 lines suppressed ...

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-cachetools.git



More information about the Python-modules-commits mailing list