Skip to content

Commit 67e8ce5

Browse files
committed
Merge branch 'release/0.6.1' into stable
2 parents a9f1309 + 567425e commit 67e8ce5

File tree

5 files changed

+97
-34
lines changed

5 files changed

+97
-34
lines changed

CHANGES

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
0.6.1 (2011-10-10)
2+
- Building in 0.6 was very much broken (thanks Oliver Tonnhofer).
3+
- A custom "static_folder" for a Flask app or Blueprint/Module is now
4+
supported.
5+
16
0.6 (2011-10-03)
27
- Support webassets 0.6.
38
- Fixed use of wrong Flask app in some cases.

docs/conf.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
sys.path.append(os.path.abspath('_themes'))
2222

2323

24+
# make sure we are documenting the local version with autodoc
25+
sys.path.insert(0, os.path.abspath('../src'))
26+
from flaskext import assets as flaskassets
27+
28+
2429
# -- General configuration -----------------------------------------------------
2530

2631
# Add any Sphinx extension module names here, as strings. They can be extensions
@@ -48,9 +53,9 @@
4853
# built documents.
4954
#
5055
# The short X.Y version.
51-
version = '1.0'
56+
version = ".".join(map(str, flaskassets.__version__))
5257
# The full version, including alpha/beta/rc tags.
53-
release = '1.0'
58+
release = version
5459

5560
# The language for content autogenerated by Sphinx. Refer to documentation
5661
# for a list of supported languages.

src/flaskext/assets.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from webassets.env import BaseEnvironment, ConfigStorage
66

77

8-
__version__ = (0, 6)
8+
__version__ = (0, 6, 1)
99

1010
__all__ = ('Environment', 'Bundle',)
1111

@@ -76,6 +76,19 @@ def __delitem__(self, key):
7676
del self.env._app.config[self._transform_key(key)]
7777

7878

79+
80+
def get_static_folder(app_or_blueprint):
81+
"""Return the static folder of the given Flask app
82+
instance, or module/blueprint.
83+
84+
In newer Flask versions this can be customized, in older
85+
ones (<=0.6) the folder is fixed.
86+
"""
87+
if hasattr(app_or_blueprint, 'static_folder'):
88+
return app_or_blueprint.static_folder
89+
return path.join(app_or_blueprint.root_path, 'static')
90+
91+
7992
class Environment(BaseEnvironment):
8093

8194
config_storage_class = FlaskConfigStorage
@@ -141,6 +154,21 @@ def absurl(self, fragment):
141154
if ctx:
142155
ctx.pop()
143156

157+
# XXX: This is required because in a couple of places, webassets 0.6
158+
# still access env.directory, at one point even directly. We need to
159+
# fix this for 0.6 compatibility, but it might be preferrable to
160+
# introduce another API similar to _normalize_source_path() for things
161+
# like the cache directory and output files.
162+
def set_directory(self, directory):
163+
self.config['directory'] = directory
164+
def get_directory(self):
165+
if self.config.get('directory') is not None:
166+
return self.config['directory']
167+
return get_static_folder(self._app)
168+
directory = property(get_directory, set_directory, doc=
169+
"""The base directory to which all paths will be relative to.
170+
""")
171+
144172
def _normalize_source_path(self, filename):
145173
if path.isabs(filename):
146174
return filename
@@ -149,15 +177,15 @@ def _normalize_source_path(self, filename):
149177
try:
150178
if hasattr(self._app, 'blueprints'):
151179
blueprint, name = filename.split('/', 1)
152-
directory = path.join(self._app.blueprints[blueprint].root_path, 'static')
180+
directory = get_static_folder(self._app.blueprints[blueprint])
153181
filename = name
154182
else:
155183
# Module support for Flask < 0.7
156184
module, name = filename.split('/', 1)
157-
directory = path.join(self._app.modules[module].root_path, 'static')
185+
directory = get_static_folder(self._app.modules[module])
158186
filename = name
159187
except (ValueError, KeyError):
160-
directory = path.join(self._app.root_path, 'static')
188+
directory = get_static_folder(self._app)
161189
return path.abspath(path.join(directory, filename))
162190

163191
def init_app(self, app):

