Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save keitheis/37de7d83a50c9d25e30b to your computer and use it in GitHub Desktop.
Save keitheis/37de7d83a50c9d25e30b to your computer and use it in GitHub Desktop.
Failed test_asset_spec_no_static_view
________________ TestAssetSpecs.test_asset_spec_no_static_view _________________
self = <pyramid_webassets.tests.test_webassets.TestAssetSpecs testMethod=test_asset_spec_no_static_view>
def test_asset_spec_no_static_view(self):
from webassets import Bundle
self.create_files({
'dotted/__init__.py': '',
'dotted/package/__init__.py': '',
'dotted/package/name/__init__.py': '',
'dotted/package/name/static/zing.css':
'* { text-decoration: underline }'})
asset_spec = 'dotted.package.name:static/zing.css'
bundle = Bundle(asset_spec)
# webassets will copy the file into a place that it can generate
# a url for
> urls = _urls(bundle, self.env)
pyramid_webassets/tests/test_webassets.py:576:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
bundle = <Bundle output=None, filters=(), contents=('dotted.package.name:static/zing.css',)>
env = <pyramid_webassets.Environment object at 0x108b54518>
def _urls(bundle, env):
if webassets_version > (0, 9):
with bundle.bind(env):
> return bundle.urls()
pyramid_webassets/tests/test_webassets.py:16:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Bundle output=None, filters=(), contents=('dotted.package.name:static/zing.css',)>
args = (), kwargs = {}
ctx = <webassets.bundle.ContextWrapper object at 0x108b83b00>, urls = []
bundle = <Bundle output=None, filters=(), contents=('dotted.package.name:static/zing.css',)>
extra_filters = []
new_ctx = <webassets.bundle.ContextWrapper object at 0x108b83b00>
def urls(self, *args, **kwargs):
"""Return a list of urls for this bundle.
Depending on the environment and given options, this may be a single
url (likely the case in production mode), or many urls (when we source
the original media files in DEBUG mode).
Insofar necessary, this will automatically create or update the files
behind these urls.
"""
ctx = wrap(self.env, self)
urls = []
for bundle, extra_filters, new_ctx in self.iterbuild(ctx):
> urls.extend(bundle._urls(new_ctx, extra_filters, *args, **kwargs))
../../../.virtualenvs/34/lib/python3.4/site-packages/webassets/bundle.py:787:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Bundle output=None, filters=(), contents=('dotted.package.name:static/zing.css',)>
ctx = <webassets.bundle.ContextWrapper object at 0x108b83b00>
extra_filters = [], args = (), kwargs = {}, debug = False
supposed_to_merge = True, urls = []
def _urls(self, ctx, extra_filters, *args, **kwargs):
"""Return a list of urls for this bundle, and all subbundles,
and, when it becomes necessary, start a build process.
"""
# Look at the debug value to see if this bundle should return the
# source urls (in debug mode), or a single url of the bundle in built
# form. Once a bundle needs to be built, all of it's child bundles
# are built as well of course, so at this point we leave the urls()
# recursion and start a build() recursion.
debug = _effective_debug_level(ctx, self, extra_filters)
if debug == 'merge':
supposed_to_merge = True
elif debug is True:
supposed_to_merge = False
elif debug is False:
supposed_to_merge = True
else:
raise BundleError('Invalid debug value: %s' % debug)
# We will output a single url for this bundle unless a) the
# configuration tells us to output the source urls
# ("supposed_to_merge"), or b) this bundle isn't actually configured to
# be built, that is, has no filters and no output target.
if supposed_to_merge and (self.filters or self.output):
# With ``auto_build``, build the bundle to make sure the output is
# up to date; otherwise, we just assume the file already exists.
# (not wasting any IO ops)
if ctx.auto_build:
self._build(ctx, extra_filters=extra_filters, force=False,
*args, **kwargs)
return [self._make_output_url(ctx)]
else:
# We either have no files (nothing to build), or we are
# in debug mode: Instead of building the bundle, we
# source all contents instead.
urls = []
> for org, cnt in self.resolve_contents(ctx):
if isinstance(cnt, Bundle):
../../../.virtualenvs/34/lib/python3.4/site-packages/webassets/bundle.py:753:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <Bundle output=None, filters=(), contents=('dotted.package.name:static/zing.css',)>
ctx = <webassets.bundle.ContextWrapper object at 0x108b83b00>, force = False
def resolve_contents(self, ctx=None, force=False):
"""Return an actual list of source files.
What the user specifies as the bundle contents cannot be
processed directly. There may be glob patterns of course. We
may need to search the load path. It's common for third party
extensions to provide support for referencing assets spread
across multiple directories.
This passes everything through :class:`Environment.resolver`,
through which this process can be customized.
At this point, we also validate source paths to complain about
missing files early.
The return value is a list of 2-tuples ``(original_item,
abspath)``. In the case of urls and nested bundles both tuple
values are the same.
Set ``force`` to ignore any cache, and always re-resolve
glob patterns.
"""
if not ctx:
ctx = wrap(self.env, self)
# TODO: We cache the values, which in theory is problematic, since
# due to changes in the env object, the result of the globbing may
# change. Not to mention that a different env object may be passed
# in. We should find a fix for this.
if getattr(self, '_resolved_contents', None) is None or force:
resolved = []
for item in self.contents:
try:
> result = ctx.resolver.resolve_source(ctx, item)
../../../.virtualenvs/34/lib/python3.4/site-packages/webassets/bundle.py:233:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pyramid_webassets.PyramidResolver object at 0x108d11940>
ctx = <webassets.bundle.ContextWrapper object at 0x108b83b00>
item = 'dotted.package.name:static/zing.css'
def resolve_source(self, ctx, item):
"""Given ``item`` from a Bundle's contents, this has to
return the final value to use, usually an absolute
filesystem path.
.. note::
It is also allowed to return urls and bundle instances
(or generally anything else the calling :class:`Bundle`
instance may be able to handle). Indeed this is the
reason why the name of this method does not imply a
return type.
The incoming item is usually a relative path, but may also be
an absolute path, or a url. These you will commonly want to
return unmodified.
This method is also allowed to resolve ``item`` to multiple
values, in which case a list should be returned. This is
commonly used if ``item`` includes glob instructions
(wildcards).
.. note::
Instead of this, subclasses should consider implementing
:meth:`search_for_source` instead.
"""
# Pass through some things unscathed
if not isinstance(item, six.string_types):
# Don't stand in the way of custom values.
return item
if is_url(item) or path.isabs(item):
return item
> return self.search_for_source(ctx, item)
../../../.virtualenvs/34/lib/python3.4/site-packages/webassets/env.py:242:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pyramid_webassets.PyramidResolver object at 0x108d11940>
ctx = <webassets.bundle.ContextWrapper object at 0x108b83b00>
item = 'dotted.package.name:static/zing.css'
def search_for_source(self, ctx, item):
print("search_for_source")
package, subpath = self._split_spec(item)
print(package, subpath, item)
if package is None:
if USING_WEBASSETS_CONTEXT:
return super(PyramidResolver, self).search_for_source(
ctx,
item
)
else: # pragma: no cover
return super(PyramidResolver, self).search_for_source(
item
)
else:
> pkgpath = self._resolve_spec(package + ':')
pyramid_webassets/__init__.py:76:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <pyramid_webassets.PyramidResolver object at 0x108d11940>
spec = 'dotted.package.name:'
def _resolve_spec(self, spec):
print("_resolve_spec")
package, subpath = self._split_spec(spec)
print(package, subpath, spec)
try:
pkgpath = self.resolver.resolve(package + ':').abspath()
except ImportError as e:
> raise BundleError(e)
E webassets.exceptions.BundleError: No module named 'dotted'
pyramid_webassets/__init__.py:57: BundleError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment