Skip to content

Commit 185b475

Browse files
committed
Merge branch 'release/0.7' into stable
2 parents 2bfd73f + 094a764 commit 185b475

File tree

14 files changed

+220
-136
lines changed

14 files changed

+220
-136
lines changed

.travis.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
language: python
2+
python:
3+
- 2.6
4+
install: pip install tox
5+
# List envs explicitly to skip PyPy
6+
script: tox -e py25_flask08,py26_flask08,py27_flask08
7+
notifications:
8+
email:
9+
- michael@elsdoerfer.com
10+
branches:
11+
only:
12+
- master
13+
14+

CHANGES

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
0.7 (2012-04-11)
2+
This release is compatible with webassets 0.7.
3+
4+
- Now officially requires at least Flask 0.8, so it can use the new
5+
extension import system, but using the compatibility module, older
6+
Flask versions should work fine as well:
7+
http://flask.pocoo.org/docs/extensions/
8+
- Support Python 2.5.
9+
- Allow customizing the backend of ``ManageAssets`` command.
10+
- Due to webassets 0.7, the cssrewrite filter now works with Blueprints.
11+
112
0.6.2 (2011-10-12)
213
- Fixed Blueprint/Module resolving in output path.
314

TODO

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ attempting something like g.assets_env.register().
55

66
Using loaders is currently somewhat verbose, it'd be more micro-framework-like
77
if we could say "assets_env.load('yaml', ...)".
8+
9+
Now that we officially require Flask 0.8, and are no longer testing
10+
older versions, remove the support code for those older versions.

docs/index.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Flask-Assets
22
============
33

4-
.. module:: flaskext.assets
4+
.. module:: flask_assets
55

66
Flask-Assets helps you to integrate `webassets`_ into your `Flask`_
77
application.
@@ -31,7 +31,7 @@ registering your assets with it in the form of so called *bundles*.
3131
.. code-block:: python
3232
3333
from flask import Flask
34-
from flaskext.assets import Environment, Bundle
34+
from flask.ext.assets import Environment, Bundle
3535
3636
app = Flask(__name__)
3737
assets = Environment(app)
@@ -59,7 +59,7 @@ rather than passing a fixed application object:
5959
.. code-block:: python
6060
6161
app = Flask(__name__)
62-
assets = flaskext.assets.Environment()
62+
assets = flask.ext.assets.Environment()
6363
assets.init_app(app)
6464
6565

example/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
sys.path.insert(0, path.join(path.dirname(__file__), '../src'))
55

66
from flask import Flask, render_template, url_for
7-
from flaskext.assets import Environment, Bundle
7+
from flask.ext.assets import Environment, Bundle
88

99
app = Flask(__name__)
1010

