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

Bugfix: compiler asset type fix #27

Merged
merged 4 commits into from
Jul 29, 2024
Merged
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
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ jobs:
python -m pip install --upgrade pip
python -m pip install pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
sudo apt-get update
sudo apt-get install -y wget minify
wget "https://dl.google.com/closure-compiler/compiler-20150315.zip"
unzip compiler-20150315.zip compiler.jar
- name: Test with pytest
run: |
pytest
Expand Down
5 changes: 3 additions & 2 deletions assetman/compilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import re

import assetman.managers
from assetman.tools import make_absolute_static_path, make_relative_static_path, get_static_pattern, make_output_path
from assetman.tools import make_absolute_static_path, make_relative_static_path, get_static_pattern, make_output_path, _unicode

def run_proc(cmd, stdin=None):
"""Runs the given cmd as a subprocess. If the exit code is non-zero, calls
Expand Down Expand Up @@ -200,7 +200,8 @@ def replacer(match):
logging.debug('Not inlining %s (%.2fKB)', path, os.stat(path).st_size / KB)
return match.group(0)
else:
encoded = base64.b64encode(open(path, 'rb').read())
# data_uri format requires strings instead of bytes
encoded = _unicode(base64.b64encode(open(path, 'rb').read()))
mime_type, _ = mimetypes.guess_type(path)
if not mime_type and path.endswith('.otf'):
mime_type = 'application/octet-stream'
Expand Down
Empty file.
14 changes: 7 additions & 7 deletions assetman/tests/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ def get_settings(**opts):
skip_s3_upload=True,
force_recompile=False,
skip_inline_images=True,
closure_compiler=opts.get("closure_compiler", "/bitly/local/bin/closure-compiler.jar"),
minify_compressor_path=opts.get("minify_compressor_path", "/bitly/local/bin/minify"),
sass_compiler=opts.get("sass_compiler", "/bitly/local/bin/sass"),
lessc_path=opts.get("lessc_path", "/bitly/local/hamburger/node_modules/.bin/lessc"), # lessc is included as a node module in hamburger. Does not exist in /bitly/local/bin/
closure_compiler=opts.get("closure_compiler", "compiler.jar"),
minify_compressor_path=opts.get("minify_compressor_path", "/usr/bin/minify"),
sass_compiler=opts.get("sass_compiler", None),
lessc_path=opts.get("lessc_path", None), # less is unused
Comment on lines +29 to +30
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None is the default value from .get and can be removed.

aws_username=None,
java_bin="/usr/bin/java",
)
Expand All @@ -43,13 +43,12 @@ def run_compiler(test_needs_compile=True, **opts):
always cause skip_upload to be True, so that we don't upload test assets
to our CDN.
"""

manifest = assetman.compile.run(get_settings(test_needs_compile=test_needs_compile, **opts))
logging.debug(manifest)
return manifest

def test_needs_compile():
main_files = ["test.css", "test.less", "test.js"]
main_files = ["test.css", "test.js"]
dependency_files = ["dependency.png"]
try:
manifest = run_compiler()
Expand Down Expand Up @@ -79,7 +78,7 @@ def test_needs_compile():

files_to_upload = upload_assets_to_s3(manifest, get_settings(), skip_s3_upload=True)
logging.debug(files_to_upload)
assert len(files_to_upload) == 4
assert len(files_to_upload) == 3


@contextlib.contextmanager
Expand All @@ -88,6 +87,7 @@ def temporarily_alter_contents(path, data):
before restoring the original contents when the with block is exited.
"""
assert isinstance(data, str)
path = 'assetman/tests/%s' % path
contents = open(path).read()
open(path, 'a').write(data)
yield
Expand Down
2 changes: 1 addition & 1 deletion assetman/tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ def test_settings_can_load_from_file(self):
settings_stub = {
'testkey1': "testvalue1",
'testkey2': "testvalue2",
"lessc_path" : "asdf",
"sass_compiler": "asdf",
"lessc_path": None,
"minify_compressor_path": "asdf",
"closure_compiler": "asdf",
"java_bin": "asdf"
Expand Down
3 changes: 1 addition & 2 deletions assetman/tests/test_tornado_templates.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest

from assetman.compilers import JSCompiler, LessCompiler, CSSCompiler
from assetman.compilers import JSCompiler, CSSCompiler
from assetman.parsers.tornado_parser import TornadoParser
import assetman.tools
from assetman.settings import Settings
Expand Down Expand Up @@ -30,7 +30,6 @@ def test_returns_asset_blocks_from_template(self):
compiler_types = [type(t) for t in compilers]

assert JSCompiler in compiler_types, compilers
assert LessCompiler in compiler_types, compilers
assert CSSCompiler in compiler_types, compilers

if __name__ == "__main__":
Expand Down
3 changes: 0 additions & 3 deletions assetman/tests/tornado_templates/tornado_test_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
{% apply assetman.include_css %}
test.css
{% end %}
{% apply assetman.include_less %}
test.less
{% end %}
</head>
<body>
<div>
Expand Down
3 changes: 2 additions & 1 deletion assetman/tornadoutils/static.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ def do_compile(self, abs_path, url_path):
env = {
'PATH': os.environ.get('PATH', '')
}
return self.run_proc(cmd, env=env)
out = self.run_proc(cmd, env=env)
return out


class SassCompilerHandler(CompilingStaticHandler):
Expand Down
Loading