Skip to content

Commit 05f6d5a

Browse files
committedSep 3, 2018
Fix #3074 — get rid of the webassets library
Signed-off-by: Chris Warrick <kwpolska@gmail.com>
1 parent 559f2c8 commit 05f6d5a

9 files changed

+30
-48
lines changed
 

‎CHANGES.txt

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ Features
2121
Bugfixes
2222
--------
2323

24+
Removed features
25+
----------------
26+
27+
* The ``webassets`` library is no longer required, we now manually
28+
bundle files (Issue #3074)
29+
2430
New in v8.0.0b3 (changes since Beta 2)
2531
======================================
2632

‎docs/creating-a-theme.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ Doing the same for layout-reverse, sidebar-overlay and the rest is left as an ex
813813
Bundles
814814
-------
815815

816-
If you have ``webassets`` installed and the ``USE_BUNDLES`` option set to True,
816+
If the ``USE_BUNDLES`` option set to True,
817817
Nikola can put several CSS or JS files together in a larger file, which can
818818
makes site load faster for some deployments. To do this, your theme needs
819819
a ``bundles`` file. The file format is a modified

‎docs/manual.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -2342,7 +2342,7 @@ different ones, or about other web servers, please share!
23422342
4. Optionally you can create static compressed copies and save some CPU on your server
23432343
with the GZIP_FILES option in Nikola.
23442344

2345-
5. The webassets Nikola plugin can drastically decrease the number of CSS and JS files your site fetches.
2345+
5. The bundles Nikola plugin can drastically decrease the number of CSS and JS files your site fetches.
23462346

23472347
6. Through the filters feature, you can run your files through arbitrary commands, so that images
23482348
are recompressed, JavaScript is minimized, etc.

‎docs/theming.rst

+2-3
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ parent, engine
7474

7575
bundles
7676
A `config <https://docs.python.org/3/library/configparser.html>`_ file
77-
containing a list of files to be turned into bundles using WebAssets. For
78-
example:
77+
containing a list of files to be turned into bundles. For example:
7978

8079
.. code:: ini
8180
@@ -93,7 +92,7 @@ bundles
9392
This makes the page much more efficient because it avoids multiple connections to the server,
9493
at the cost of some extra difficult debugging.
9594

96-
WebAssets supports bundling CSS and JS files.
95+
Bundling applies to CSS and JS files.
9796

9897
Templates should use either the bundle or the individual files based on the ``use_bundles``
9998
variable, which in turn is set by the ``USE_BUNDLES`` option.

‎nikola/conf.py.in

+3-3
Original file line numberDiff line numberDiff line change
@@ -1191,9 +1191,9 @@ MARKDOWN_EXTENSIONS = ['markdown.extensions.fenced_code', 'markdown.extensions.c
11911191
# # 'creator': '@username', # Username for the content creator / author.
11921192
# }
11931193

1194-
# If webassets is installed, bundle JS and CSS into single files to make
1195-
# site loading faster in a HTTP/1.1 environment but is not recommended for
1196-
# HTTP/2.0 when caching is used. Defaults to True.
1194+
# Bundle JS and CSS into single files to make site loading faster in a HTTP/1.1
1195+
# environment but is not recommended for HTTP/2.0 when caching is used.
1196+
# Defaults to True.
11971197
# USE_BUNDLES = True
11981198

11991199
# Plugins you don't want to use. Be careful :-)

‎nikola/plugins/task/bundles.plugin

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module = bundles
66
author = Roberto Alsina
77
version = 1.0
88
website = https://getnikola.com/
9-
description = Theme bundles using WebAssets
9+
description = Bundle assets
1010

1111
[Nikola]
1212
PluginCategory = Task

‎nikola/plugins/task/bundles.py

+16-37
Original file line numberDiff line numberDiff line change
@@ -24,39 +24,26 @@
2424
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
2525
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2626

27-
"""Bundle assets using WebAssets."""
27+
"""Bundle assets."""
2828

2929

3030
import configparser
3131
import io
3232
import itertools
3333
import os
34-
35-
try:
36-
import webassets
37-
except ImportError:
38-
webassets = None # NOQA
34+
import shutil
3935

4036
from nikola.plugin_categories import LateTask
4137
from nikola import utils
4238

4339

4440
class BuildBundles(LateTask):
45-
"""Bundle assets using WebAssets."""
41+
"""Bundle assets."""
4642

4743
name = "create_bundles"
4844

49-
def set_site(self, site):
50-
"""Set Nikola site."""
51-
super(BuildBundles, self).set_site(site)
52-
if webassets is None and site.configured and site.config['USE_BUNDLES']:
53-
utils.req_missing(['webassets'], 'USE_BUNDLES', optional=True)
54-
self.logger.warn('Setting USE_BUNDLES to False.')
55-
site.config['USE_BUNDLES'] = False
56-
site._GLOBAL_CONTEXT['use_bundles'] = False
57-
5845
def gen_tasks(self):
59-
"""Bundle assets using WebAssets."""
46+
"""Bundle assets."""
6047
kw = {
6148
'filters': self.site.config['FILTERS'],
6249
'output_folder': self.site.config['OUTPUT_FOLDER'],
@@ -70,28 +57,20 @@ def gen_tasks(self):
7057
def build_bundle(output, inputs):
7158
out_dir = os.path.join(kw['output_folder'],
7259
os.path.dirname(output))
73-
inputs = [os.path.relpath(i, out_dir) for i in inputs if os.path.isfile(i)]
74-
cache_dir = os.path.join(kw['cache_folder'], 'webassets')
75-
utils.makedirs(cache_dir)
76-
env = webassets.Environment(out_dir, os.path.dirname(output),
77-
cache=cache_dir)
78-
if inputs:
79-
bundle = webassets.Bundle(*inputs, output=os.path.basename(output))
80-
env.register(output, bundle)
81-
# This generates the file
82-
try:
83-
env[output].build(force=True)
84-
except Exception as e:
85-
self.logger.error("Failed to build bundles.")
86-
self.logger.exception(e)
87-
self.logger.notice("Try running ``nikola clean`` and building again.")
88-
else:
89-
with open(os.path.join(out_dir, os.path.basename(output)), 'wb+'):
90-
pass # Create empty file
60+
inputs = [
61+
os.path.join(
62+
out_dir,
63+
os.path.relpath(i, out_dir))
64+
for i in inputs if os.path.isfile(i)
65+
]
66+
with open(os.path.join(out_dir, os.path.basename(output)), 'wb+') as out_fh:
67+
for i in inputs:
68+
with open(i, 'rb') as in_fh:
69+
shutil.copyfileobj(in_fh, out_fh)
9170

9271
yield self.group_task()
93-
if (webassets is not None and self.site.config['USE_BUNDLES'] is not
94-
False):
72+
73+
if self.site.config['USE_BUNDLES']:
9574
for name, _files in kw['theme_bundles'].items():
9675
output_path = os.path.join(kw['output_folder'], name)
9776
dname = os.path.dirname(name)

‎requirements-extras.txt

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ micawber>=0.3.0
66
pygal>=2.0.0
77
typogrify>=2.0.4
88
phpserialize>=1.3
9-
webassets>=0.10.1
109
notebook>=4.0.0
1110
ipykernel>=4.0.0
1211
ghp-import2>=1.0.0

‎snapcraft.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ parts:
2828
- pygal>=2.0.0
2929
- typogrify>=2.0.4
3030
- phpserialize>=1.3
31-
- webassets>=0.10.1
3231
- ghp-import2>=1.0.0
3332
- ws4py==0.3.5
3433
- watchdog==0.8.3

0 commit comments

Comments
 (0)
Please sign in to comment.