setup.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,46 +8,47 @@
88
merging, minifying and compiling CSS and Javascript files.
99
"""
1010

11-
from setuptools import setup, find_packages
11+
from __future__ import with_statement
12+
from setuptools import setup
1213

1314
# Figure out the version; this could be done by importing the
1415
# module, though that requires dependencies to be already installed,
1516
# which may not be the case when processing a pip requirements
16-
# file, for example.a
17-
import os, re
18-
here = os.path.dirname(os.path.abspath(__file__))
19-
version_re = re.compile(
20-
r'__version__ = (\(.*?\))')
21-
fp = open(os.path.join(here, 'src/flaskext', 'assets.py'))
22-
version = None
23-
for line in fp:
24-
match = version_re.search(line)
25-
if match:
26-
version = eval(match.group(1))
27-
break
28-
else:
29-
raise Exception("cannot find version")
30-
fp.close()
17+
# file, for example.
18+
def parse_version(asignee):
19+
import os, re
20+
here = os.path.dirname(os.path.abspath(__file__))
21+
version_re = re.compile(
22+
r'__version__ = (\(.*?\))')
23+
with open(os.path.join(here, 'src', 'flask_assets.py')) as fp:
24+
for line in fp:
25+
match = version_re.search(line)
26+
if match:
27+
version = eval(match.group(1))
28+
return ".".join(map(str, version))
29+
else:
30+
raise Exception("cannot find version")
31+
version = parse_version('__version__')
32+
webassets_version = parse_version('__webassets_version__')
3133

3234

3335
setup(
3436
name='Flask-Assets',
35-
version=".".join(map(str, version)),
37+
version=version,
3638
url='http://github.com/miracle2k/flask-assets',
3739
license='BSD',
3840
author='Michael Elsdoerfer',
3941
author_email='michael@elsdoerfer.com',
4042
description='Asset management for Flask, to compress and merge ' \
4143
'CSS and Javascript files.',
4244
long_description=__doc__,
43-
packages=find_packages('src'),
45+
py_modules=['flask_assets'],
4446
package_dir={'': 'src'},
45-
namespace_packages=['flaskext'],
4647
zip_safe=False,
4748
platforms='any',
4849
install_requires=[
49-
'Flask>=0.6',
50-
'webassets==0.6',
50+
'Flask>=0.8',
51+
'webassets==%s' % webassets_version,
5152
],
5253
classifiers=[
5354
'Environment :: Web Environment',
@@ -63,4 +64,4 @@
6364
'nose',
6465
'flask-script'
6566
],
66-
)
67+
)

src/flaskext/assets.py renamed to src/flask_assets.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
from __future__ import with_statement
22
from os import path
33
from flask import _request_ctx_stack, url_for
4-
from webassets import Bundle
5-
from webassets.env import BaseEnvironment, ConfigStorage
4+
from webassets.env import BaseEnvironment, ConfigStorage, env_options
5+
66

7+
__version__ = (0, 7)
8+
__webassets_version__ = (0, 7) # webassets core compatibility. used in setup.py
79

8-
__version__ = (0, 6, 2)
910

1011
__all__ = ('Environment', 'Bundle',)
1112

1213

14+
# We want to expose this here.
15+
from webassets import Bundle
16+
17+
1318
class FlaskConfigStorage(ConfigStorage):
1419
"""Uses the config object of a Flask app as the backend: either the app
1520
instance bound to the extension directly, or the current Flasp app on
@@ -25,15 +30,12 @@ class FlaskConfigStorage(ConfigStorage):
2530
allow global across-app defaults.
2631
"""
2732

28-
_mapping = [
29-
'debug', 'cache', 'updater', 'auto_create', 'expire', 'directory', 'url',]
30-
3133
def __init__(self, *a, **kw):
3234
self._defaults = {}
3335
ConfigStorage.__init__(self, *a, **kw)
3436

3537
def _transform_key(self, key):
36-
if key.lower() in self._mapping:
38+
if key.lower() in env_options:
3739
return "ASSETS_%s" % key.upper()
3840
else:
3941
return key.upper()
@@ -51,6 +53,10 @@ def __contains__(self, key):
5153
return self._transform_key(key) in self.env._app.config
5254

5355
def __getitem__(self, key):
56+
value = self._get_deprecated(key)
57+
if value:
58+
return value
59+
5460
# First try the current app's config
5561
public_key = self._transform_key(key)
5662
if self.env._app:
@@ -70,7 +76,8 @@ def __getitem__(self, key):
7076
raise KeyError()
7177

7278
def __setitem__(self, key, value):
73-
self.env._app.config[self._transform_key(key)] = value
79+
if not self._set_deprecated(key, value):
80+
self.env._app.config[self._transform_key(key)] = value
7481

7582
def __delitem__(self, key):
7683
del self.env._app.config[self._transform_key(key)]
@@ -206,6 +213,7 @@ def init_app(self, app):
206213
pass
207214
else:
208215
import argparse
216+
from webassets.script import GenericArgparseImplementation
209217

210218
class CatchAllParser(object):
211219
def parse_known_args(self, app_args):
@@ -215,8 +223,9 @@ class ManageAssets(script.Command):
215223
"""Manage assets."""
216224
capture_all_args = True
217225

218-
def __init__(self, assets_env=None):
226+
def __init__(self, assets_env=None, impl=GenericArgparseImplementation):
219227
self.env = assets_env
228+
self.implementation = impl
220229

221230
def create_parser(self, prog):
222231
return CatchAllParser()
@@ -231,7 +240,14 @@ def run(self, args):
231240
from flask import current_app
232241
self.env = current_app.jinja_env.assets_environment
233242

234-
from webassets import script
235-
return script.main(args, env=self.env)
243+
# Determine 'prog' - something like for example
244+
# "./manage.py assets", to be shown in the help string.
245+
# While we don't know the command name we are registered with
246+
# in Flask-Assets, we are lucky to be able to rely on the
247+
# name being in argv[1].
248+
import sys, os.path
249+
prog = '%s %s' % (os.path.basename(sys.argv[0]), sys.argv[1])
250+
251+
return self.implementation(self.env, prog=prog).main(args)
236252

237253
__all__ = __all__ + ('ManageAssets',)

src/flaskext/__init__.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

tests/helpers.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
except ImportError:
77
FLASK_VERSION = '0.6'
88
from webassets.test import TempEnvironmentHelper as BaseTempEnvironmentHelper
9-
from flaskext.assets import Environment
9+
from flask.ext.assets import Environment
1010

1111
try:
1212
from flask import Blueprint
@@ -23,7 +23,7 @@
2323

2424
class TempEnvironmentHelper(BaseTempEnvironmentHelper):
2525

26-
def _create_environment(self):
26+
def _create_environment(self, **kwargs):
2727
if FLASK_VERSION < '0.7':
2828
# Older Flask versions do not support the
2929
# static_folder argument, which we need to use
@@ -32,6 +32,21 @@ def _create_environment(self):
3232
raise SkipTest()
3333

3434
if not hasattr(self, 'app'):
35-
self.app = Flask(__name__, static_folder=self.tempdir)
35+
self.app = Flask(__name__, static_folder=self.tempdir, **kwargs)
3636
self.env = Environment(self.app)
3737
return self.env
38+
39+
40+
41+
try:
42+
from test.test_support import check_warnings
43+
except ImportError:
44+
# Python < 2.6
45+
import contextlib
46+
47+
@contextlib.contextmanager
48+
def check_warnings(*filters, **kwargs):
49+
# We cannot reasonably support this, we'd have to copy to much code.
50+
# (or write our own). Since this is only testing warnings output,
51+
# we might slide by ignoring it.
52+
yield

tests/test_config.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
"""
33

