From 3e59c158ff8db1de9e489c505bfb23cd5178acf5 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Tue, 24 Dec 2013 15:30:39 -0800 Subject: [PATCH] enable queries over computed attributes This makes containment (field in obj) work with all attributes even though other dict-like methods for iterating over the object don't expose computed fields by default. I think this is the right compromise to avoid accidental eager evaluation of computed fields. --- beets/__init__.py | 2 +- beets/library.py | 9 +++++---- docs/changelog.rst | 15 +++++++++++++++ docs/conf.py | 2 +- setup.py | 2 +- 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/beets/__init__.py b/beets/__init__.py index 8fd145982..936a4d2e7 100644 --- a/beets/__init__.py +++ b/beets/__init__.py @@ -12,7 +12,7 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. -__version__ = '1.3.2' +__version__ = '1.3.3' __author__ = 'Adrian Sampson ' import beets.library diff --git a/beets/library.py b/beets/library.py index c514e24c7..565510280 100644 --- a/beets/library.py +++ b/beets/library.py @@ -360,9 +360,9 @@ class Model(object): self._dirty.add(key) def keys(self, computed=False): - """Get the fixed, flexible, and plugin-provided field names for - this object. The `computed` parameter controls whether computed - (plugin-provided) fields are included in the key list. + """Get a list of available field names for this object. The + `computed` parameter controls whether computed (plugin-provided) + fields are included in the key list. """ base_keys = list(self._fields) + self._values_flex.keys() if computed: @@ -381,6 +381,7 @@ class Model(object): def items(self): """Iterate over (key, value) pairs that this object contains. + Computed fields are not included. """ for key in self.keys(): yield key, self[key] @@ -397,7 +398,7 @@ class Model(object): def __contains__(self, key): """Determine whether `key` is an attribute on this object. """ - return key in self.keys() + return key in self.keys(True) # Convenient attribute access. diff --git a/docs/changelog.rst b/docs/changelog.rst index 648911376..6114fceac 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -1,6 +1,21 @@ Changelog ========= +1.3.3 (in development) +---------------------- + +Version 1.3.3 brings a set of internal changes to how fields work. The +consequences for all users are: + +* Plugin-provided fields can now be used in queries. For example, if you use + the :doc:`/plugins/inline` to define a field called ``era``, you can now + filter your library based on that field by typing something like + ``beet list era:goldenage``. + +For developers, the short version of the story is that Item and Album objects +provide *uniform access* across fixed, flexible, and computed attributes. + + 1.3.2 (December 22, 2013) ------------------------- diff --git a/docs/conf.py b/docs/conf.py index 38e235620..691a9d5f6 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -13,7 +13,7 @@ project = u'beets' copyright = u'2012, Adrian Sampson' version = '1.3' -release = '1.3.2' +release = '1.3.3' pygments_style = 'sphinx' diff --git a/setup.py b/setup.py index 03cf855b0..a0e693400 100755 --- a/setup.py +++ b/setup.py @@ -42,7 +42,7 @@ if 'sdist' in sys.argv: shutil.copytree(os.path.join(docdir, '_build', 'man'), mandir) setup(name='beets', - version='1.3.2', + version='1.3.3', description='music tagger and library organizer', author='Adrian Sampson', author_email='adrian@radbox.org',