Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid overwriting settings by storing them separately on the configuration context #433

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 35 additions & 32 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,46 @@
language: python
python:
- 2.6
python: 2.7
sudo: false
install:
# Supposed to help get PIL to install on PyPi
# https://github.com/python-imaging/Pillow/issues/570
- sudo apt-get install python-tk

# To install external filter binaries, we first need to install
# RubyGems and Node/NPM. I'm not sure why, since it seems clear
# that NVM and RVM are pre-installed (see below).
- sudo apt-get install python-software-properties
- sudo apt-add-repository -y ppa:chris-lea/node.js
- sudo apt-get update
- sudo apt-get install nodejs rubygems
- sudo apt-get install npm
- npm install -g postcss autoprefixer
# Setup a virtualenv (to allow installing nodeenv)
- rm -rf py_env
- virtualenv py_env
- . py_env/bin/activate
- pip install nodeenv

# These are useful for debugging this mess.
#- env
#- gem env
#- rvm info
# Install and activate nodeenv (to get a current version of nodejs)
- rm -rf node_env
- source py_env/bin/activate
- nodeenv node_env --node=4.0.0 --prebuilt
- source node_env/bin/activate

# Use non-http registry? https://github.com/n1k0/casperjs/issues/876
# Without this, installing doesn't work.
- sudo npm config set registry http://registry.npmjs.org/

# Now install the external filter binaries, finally.
# If we use sudo for this, ruby gems will not work: it seems they are
# then installed globally, but are then searched for in a RVM location.
# (Clearing GEM_HOME might be a way to fix this, if sudo where necessary).
# Install node requirements (inside the nodeenv)
- sh requirements-dev.sh

# Install our test runner
# Install our test runner (inside the virtualenv)
- pip install tox

script: tox
notifications:
email:
- [email protected]
env:
- TOX_ENV=py27
- TOX_ENV=py33
- TOX_ENV=py34
- TOX_ENV=py35
- TOX_ENV=pypy
- TOX_ENV=no-glob2
- TOX_ENV=external-jsmin
script: tox -e $TOX_ENV
branches:
only:
- master
addons:
apt:
sources:
- deadsnakes
packages:
- python3.3
- python3.4
- python3.5
- python-tk
- python-software-properties
- rubygems
- python-virtualenv
2 changes: 1 addition & 1 deletion requirements-dev-2.x.pip
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ slimmer
cssmin

# Default rsmin package is not installable via pip
http://michael.elsdoerfer.name/rjsmin/rjsmin-1.0.1-webassets.tar.gz
rjsmin
7 changes: 1 addition & 6 deletions requirements-dev.pip
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ mock
Sphinx

# Libs that are needed for some features
PyYaml
glob2

# Libs that are needed by filters.
Expand All @@ -22,8 +21,4 @@ cssutils
yuicompressor
closure
slimit==0.8.1
ply==3.4 # https://github.com/rspivak/slimit/issues/76
libsass==0.8.3

# Python libs that requiring manual installation
#cssprefixer
ply==3.4 # https://github.com/rspivak/slimit/issues/76
2 changes: 2 additions & 0 deletions requirements-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ npm install -g stylus
npm install -g handlebars
npm install -g typescript
npm install -g [email protected]
npm install -g autoprefixer
npm install -g postcss-cli
67 changes: 51 additions & 16 deletions src/webassets/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,10 +435,17 @@ def _get_debug(self):
def _set_cache(self, enable):
self._storage['cache'] = enable
def _get_cache(self):
cache = get_cache(self._storage['cache'], self)
if cache != self._storage['cache']:
self._storage['cache'] = cache
return cache
""" Instantiate the cache once and store it on the context.
If the underlying setting changes, reinstantiate the cache.
"""
if hasattr(self, '_cache'):
stored_setting, stored_cache = self._cache
if stored_setting == self._storage['cache']:
return stored_cache

new_cache = get_cache(self._storage['cache'], self)
self._cache = (self._storage['cache'], new_cache)
return new_cache
cache = property(_get_cache, _set_cache, doc=
"""Controls the behavior of the cache. The cache will speed up rebuilding
of your bundles, by caching individual filter results. This can be
Expand Down Expand Up @@ -480,10 +487,24 @@ def _get_auto_build(self):
def _set_manifest(self, manifest):
self._storage['manifest'] = manifest
def _get_manifest(self):
manifest = get_manifest(self._storage['manifest'], env=self)
if manifest != self._storage['manifest']:
self._storage['manifest'] = manifest
return manifest
""" Instantiate the manifest once and store it on the context.
If the underlying setting changes, reinstantiate the manifest.
"""
if hasattr(self, '_manifest'):
stored_setting, stored_manifest = self._manifest
if stored_setting == self._storage['manifest']:
return stored_manifest

try:
new_manifest = get_manifest(self._storage['manifest'], env=self)
except ValueError:
new_manifest = get_manifest(
# abspath() is important, or this will be considered
# relative to Environment.directory.
"file:%s" % os.path.abspath(self._storage['manifest']),
env=self)
self._manifest = (self._storage['manifest'], new_manifest)
return new_manifest
manifest = property(_get_manifest, _set_manifest, doc=
"""A manifest persists information about the versions bundles
are at.
Expand Down Expand Up @@ -530,10 +551,17 @@ def _get_manifest(self):
def _set_versions(self, versions):
self._storage['versions'] = versions
def _get_versions(self):
versions = get_versioner(self._storage['versions'])
if versions != self._storage['versions']:
self._storage['versions'] = versions
return versions
""" Instantiate the versioner once and store it on the context.
If the underlying setting changes, reinstantiate the versioner.
"""
if hasattr(self, '_versions'):
stored_setting, stored_versions = self._versions
if stored_setting == self._storage['versions']:
return stored_versions

new_versions = get_versioner(self._storage['versions'])
self._versions = (self._storage['versions'], new_versions)
return new_versions
versions = property(_get_versions, _set_versions, doc=
"""Defines what should be used as a Bundle ``version``.

Expand Down Expand Up @@ -563,10 +591,17 @@ def _get_versions(self):
def set_updater(self, updater):
self._storage['updater'] = updater
def get_updater(self):
updater = get_updater(self._storage['updater'])
if updater != self._storage['updater']:
self._storage['updater'] = updater
return updater
""" Instantiate the updater once and store it on the context.
If the underlying setting changes, reinstantiate the updater.
"""
if hasattr(self, '_updater'):
stored_setting, stored_updater = self._updater
if stored_setting == self._storage['updater']:
return stored_updater

new_updater = get_updater(self._storage['updater'])
self._updater = (self._storage['updater'], new_updater)
return new_updater
updater = property(get_updater, set_updater, doc=
"""Controls how the ``auto_build`` option should determine
whether a bundle needs to be rebuilt.
Expand Down
9 changes: 0 additions & 9 deletions src/webassets/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,7 @@ def __call__(self, bundles=None, output=None, directory=None, no_cache=None,
# TODO: Reset again (refactor commands to be classes)
self.environment.debug = False

# TODO: Oh how nice it would be to use the future options stack.
if manifest is not None:
try:
manifest = get_manifest(manifest, env=self.environment)
except ValueError:
manifest = get_manifest(
# abspath() is important, or this will be considered
# relative to Environment.directory.
"file:%s" % os.path.abspath(manifest),
env=self.environment)
self.environment.manifest = manifest

# Use output as a dict.
Expand Down
12 changes: 4 additions & 8 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ deps26 =
deps3 =
-r{toxinidir}/requirements-dev.pip

[testenv:py35]
basepython = python3.5
deps =
{[base]deps3}

[testenv:py33]
basepython = python3.3
Expand Down Expand Up @@ -68,11 +72,3 @@ deps =
pytest==2.5.2
mock==0.8.0
jsmin==2.0.2

[testenv:external-rjsmin]
basepython = python2.7
deps =
nose==1.0.0
pytest==2.5.2
mock==0.8.0
http://michael.elsdoerfer.name/rjsmin/rjsmin-1.0.1-webassets.tar.gz