summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Merickel <michael@merickel.org>2015-11-12 10:45:47 -0600
committerMichael Merickel <michael@merickel.org>2015-11-12 19:57:12 -0600
commit7410250313f893e5952bb2697324a4d4e3d47d22 (patch)
tree2eb128eb555568dfe19a4a256b1ebe569edd35ac
parentcbec33b898efffbfa6acaf91cae45ec0daed4d7a (diff)
downloadpyramid-7410250313f893e5952bb2697324a4d4e3d47d22.tar.gz
pyramid-7410250313f893e5952bb2697324a4d4e3d47d22.tar.bz2
pyramid-7410250313f893e5952bb2697324a4d4e3d47d22.zip
support asset specs in ManifestCacheBuster
-rw-r--r--pyramid/static.py22
-rw-r--r--pyramid/tests/test_static.py14
2 files changed, 30 insertions, 6 deletions
diff --git a/pyramid/static.py b/pyramid/static.py
index 59f440c82..c2c8c89e5 100644
--- a/pyramid/static.py
+++ b/pyramid/static.py
@@ -19,7 +19,10 @@ from pkg_resources import (
from repoze.lru import lru_cache
-from pyramid.asset import resolve_asset_spec
+from pyramid.asset import (
+ abspath_from_asset_spec,
+ resolve_asset_spec,
+)
from pyramid.compat import text_
@@ -211,7 +214,11 @@ class ManifestCacheBuster(object):
uses a supplied manifest file to map an asset path to a cache-busted
version of the path.
- The file is expected to conform to the following simple JSON format:
+ The ``manifest_spec`` can be an absolute path or a :term:`asset spec`
+ pointing to a package-relative file.
+
+ The manifest file is expected to conform to the following simple JSON
+ format:
.. code-block:: json
@@ -222,7 +229,7 @@ class ManifestCacheBuster(object):
Specifically, it is a JSON-serialized dictionary where the keys are the
source asset paths used in calls to
- :meth:`~pyramid.request.Request.static_url. For example::
+ :meth:`~pyramid.request.Request.static_url`. For example::
.. code-block:: python
@@ -247,8 +254,10 @@ class ManifestCacheBuster(object):
exists = staticmethod(exists) # testing
getmtime = staticmethod(getmtime) # testing
- def __init__(self, manifest_path, reload=False):
- self.manifest_path = manifest_path
+ def __init__(self, manifest_spec, reload=False):
+ package_name = caller_package().__name__
+ self.manifest_path = abspath_from_asset_spec(
+ manifest_spec, package_name)
self.reload = reload
self._mtime = None
@@ -260,7 +269,8 @@ class ManifestCacheBuster(object):
Return a mapping parsed from the ``manifest_path``.
Subclasses may override this method to use something other than
- ``json.loads``.
+ ``json.loads`` to load any type of file format and return a conforming
+ dictionary.
"""
with open(self.manifest_path, 'rb') as fp:
diff --git a/pyramid/tests/test_static.py b/pyramid/tests/test_static.py
index ac30e9e50..4a07c2cb1 100644
--- a/pyramid/tests/test_static.py
+++ b/pyramid/tests/test_static.py
@@ -423,6 +423,20 @@ class TestManifestCacheBuster(unittest.TestCase):
fut('foo', ('css', 'main.css'), {}),
(['css', 'main-test.css'], {}))
+ def test_it_with_relspec(self):
+ fut = self._makeOne('fixtures/manifest.json').pregenerate
+ self.assertEqual(fut('foo', ('bar',), {}), (['bar'], {}))
+ self.assertEqual(
+ fut('foo', ('css', 'main.css'), {}),
+ (['css', 'main-test.css'], {}))
+
+ def test_it_with_absspec(self):
+ fut = self._makeOne('pyramid.tests:fixtures/manifest.json').pregenerate
+ self.assertEqual(fut('foo', ('bar',), {}), (['bar'], {}))
+ self.assertEqual(
+ fut('foo', ('css', 'main.css'), {}),
+ (['css', 'main-test.css'], {}))
+
def test_reload(self):
manifest_path = os.path.join(here, 'fixtures', 'manifest.json')
new_manifest_path = os.path.join(here, 'fixtures', 'manifest2.json')