[Python-modules-commits] [zict] 01/05: New upstream version 0.1.3

Diane Trout diane at moszumanska.debian.org
Fri Oct 13 20:40:08 UTC 2017


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

diane pushed a commit to branch master
in repository zict.

commit 0e6e551c3e5f944c524688b41cc2ff57c031a86e
Author: Diane Trout <diane at ghic.org>
Date:   Fri Oct 13 08:30:00 2017 -0700

    New upstream version 0.1.3
---
 PKG-INFO                | 12 ++++++++----
 README.rst              |  6 +++++-
 setup.py                |  6 +++---
 zict.egg-info/PKG-INFO  | 12 ++++++++----
 zict/__init__.py        |  2 +-
 zict/file.py            | 16 +++++++++++++++-
 zict/lru.py             | 26 +++++++++++++++++++++-----
 zict/tests/test_file.py |  7 +++++++
 zict/tests/test_lru.py  | 16 ++++++++++++++++
 9 files changed, 84 insertions(+), 19 deletions(-)

diff --git a/PKG-INFO b/PKG-INFO
index 0ed01da..c0d18d9 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,8 +1,8 @@
 Metadata-Version: 1.0
 Name: zict
-Version: 0.1.1
+Version: 0.1.3
 Summary: Mutable mapping tools
-Home-page: http://github.com/mrocklin/zict/
+Home-page: http://zict.readthedocs.io/en/latest/
 Author: Matthew Rocklin
 Author-email: mrocklin at gmail.com
 License: BSD
@@ -11,7 +11,11 @@ Description: Zict
         
         |Build Status|
         
-        Mutable Mapping interfaces
+        Mutable Mapping interfaces.  See documentation_.
         
-Keywords: mutable mapping dict
+        .. _documentation: http://zict.readthedocs.io/en/latest/
+        .. |Build Status| image:: https://travis-ci.org/dask/zict.svg?branch=master
+           :target: https://travis-ci.org/dask/zict
+        
+Keywords: mutable mapping,dict,dask
 Platform: UNKNOWN
diff --git a/README.rst b/README.rst
index 0843012..2ed1ac0 100644
--- a/README.rst
+++ b/README.rst
@@ -3,4 +3,8 @@ Zict
 
 |Build Status|
 
