Permalink
Browse files

Merge branch 'release/0.10' into stable

  • Loading branch information...
2 parents db8a6ca + e1796e7 commit bc96c7138dec7c696fe23dda758d68a015e155ee @miracle2k committed Jul 3, 2014
Showing with 103 additions and 139 deletions.
  1. +19 −5 .travis.yml
  2. +3 −0 CHANGES
  3. +1 −4 README.rst
  4. +1 −1 requirements-dev.pip
  5. +2 −3 setup.py
  6. +54 −42 src/flask_assets.py
  7. +0 −28 tests/test_filters.py
  8. +12 −11 tests/test_integration.py
  9. +6 −2 tests/test_script.py
  10. +5 −43 tox.ini
View
@@ -1,14 +1,28 @@
language: python
python:
- 2.6
-install: pip install tox
-# List envs explicitly to skip PyPy
-script: tox -e py26_flask08,py27_flask08,py33_flask010
+ - 2.7
+ - 3.3
+ - pypy
+env:
+ - FLASK=0.8
+ - FLASK=0.9
+ - FLASK=0.10
+install:
+ - pip install Flask==$FLASK
+ - pip install -r requirements-dev.pip --allow-external webassets
+script:
+ - nosetests tests
notifications:
email:
- michael@elsdoerfer.com
branches:
only:
- master
-
-
+matrix:
+ exclude:
+ # These do not support Python 3 yet.
+ - python: 3.3
+ env: FLASK=0.8
+ - python: 3.3
+ env: FLASK=0.9
View
@@ -1,3 +1,6 @@
+0.10 (2014-07-03)
+ This release is compatible with webassets 0.10.
+
0.9 (2014-02-20)
This release is compatible with webassets 0.9.
flask-assets now support Python 3, and drops support for Python 2.5.
View
@@ -1,10 +1,7 @@
Integrates the `webassets`_ library with Flask, adding support for
merging, minifying and compiling CSS and Javascript files.
-Documentation of latest stable version:
- http://elsdoerfer.name/docs/flask-assets/
-
-Documentation of development version:
+Documentation:
http://flask-assets.readthedocs.org/
.. _webassets: http://github.com/miracle2k/webassets
View
@@ -1,6 +1,6 @@
nose
Flask>=0.8
Flask-Script>=0.3.3
-webassets>=0.8
+webassets==0.10
PyYAML
pyScss>=1.1.5
View
@@ -29,8 +29,7 @@ def parse_version(asignee):
else:
raise Exception("cannot find version")
version = parse_version('__version__')
-webassets_version = parse_version('__webassets_version__')
-
+webassets_requirement = parse_version('__webassets_version__')
setup(
name='Flask-Assets',
@@ -48,7 +47,7 @@ def parse_version(asignee):
platforms='any',
install_requires=[
'Flask>=0.8',
- 'webassets==%s' % webassets_version,
+ 'webassets%s' % webassets_requirement,
],
classifiers=[
'Environment :: Web Environment',
View
@@ -8,8 +8,8 @@
from webassets.loaders import PythonLoader, YAMLLoader
-__version__ = (0, 9)
-__webassets_version__ = (0, 9) # webassets core compatibility. used in setup.py
+__version__ = (0, 10)
+__webassets_version__ = ('>=0.10',) # webassets core compatibility. used in setup.py
__all__ = ('Environment', 'Bundle',)
@@ -24,6 +24,7 @@ class Jinja2Filter(Filter):
Flask contexts.
"""
name = 'jinja2'
+ max_debug_level = None
def __init__(self, context=None):
super(Jinja2Filter, self).__init__()
@@ -145,78 +146,77 @@ class FlaskResolver(Resolver):
are no longer resolved.
"""
- def split_prefix(self, item):
+ def split_prefix(self, ctx, item):
"""See if ``item`` has blueprint prefix, return (directory, rel_path).
"""
+ app = ctx.environment._app
try:
- if hasattr(self.env._app, 'blueprints'):
+ if hasattr(app, 'blueprints'):
blueprint, name = item.split('/', 1)
- directory = get_static_folder(self.env._app.blueprints[blueprint])
+ directory = get_static_folder(app.blueprints[blueprint])
endpoint = '%s.static' % blueprint
item = name
else:
# Module support for Flask < 0.7
module, name = item.split('/', 1)
- directory = get_static_folder(self.env._app.modules[module])
+ directory = get_static_folder(app.modules[module])
endpoint = '%s.static' % module
item = name
except (ValueError, KeyError):
- directory = get_static_folder(self.env._app)
+ directory = get_static_folder(app)
endpoint = 'static'
return directory, item, endpoint
- @property
- def use_webassets_system_for_output(self):
- return self.env.config.get('directory') is not None or \
- self.env.config.get('url') is not None
+ def use_webassets_system_for_output(self, ctx):
+ return ctx.config.get('directory') is not None or \
+ ctx.config.get('url') is not None
- @property
- def use_webassets_system_for_sources(self):
- return bool(self.env.load_path)
+ def use_webassets_system_for_sources(self, ctx):
+ return bool(ctx.load_path)
- def search_for_source(self, item):
+ def search_for_source(self, ctx, item):
# If a load_path is set, use it instead of the Flask static system.
#
# Note: With only env.directory set, we don't go to default;
# Setting env.directory only makes the output directory fixed.
- if self.use_webassets_system_for_sources:
- return Resolver.search_for_source(self, item)
+ if self.use_webassets_system_for_sources(ctx):
+ return Resolver.search_for_source(self, ctx, item)
# Look in correct blueprint's directory
- directory, item, endpoint = self.split_prefix(item)
+ directory, item, endpoint = self.split_prefix(ctx, item)
try:
return self.consider_single_directory(directory, item)
except IOError:
# XXX: Hack to make the tests pass, which are written to not
# expect an IOError upon missing files. They need to be rewritten.
return path.normpath(path.join(directory, item))
- def resolve_output_to_path(self, target, bundle):
+ def resolve_output_to_path(self, ctx, target, bundle):
# If a directory/url pair is set, always use it for output files
- if self.use_webassets_system_for_output:
- return Resolver.resolve_output_to_path(self, target, bundle)
+ if self.use_webassets_system_for_output(ctx):
+ return Resolver.resolve_output_to_path(self, ctx, target, bundle)
# Allow targeting blueprint static folders
- directory, rel_path, endpoint = self.split_prefix(target)
+ directory, rel_path, endpoint = self.split_prefix(ctx, target)
return path.normpath(path.join(directory, rel_path))
- def resolve_source_to_url(self, filepath, item):
+ def resolve_source_to_url(self, ctx, filepath, item):
# If a load path is set, use it instead of the Flask static system.
- if self.use_webassets_system_for_sources:
- return super(FlaskResolver, self).resolve_source_to_url(filepath, item)
+ if self.use_webassets_system_for_sources(ctx):
+ return super(FlaskResolver, self).resolve_source_to_url(ctx, filepath, item)
- return self.convert_item_to_flask_url(item, filepath)
+ return self.convert_item_to_flask_url(ctx, item, filepath)
- def resolve_output_to_url(self, target):
+ def resolve_output_to_url(self, ctx, target):
# With a directory/url pair set, use it for output files.
- if self.use_webassets_system_for_output:
- return Resolver.resolve_output_to_url(self, target)
+ if self.use_webassets_system_for_output(ctx):
+ return Resolver.resolve_output_to_url(self, ctx, target)
# Otherwise, behaves like all other flask URLs.
- return self.convert_item_to_flask_url(target)
+ return self.convert_item_to_flask_url(ctx, target)
- def convert_item_to_flask_url(self, item, filepath=None):
+ def convert_item_to_flask_url(self, ctx, item, filepath=None):
"""Given a relative reference like `foo/bar.css`, returns
the Flask static url. By doing so it takes into account
blueprints, i.e. in the aformentioned example,
@@ -230,7 +230,7 @@ def convert_item_to_flask_url(self, item, filepath=None):
then we import the url_for function from flask.ext.s3,
otherwise we import url_for from flask directly.
"""
- if self.env._app.config.get("FLASK_ASSETS_USE_S3"):
+ if ctx.environment._app.config.get("FLASK_ASSETS_USE_S3"):
try:
from flask.ext.s3 import url_for
except ImportError as e:
@@ -239,22 +239,22 @@ def convert_item_to_flask_url(self, item, filepath=None):
else:
from flask import url_for
- directory, rel_path, endpoint = self.split_prefix(item)
+ directory, rel_path, endpoint = self.split_prefix(ctx, item)
if filepath is not None:
filename = filepath[len(directory)+1:]
else:
filename = rel_path
- ctx = None
+ flask_ctx = None
if not _request_ctx_stack.top:
- ctx = self.env._app.test_request_context()
- ctx.push()
+ flask_ctx = ctx.environment._app.test_request_context()
+ flask_ctx.push()
try:
return url_for(endpoint, filename=filename)
finally:
- if ctx:
- ctx.pop()
+ if flask_ctx:
+ flask_ctx.pop()
class Environment(BaseEnvironment):
@@ -307,6 +307,14 @@ def get_directory(self):
directory = property(get_directory, set_directory, doc=
"""The base directory to which all paths will be relative to.
""")
+ def set_url(self, url):
+ self.config['url'] = url
+ def get_url(self):
+ if self.config.get('url') is not None:
+ return self.config['url']
+ return self._app.static_url_path
+ url = property(get_url, set_url, doc=
+ """The base url to which all static urls will be relative to.""")
def init_app(self, app):
app.jinja_env.add_extension('webassets.ext.jinja2.AssetsExtension')
@@ -339,6 +347,9 @@ def _construct_parser(self, *a, **kw):
super(FlaskArgparseInterface, self).\
_construct_parser(*a, **kw)
self.parser.add_argument(
+ '--jinja-extension', default='*.html',
+ help='specify the glob pattern for Jinja extensions (default: *.html)')
+ self.parser.add_argument(
'--parse-templates', action='store_true',
help='search project templates to find bundles')
@@ -350,7 +361,7 @@ def _setup_assets_env(self, ns, log):
# Note that we exclude container bundles. By their very nature,
# they are guaranteed to have been created by solely referencing
# other bundles which are already registered.
- env.add(*[b for b in self.load_from_templates(env)
+ env.add(*[b for b in self.load_from_templates(env, ns.jinja_extension)
if not b.is_container])
if not len(env):
@@ -361,7 +372,7 @@ def _setup_assets_env(self, ns, log):
'--parse-templates option.')
return env
- def load_from_templates(self, env):
+ def load_from_templates(self, env, jinja_extension):
from webassets.ext.jinja2 import Jinja2Loader, AssetsExtension
from flask import current_app as app
@@ -376,7 +387,8 @@ def load_from_templates(self, env):
template_dirs.append(
path.join(blueprint.root_path, blueprint.template_folder))
- return Jinja2Loader(env, template_dirs, [jinja2_env]).load_bundles()
+ return Jinja2Loader(env, template_dirs, [jinja2_env], jinja_ext=jinja_extension).\
+ load_bundles()
class ManageAssets(script.Command):
"""Manage assets."""
@@ -407,6 +419,6 @@ def run(self, args):
prog = '%s %s' % (os.path.basename(sys.argv[0]), sys.argv[1])
impl = self.implementation(self.env, prog=prog, log=self.log)
- impl.main(args)
+ return impl.main(args)
__all__ = __all__ + ('ManageAssets',)
View
@@ -1,28 +0,0 @@
-from __future__ import absolute_import
-from nose.tools import assert_raises
-from nose import SkipTest
-from tests.helpers import TempEnvironmentHelper
-
-
-class TestFilters(TempEnvironmentHelper):
-
- def test_pyscss(self):
- """This filter used to make trouble because if required
- Environment.url and Environment.directory to be set.
- """
- try:
- import scss
- except ImportError:
- raise SkipTest()
-
- self.create_files({'foo': ''})
- bundle = self.mkbundle('foo', filters='pyscss', output='out')
-
- # By default we'd get an error, because the filter can't use
- # any good defaults.
- assert_raises(EnvironmentError, bundle.build)
-
- # If we set a director/url pair, it works.
- self.env.config['PYSCSS_STATIC_ROOT'] = 'a'
- self.env.config['PYSCSS_STATIC_URL'] = 'b'
- bundle.build()
Oops, something went wrong.

0 comments on commit bc96c71

Please sign in to comment.