tests/helpers.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,37 @@
1-
from flask.app import Flask, Blueprint, Module
1+
from nose import SkipTest
2+
from nose.tools import assert_raises
3+
from flask.app import Flask
4+
try:
5+
from flask import __version__ as FLASK_VERSION
6+
except ImportError:
7+
FLASK_VERSION = '0.6'
28
from webassets.test import TempEnvironmentHelper as BaseTempEnvironmentHelper
39
from flaskext.assets import Environment
410

11+
try:
12+
from flask import Blueprint
13+
Module = None
14+
except ImportError:
15+
# Blueprints only available starting with 0.7,
16+
# fall back to old Modules otherwise.
17+
Blueprint = None
18+
from flask import Module
519

6-
__all__ = ('TempEnvironmentHelper',)
720

21+
__all__ = ('TempEnvironmentHelper', 'Module', 'Blueprint')
822

9-
class TempEnvironmentHelper(BaseTempEnvironmentHelper):
10-
11-
def setdp(self):
12-
# webassets now requires the files we pass in to exist,
13-
# so we can' just do tests with arbitrary filenames.
14-
self.app = Flask(__name__, static_path='/app_static')
15-
import test_module
16-
if not Blueprint:
17-
self.module = Module(test_module.__name__, name='module',
18-
static_path='/mod_static')
19-
self.app.register_module(self.module)
20-
else:
21-
self.blueprint = Blueprint('module', test_module.__name__,
22-
static_url_path='/mod_static',
23-
static_folder='static')
24-
self.app.register_blueprint(self.blueprint)
25-
self.env = Environment(self.app)
2623

24+
class TempEnvironmentHelper(BaseTempEnvironmentHelper):
2725

2826
def _create_environment(self):
27+
if FLASK_VERSION < '0.7':
28+
# Older Flask versions do not support the
29+
# static_folder argument, which we need to use
30+
# a temporary folder for static files, without
31+
# having to do sys.path hacking.
32+
raise SkipTest()
33+
2934
if not hasattr(self, 'app'):
30-
self.app = Flask(__name__)
35+
self.app = Flask(__name__, static_folder=self.tempdir)
3136
self.env = Environment(self.app)
3237
return self.env

tests/test_integration.py

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,10 @@
22
from nose.tools import assert_raises
33

44
from flask import Flask
5-
try:
6-
from flask import Blueprint
7-
except ImportError:
8-
# Blueprints only available starting with 0.7,
9-
# fall back to old Modules otherwise.
10-
Blueprint = None
11-
from flask import Module
125
from flaskext.assets import Environment, Bundle
136
from webassets.bundle import get_all_bundle_files
14-
7+
from helpers import TempEnvironmentHelper, Module, Blueprint
8+
159

1610
class TestUrlAndDirectory(object):
1711
"""By default, the 'url' and 'directory' settings of webassets are
@@ -61,6 +55,10 @@ def test_directory_auto(self):
6155
# module name, you can always use this hack:
6256
assert get_all_bundle_files(Bundle('./module/bar'), self.env) == [root + '/static/module/bar']
6357

58+
# Custom static folder
59+
self.app.static_folder = '/'
60+
assert get_all_bundle_files(Bundle('foo'), self.env) == ['/foo']
61+
6462
def test_directory_custom(self):
6563
"""A custom root directory is configured."""
6664
self.env.directory = '/tmp'
@@ -127,3 +125,25 @@ def test(self):
127125
root = self.app.root_path
128126
assert get_all_bundle_files(Bundle('foo'), self.env) == [root + '/static/foo']
129127

128+
129+
class TestBuild(TempEnvironmentHelper):
130+
"""[Regression]
131+
132+
Make sure actually building a bundle works also.
133+
"""
134+
135+
default_files = {
136+
'foo': 'function bla () { /* comment */ var a; } ',
137+
}
138+
139+
def test_build(self):
140+
self.mkbundle('foo', filters='rjsmin', output='out').build()
141+
assert self.get('out') == 'function bla(){var a;}'
142+
143+
def test_with_cache_default_directory(self):
144+
"""[Regression] The cache directory is created in the Flask
145+
main static folder.
146+
"""
147+
self.env.cache = True
148+
self.mkbundle('foo', filters='rjsmin', output='out').build()
149+
assert self.get('out') == 'function bla(){var a;}'

0 commit comments

Comments
 (0)