-Mutable Mapping interfaces
+Mutable Mapping interfaces.  See documentation_.
+
+.. _documentation: http://zict.readthedocs.io/en/latest/
+.. |Build Status| image:: https://travis-ci.org/dask/zict.svg?branch=master
+   :target: https://travis-ci.org/dask/zict
diff --git a/setup.py b/setup.py
index 7fa2bfa..f5ead0e 100755
--- a/setup.py
+++ b/setup.py
@@ -4,13 +4,13 @@ import os
 from setuptools import setup
 
 setup(name='zict',
-      version='0.1.1',
+      version='0.1.3',
       description='Mutable mapping tools',
-      url='http://github.com/mrocklin/zict/',
+      url='http://zict.readthedocs.io/en/latest/',
       maintainer='Matthew Rocklin',
       maintainer_email='mrocklin at gmail.com',
       license='BSD',
-      keywords='mutable mapping dict',
+      keywords='mutable mapping,dict,dask',
       packages=['zict'],
       install_requires=[open('requirements.txt').read().strip().split('\n')],
       long_description=(open('README.rst').read() if os.path.exists('README.rst')
diff --git a/zict.egg-info/PKG-INFO b/zict.egg-info/PKG-INFO
index 0ed01da..c0d18d9 100644
--- a/zict.egg-info/PKG-INFO
+++ b/zict.egg-info/PKG-INFO
@@ -1,8 +1,8 @@
 Metadata-Version: 1.0
 Name: zict
-Version: 0.1.1
+Version: 0.1.3
 Summary: Mutable mapping tools
-Home-page: http://github.com/mrocklin/zict/
+Home-page: http://zict.readthedocs.io/en/latest/
 Author: Matthew Rocklin
 Author-email: mrocklin at gmail.com
 License: BSD
@@ -11,7 +11,11 @@ Description: Zict
         
         |Build Status|
         
-        Mutable Mapping interfaces
+        Mutable Mapping interfaces.  See documentation_.
         
-Keywords: mutable mapping dict
+        .. _documentation: http://zict.readthedocs.io/en/latest/
+        .. |Build Status| image:: https://travis-ci.org/dask/zict.svg?branch=master
+           :target: https://travis-ci.org/dask/zict
+        
+Keywords: mutable mapping,dict,dask
 Platform: UNKNOWN
diff --git a/zict/__init__.py b/zict/__init__.py
index 8d717a6..e918538 100644
--- a/zict/__init__.py
+++ b/zict/__init__.py
@@ -6,4 +6,4 @@ from .buffer import Buffer
 from .sieve import Sieve
 from .lmdb import LMDB
 
-__version__ = '0.1.1'
+__version__ = '0.1.3'
diff --git a/zict/file.py b/zict/file.py
index 0b45752..aa2ae4e 100644
--- a/zict/file.py
+++ b/zict/file.py
@@ -44,6 +44,16 @@ class File(ZictBase):
     >>> z['x'] = b'123'  # doctest: +SKIP
     >>> z['x']  # doctest: +SKIP
     b'123'
+
+    Also supports writing lists of bytes objects
+
+    >>> z['y'] = [b'123', b'4567']  # doctest: +SKIP
+    >>> z['y']  # doctest: +SKIP
+    b'1234567'
+
+    Or anything that can be used with file.write, like a memoryview
+
+    >>> z['data'] = np.ones(5).data  # doctest: +SKIP
     """
     def __init__(self, directory, mode='a'):
         self.directory = directory
@@ -68,7 +78,11 @@ class File(ZictBase):
 
     def __setitem__(self, key, value):
         with open(os.path.join(self.directory, _safe_key(key)), 'wb') as f:
-            f.write(value)
+            if isinstance(value, (tuple, list)):
+                for v in value:
+                    f.write(v)
+            else:
+                f.write(value)
         self._keys.add(key)
 
     def __contains__(self, key):
diff --git a/zict/lru.py b/zict/lru.py
index 1f63b35..949d313 100644
--- a/zict/lru.py
+++ b/zict/lru.py
@@ -68,11 +68,27 @@ class LRU(ZictBase):
                 cb(key, value)
 
         while self.total_weight > self.n:
-            k, priority = self.heap.popitem()
-            self.total_weight -= self.weights.pop(k)
-            v = self.d.pop(k)
-            for cb in self.on_evict:
-                cb(k, v)
+            self.evict()
+
+    def evict(self):
+        """ Evict least recently used key
+
+        This is typically called from internal use, but can be externally
+        triggered as well.
+
+        Returns
+        -------
+        k: key
+        v: value
+        w: weight
+        """
+        k, priority = self.heap.popitem()
+        weight = self.weights.pop(k)
+        self.total_weight -= weight
+        v = self.d.pop(k)
+        for cb in self.on_evict:
+            cb(k, v)
+        return k, v, weight
 
     def __delitem__(self, key):
         del self.d[key]
diff --git a/zict/tests/test_file.py b/zict/tests/test_file.py
index 62fe887..91ae461 100644
--- a/zict/tests/test_file.py
+++ b/zict/tests/test_file.py
@@ -106,3 +106,10 @@ def test_arbitrary_chars(fn):
         del z[key]
         with pytest.raises(KeyError):
             z[key]
+
+
+def test_write_list_of_bytes(fn):
+    z = File(fn)
+
+    z['x'] = [b'123', b'4567']
+    assert z['x'] == b'1234567'
diff --git a/zict/tests/test_lru.py b/zict/tests/test_lru.py
index b9ecef6..330857e 100644
--- a/zict/tests/test_lru.py
+++ b/zict/tests/test_lru.py
@@ -110,3 +110,19 @@ def test_weight():
     lru['a'] = 10000
     assert 'a' not in lru
     assert d == {'y': 4}
+
+
+def test_explicit_evict():
+    d = dict()
+    lru = LRU(10, d)
+
+    lru['x'] = 1
+    lru['y'] = 2
+
+    assert set(d) == {'x', 'y'}
+
+    k, v, w = lru.evict()
+    assert set(d) == {'y'}
+    assert k == 'x'
+    assert v == 1
+    assert w == 1

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



More information about the Python-modules-commits mailing list