44
from __future__ import with_statement
5+
from helpers import check_warnings
56

67
from nose.tools import assert_raises
78
from flask import Flask
8-
from flaskext.assets import Environment
9+
from flask.ext.assets import Environment
10+
from webassets.exceptions import ImminentDeprecationWarning
11+
912
try:
1013
from webassets.updater import BaseUpdater
1114
except ImportError:
@@ -110,3 +113,48 @@ def test_key_error(self):
110113
# The get() helper, on the other hand, simply returns None
111114
assert self.env.config.get('YADDAYADDA') == None
112115

116+
117+
118+
class TestVersionSystemDeprecations(object):
119+
"""With the introduction of the ``Environment.version`` system,
120+
some functionality has been deprecated.
121+
"""
122+
123+
def setup(self):
124+
app = Flask(__name__)
125+
self.env = Environment(app)
126+
127+
def test_expire_option(self):
128+
# Assigning to the expire option raises a deprecation warning
129+
with check_warnings(("", ImminentDeprecationWarning)) as w:
130+
self.env.expire = True
131+
with check_warnings(("", ImminentDeprecationWarning)):
132+
self.env.config['expire'] = True
133+
# Reading the expire option raises a warning also.
134+
with check_warnings(("", ImminentDeprecationWarning)):
135+
x = self.env.expire
136+
with check_warnings(("", ImminentDeprecationWarning)):
137+
x = self.env.config['expire']
138+
139+
def test_expire_option_passthrough(self):
140+
"""While "expire" no longer exists, we attempt to provide an
141+
emulation."""
142+
with check_warnings(("", ImminentDeprecationWarning)):
143+
# Read
144+
self.env.url_expire = True
145+
assert self.env.expire == 'querystring'
146+
# Write
147+
self.env.expire = False
148+
assert self.env.url_expire == False
149+
self.env.expire = 'querystring'
150+
assert self.env.url_expire == True
151+
# "filename" needs to be migrated manually
152+
assert_raises(DeprecationWarning, setattr, self.env, 'expire', 'filename')
153+
154+
def test_updater_option_passthrough(self):
155+
"""Certain values of the "updater" option have been replaced with
156+
auto_build."""
157+
with check_warnings(("", ImminentDeprecationWarning)):
158+
self.env.auto_build = True
159+
self.env.updater = False
160+
assert self.env.auto_build == False

tests/test_env.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from nose.tools import assert_raises
22
from flask import Flask
3-
from flaskext.assets import Environment
3+
from flask.ext.assets import Environment
44

55

66
class TestEnv:

0 commit comments

Comments
 (0)