From 2937b0bb45c3be41c928bdebc5ad672be8e09b93 Mon Sep 17 00:00:00 2001 From: jharshman Date: Tue, 9 Jan 2024 17:41:39 +0000 Subject: [PATCH] Port project to Python3.9 Resolves: TS-2847 --- .gitignore | 3 + assetman/S3UploadThread.py | 22 +++---- assetman/__init__.py | 4 +- assetman/compile.py | 45 +++++-------- assetman/compilers.py | 21 +++--- assetman/django_assetman/__init__.py | 1 - assetman/django_assetman/models.py | 3 - .../django_assetman/templatetags/__init__.py | 1 - .../templatetags/assetman_tags.py | 66 ------------------- assetman/managers.py | 10 +-- assetman/manifest.py | 20 +++--- assetman/parsers/base.py | 2 +- assetman/parsers/django_parser.py | 47 ------------- assetman/parsers/tornado_parser.py | 2 +- assetman/settings.py | 7 +- .../django_test_template.html | 19 ------ assetman/tests/django_test_settings.py | 36 ---------- assetman/tests/test_compiler.py | 29 ++++---- assetman/tests/test_django_templates.py | 62 ----------------- assetman/tests/test_manifest.py | 10 +-- assetman/tests/test_settings | 2 +- assetman/tests/test_settings.py | 13 ++-- assetman/tests/test_shunt.py | 4 -- assetman/tools.py | 24 ++++--- assetman/tornadoutils/__init__.py | 4 +- assetman/tornadoutils/static.py | 2 +- requirements.txt | 20 ++++++ scripts/invalidate_cloudfront_assets.py | 4 +- setup.py | 10 +-- 29 files changed, 130 insertions(+), 363 deletions(-) delete mode 100644 assetman/django_assetman/__init__.py delete mode 100644 assetman/django_assetman/models.py delete mode 100644 assetman/django_assetman/templatetags/__init__.py delete mode 100644 assetman/django_assetman/templatetags/assetman_tags.py delete mode 100644 assetman/parsers/django_parser.py delete mode 100644 assetman/tests/django_templates/django_test_template.html delete mode 100644 assetman/tests/django_test_settings.py delete mode 100644 assetman/tests/test_django_templates.py create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore index 82c7d1d..465c10a 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,6 @@ docs/build/ #compiled output *.pyc +.pytest_cache/ + +.venv/ diff --git a/assetman/S3UploadThread.py b/assetman/S3UploadThread.py index 910637f..af378a4 100755 --- a/assetman/S3UploadThread.py +++ b/assetman/S3UploadThread.py @@ -1,12 +1,12 @@ #!/bin/python -from __future__ import with_statement + import re import os import os.path import sys import threading import datetime -import Queue +import queue as Queue import mimetypes import logging import boto3 @@ -42,7 +42,7 @@ def run(self): file_name, file_path = self.queue.get() try: self.start_upload_file(file_name, file_path) - except Exception, e: + except Exception as e: logging.error('Error uploading %s: %s', file_name, e) self.errors.append((sys.exc_info(), self)) finally: @@ -52,8 +52,8 @@ def start_upload_file(self, file_name, file_path): """Starts the procecss of uploading a file to S3. Each file will be uploaded twice (once for CDN and once for our local CDN proxy). """ - assert isinstance(file_name, (str, unicode)) - assert isinstance(file_path, (str, unicode)) + assert isinstance(file_name, str) + assert isinstance(file_path, str) assert os.path.isfile(file_path) content_type, content_encoding = mimetypes.guess_type(file_name) @@ -88,7 +88,7 @@ def exists(self, obj): # https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.Client.head_object try: self.client.head_object(Bucket=obj.bucket_name, Key=obj.key) - except Exception, e: + except Exception as e: logging.error('got %s', e) return False return True @@ -143,7 +143,7 @@ def upload_assets_to_s3(manifest, settings, skip_s3_upload=False): # We know we want to upload each asset block (these correspond to the # assetman.include_* blocks in each template) - for depspec in manifest.blocks.itervalues(): + for depspec in manifest.blocks.values(): file_name = depspec['versioned_path'] file_path = make_output_path(settings['compiled_asset_root'], file_name) assert os.path.isfile(file_path), 'Missing compiled asset %s' % file_path @@ -154,7 +154,7 @@ def upload_assets_to_s3(manifest, settings, skip_s3_upload=False): # but we'll need to filter out other entries in the complete 'assets' # block of the manifest. should_skip = re.compile(r'\.(scss|less|css|js|html)$', re.I).search - for rel_path, depspec in manifest.assets.iteritems(): + for rel_path, depspec in manifest.assets.items(): if should_skip(rel_path): continue file_path = make_absolute_static_path(settings['static_dir'], rel_path) @@ -170,11 +170,11 @@ def upload_assets_to_s3(manifest, settings, skip_s3_upload=False): # Upload assets to S3 using 5 threads queue = Queue.Queue() errors = [] - for i in xrange(5): + for i in range(5): uploader = S3UploadThread(queue, errors, manifest, settings) uploader.setDaemon(True) uploader.start() - map(queue.put, to_upload) + list(map(queue.put, to_upload)) queue.join() if errors: raise Exception(errors) @@ -202,7 +202,7 @@ def replacer(match): replacement_link = prefix.rstrip('/') + '/' + versioned_path.lstrip('/') logging.info('replacing %s -> %s', path, replacement_link) return replacement_link - logging.warn('Missing path %s in manifest, using %s', path, match.group(0)) + logging.warning('Missing path %s in manifest, using %s', path, match.group(0)) return match.group(0) pattern = get_static_pattern(static_url_prefix) return re.sub(pattern, replacer, src) diff --git a/assetman/__init__.py b/assetman/__init__.py index 03f5dd5..cf9fec3 100644 --- a/assetman/__init__.py +++ b/assetman/__init__.py @@ -1,5 +1,5 @@ from assetman.manifest import Manifest # also update in setup.py -__version__ = "0.2.0" -version_info = (0, 2, 0) +__version__ = "0.3.0" +version_info = (0, 3, 0) diff --git a/assetman/compile.py b/assetman/compile.py index 832a299..e763dcd 100755 --- a/assetman/compile.py +++ b/assetman/compile.py @@ -1,6 +1,6 @@ #!/bin/python -from __future__ import with_statement + import os import re @@ -22,10 +22,6 @@ class NeedsCompilation(Exception): parser = OptionParser(description='Compiles assets for AssetMan') -parser.add_option( - '--django_template_dirs', type="string", action='append', - help='Directory to crawl looking for static assets to compile.') - parser.add_option( '--tornado_template_dirs', type="string", action='append', help='Directory to crawl looking for static assets to compile.') @@ -192,7 +188,7 @@ def iter_template_deps(static_dir, src_path, static_url_prefix): if os.path.isfile(dep_path): yield dep_path else: - logging.warn('Missing dep %s (src: %s)', dep_path, src_path) + logging.warning('Missing dep %s (src: %s)', dep_path, src_path) ############################################################################### @@ -208,9 +204,9 @@ def version_dependency(path, manifest): if manifest.assets[path]['version']: return manifest.assets[path]['version'] h = hashlib.md5() - h.update(get_file_hash(make_absolute_static_path(manifest.settings['static_dir'], path))) + h.update(get_file_hash(make_absolute_static_path(manifest.settings['static_dir'], path)).encode()) for dep_path in manifest.assets[path]['deps']: - h.update(version_dependency(dep_path, manifest)) + h.update(version_dependency(dep_path, manifest).encode()) version = h.hexdigest() _, ext = os.path.splitext(path) manifest.assets[path]['version'] = version @@ -298,7 +294,7 @@ def iter_static_deps(static_dir, src_path, static_url_prefix): if os.path.isfile(dep_path): yield dep_path else: - logging.warn('Missing dep %s (src: %s)', dep_path, src_path) + logging.warning('Missing dep %s (src: %s)', dep_path, src_path) def _build_manifest_helper(static_dir, src_paths, static_url_prefix, manifest): @@ -315,17 +311,15 @@ def _build_manifest_helper(static_dir, src_paths, static_url_prefix, manifest): _build_manifest_helper(static_dir, [dep_path], static_url_prefix, manifest) -def build_manifest(tornado_paths, django_paths, settings): +def build_manifest(tornado_paths, settings): """Recursively builds the dependency manifest for the given list of source paths. """ assert isinstance(tornado_paths, (list, tuple)) - assert isinstance(django_paths, (list, tuple)) - paths = list(set(tornado_paths).union(set(django_paths))) + paths = list(set(tornado_paths)) # First, parse each template to build a list of AssetCompiler instances path_infos = [(x, 'tornado_template') for x in tornado_paths] - path_infos += [(x, 'django_template') for x in django_paths] compilers = build_compilers(path_infos, settings) # Add each AssetCompiler's paths to our set of paths to search for deps @@ -333,7 +327,7 @@ def build_manifest(tornado_paths, django_paths, settings): for compiler in compilers: new_paths = compiler.get_paths() if settings.get('verbose'): - print compiler, new_paths + print(compiler, new_paths) paths.update(new_paths) paths = list(paths) @@ -365,7 +359,6 @@ def _create_settings(options): static_dir=options.static_dir, static_url_prefix=options.static_url_path, tornado_template_dirs=options.tornado_template_dirs, - django_template_dirs=options.django_template_dirs, template_extension=options.template_ext, test_needs_compile=options.test_needs_compile, skip_s3_upload=options.skip_s3_upload, @@ -386,7 +379,7 @@ def run(settings): logging.info('Creating output directory: %s', settings['compiled_asset_root']) os.makedirs(settings['compiled_asset_root']) - for d in settings['tornado_template_dirs'] + settings['django_template_dirs']: + for d in settings['tornado_template_dirs']: if not os.path.isdir(d): raise Exception('Template directory not found: %r', d) @@ -395,22 +388,20 @@ def run(settings): # Find all the templates we need to parse tornado_paths = list(iter_template_paths(settings['tornado_template_dirs'], settings['template_extension'])) - django_paths = list(iter_template_paths(settings['django_template_dirs'], settings['template_extension'])) - logging.debug('found %d tornado and %d django template paths', len(tornado_paths), len(django_paths)) - if not tornado_paths and not django_paths: - logging.warn("No templates found") + if not tornado_paths: + logging.warning("No templates found") # Load the current manifest and generate a new one cached_manifest = Manifest(settings).load() try: - current_manifest, compilers = build_manifest(tornado_paths, django_paths, settings) - except ParseError, e: + current_manifest, compilers = build_manifest(tornado_paths, settings) + except ParseError as e: src_path, msg = e.args logging.error('Error parsing template %s', src_path) logging.error(msg) raise Exception - except DependencyError, e: + except DependencyError as e: src_path, missing_deps = e.args logging.error('Dependency error in source %s!', src_path) logging.error('Missing paths: %s', missing_deps) @@ -421,7 +412,7 @@ def run(settings): # compiler's source path figures into the dependency tracking. But we only # need to actually compile each block once. logging.debug('Found %d assetman block compilers', len(compilers)) - compilers = dict((c.get_hash(), c) for c in compilers).values() + compilers = list(dict((c.get_hash(), c) for c in compilers).values()) logging.debug('%d unique assetman block compilers', len(compilers)) # update the manifest on each our compilers to reflect the new manifest, @@ -436,7 +427,7 @@ def needs_compile(compiler): if settings['force_recompile']: to_compile = compilers else: - to_compile = filter(needs_compile, compilers) + to_compile = list(filter(needs_compile, compilers)) if to_compile or cached_manifest.needs_recompile(current_manifest): # If we're only testing whether a compile is needed, we're done @@ -447,8 +438,8 @@ def needs_compile(compiler): try: # See note above about bug in pool.map w/r/t KeyboardInterrupt. _compile_worker = CompileWorker(settings.get('skip_inline_images', False), current_manifest) - pool.map_async(_compile_worker, to_compile).get(1e100) - except CompileError, e: + pool.map_async(_compile_worker, to_compile).get(1e9) # previously set to 1e100 which caused overflow of C _PyTime_t_ + except CompileError as e: cmd, msg = e.args logging.error('Compile error!') logging.error('Command: %s', ' '.join(cmd)) diff --git a/assetman/compilers.py b/assetman/compilers.py index d842e23..52e2f96 100644 --- a/assetman/compilers.py +++ b/assetman/compilers.py @@ -1,4 +1,4 @@ -from __future__ import absolute_import, with_statement + import base64 from collections import defaultdict @@ -24,13 +24,14 @@ def run_proc(cmd, stdin=None): popen_args = dict(stdout=subprocess.PIPE, stderr=subprocess.PIPE) if stdin is not None: popen_args['stdin'] = subprocess.PIPE + stdin = stdin.encode() proc = subprocess.Popen(cmd, **popen_args) out, err = proc.communicate(input=stdin) if proc.returncode != 0: raise CompileError(cmd, err) elif err: - logging.warn('%s stderr:\n%s', cmd[0], err) - return out + logging.warning('%s stderr:\n%s', cmd[0], err) + return out.decode() class CompileError(Exception): """Error encountered while compiling assets.""" @@ -88,16 +89,16 @@ def needs_compile(self, cached_manifest, current_manifest): if cached_manifest.blocks[name_hash]['version'] == content_hash: compiled_path = self.get_compiled_path() if not os.path.exists(compiled_path): - logging.warn('Missing compiled asset %s from %s', + logging.warning('Missing compiled asset %s from %s', compiled_path, self) return True return False else: - logging.warn('Contents of %s changed', self) + logging.warning('Contents of %s changed', self) else: compiled_path = self.get_compiled_path() if not os.path.exists(compiled_path): - logging.warn('New/unknown hash %s from %s', name_hash, self) + logging.warning('New/unknown hash %s from %s', name_hash, self) else: logging.info('new hash %s from %s but already exists on file %s', name_hash, self, compiled_path) return False @@ -109,12 +110,12 @@ def get_current_content_hash(self, manifest): for path in self.get_paths(): relative_path = make_relative_static_path(self.settings['static_dir'], path) assert relative_path in manifest.assets, relative_path - h.update(manifest.assets[relative_path]['version']) + h.update(manifest.assets[relative_path]['version'].encode()) return h.hexdigest() def get_paths(self): """Returns a list of absolute paths to the assets contained in this manager.""" - paths = map(functools.partial(make_absolute_static_path, self.settings['static_dir']), self.rel_urls) + paths = list(map(functools.partial(make_absolute_static_path, self.settings['static_dir']), self.rel_urls)) try: assert all(map(os.path.isfile, paths)) except AssertionError: @@ -222,9 +223,9 @@ def replacer(match): result = re.sub(pattern, replacer, css_src) - for url, count in seen_assets.iteritems(): + for url, count in seen_assets.items(): if count > 1: - logging.warn('inline asset duplicated %dx: %s', count, url) + logging.warning('inline asset duplicated %dx: %s', count, url) return result diff --git a/assetman/django_assetman/__init__.py b/assetman/django_assetman/__init__.py deleted file mode 100644 index 8b13789..0000000 --- a/assetman/django_assetman/__init__.py +++ /dev/null @@ -1 +0,0 @@ - diff --git a/assetman/django_assetman/models.py b/assetman/django_assetman/models.py deleted file mode 100644 index 2f17b6c..0000000 --- a/assetman/django_assetman/models.py +++ /dev/null @@ -1,3 +0,0 @@ -# Django insists that templatetags be loaded from a Django app, -# which requires a models.py, even if empty. - diff --git a/assetman/django_assetman/templatetags/__init__.py b/assetman/django_assetman/templatetags/__init__.py deleted file mode 100644 index 8b13789..0000000 --- a/assetman/django_assetman/templatetags/__init__.py +++ /dev/null @@ -1 +0,0 @@ - diff --git a/assetman/django_assetman/templatetags/assetman_tags.py b/assetman/django_assetman/templatetags/assetman_tags.py deleted file mode 100644 index 75a8fe6..0000000 --- a/assetman/django_assetman/templatetags/assetman_tags.py +++ /dev/null @@ -1,66 +0,0 @@ -from django import template -from django.conf import settings - -register = template.Library() - - -class AssetmanNode(template.Node): - """ - A template node that treats text content as paths to feed to asssetman - compilers. - """ - - def __init__(self, asset_type, nodelist, settings): - self.asset_type = asset_type - for node in nodelist: - if not isinstance(node, template.TextNode): - raise template.TemplateSyntaxError("only text allowed inside assetman tags") - self.nodelist = nodelist - self.settings = settings - - def render(self, context): - # Avoid circular import. TODO: code smell, re-organize. - from assetman.parsers.django_parser import get_compiler_class - compiler = get_compiler_class(self)(self.get_all_text(), - settings=self.settings) - return compiler.render() - - def get_all_text(self): - return '\n'.join(child.s.strip() for child in self.get_nodes_by_type(template.TextNode)) - - - -@register.tag(name="assetman") -def do_assetman(parser, token): - """ - Syntax:: - - {% load assetman_tags %} - {% assetman include_js %} - path/to/asset.js - another/path/to/another_asset.js - {% endassetman %} - - {% assetman include_css %} - path/to/asset.css - {% endassetman %} - - {% assetman include_sass %} - path/to/asset.less - {% endassetman %} - - {% assetman include_less %} - path/to/asset.less - {% endassetman %} - - """ - args = token.split_contents() - allowed_args = ('include_js', 'include_css', 'include_sass', 'include_less') - if not (len(args) == 2 and args[1] in allowed_args): - raise template.TemplateSyntaxError( - 'assetman requires exactly 2 args and second must be one of %s' - % allowed_args) - - nodelist = parser.parse(('endassetman',)) - parser.delete_first_token() - return AssetmanNode(args[1], nodelist, settings.ASSETMAN_SETTINGS) diff --git a/assetman/managers.py b/assetman/managers.py index bca0b3b..c9f8bc1 100644 --- a/assetman/managers.py +++ b/assetman/managers.py @@ -1,4 +1,4 @@ -from __future__ import absolute_import, with_statement + import os import logging @@ -46,7 +46,7 @@ def __init__(self, rel_url_text, local=False, include_tag=True, src_path=None, s Any extra kwargs will be interpreted as extra HTML params to include on the rendered element. """ - self.rel_urls = filter(None, _utf8(rel_url_text).split()) + self.rel_urls = [_f for _f in _utf8(rel_url_text).split() if _f] self.local = local self.include_tag = include_tag self.src_path = src_path @@ -71,7 +71,7 @@ def get_hash(self): """Gets the md5 hash for the URLs in this block of assets, which will be used to refer to the compiled assets in production. """ - return hashlib.md5('\n'.join(self.rel_urls)).hexdigest() + return hashlib.md5('\n'.join(self.rel_urls).encode()).hexdigest() def get_ext(self): """Returns the file extension (without leading period) to use for the @@ -101,7 +101,7 @@ def render_attrs(self): leading space. """ attrs = ' '.join('%s=%r' % (attr, _utf8(val)) - for attr, val in self.attrs.iteritems()) + for attr, val in self.attrs.items()) return ' ' + attrs if attrs else '' def render_asset(self, url): @@ -123,7 +123,7 @@ def render(self): """ try: if self.settings['enable_static_compilation']: - urls = map(self.make_asset_url, self.rel_urls) + urls = list(map(self.make_asset_url, self.rel_urls)) return '\n'.join(map(self.render_asset, urls)) else: compiled_name = self.get_compiled_name() diff --git a/assetman/manifest.py b/assetman/manifest.py index 5bc0987..fea80b0 100644 --- a/assetman/manifest.py +++ b/assetman/manifest.py @@ -1,7 +1,7 @@ -from __future__ import absolute_import, with_statement + import os -import simplejson as json +import json import logging from assetman.settings import Settings @@ -51,8 +51,8 @@ def load(self, compiled_asset_path=None): self._manifest = json.load(open(filename)) assert isinstance(self.assets, dict) assert isinstance(self.blocks, dict) - except (AssertionError, KeyError, IOError, json.JSONDecodeError), e: - logging.warn('error opening manifest file: %s', e) + except (AssertionError, KeyError, IOError, json.JSONDecodeError) as e: + logging.warning('error opening manifest file: %s', e) self._manifest = self.make_empty_manifest() return self @@ -76,12 +76,12 @@ def normalize(self): when the manifest is built) and then by ensuring that every dependency has its own entry and version in the top level of the manifest. """ - for parent, depspec in self.assets.iteritems(): + for parent, depspec in self.assets.items(): depspec['deps'] = list(depspec['deps']) for dep in depspec['deps']: assert dep in self.assets, (parent, dep) assert depspec['version'], (parent, dep) - for name_hash, depspec in self.blocks.iteritems(): + for name_hash, depspec in self.blocks.items(): assert depspec['version'], name_hash def union(self, newer_manifest): @@ -89,8 +89,8 @@ def union(self, newer_manifest): # generations ago an entry was created def age(entry): entry['age'] = entry.get('age', 0) + 1 - map(age, self.blocks.values()) - map(age, self.assets.values()) + list(map(age, list(self.blocks.values()))) + list(map(age, list(self.assets.values()))) self.blocks.update(newer_manifest.blocks) self.assets.update(newer_manifest.assets) @@ -102,11 +102,11 @@ def assets_in_sync(asset): logging.info('new asset %s (not in current manifest)', asset) return False if self.assets[asset]['version'] != newer_manifest.assets[asset]['version']: - logging.warn('Static asset %s version mismatch', asset) + logging.warning('Static asset %s version mismatch', asset) return False return True assets_out_of_sync = not all(map(assets_in_sync, newer_manifest.assets)) if assets_out_of_sync: - logging.warn('Static assets out of sync') + logging.warning('Static assets out of sync') return assets_out_of_sync diff --git a/assetman/parsers/base.py b/assetman/parsers/base.py index 20f119f..55be297 100644 --- a/assetman/parsers/base.py +++ b/assetman/parsers/base.py @@ -1,4 +1,4 @@ -from __future__ import absolute_import, with_statement + from assetman.settings import Settings from assetman.compilers import JSCompiler, LessCompiler, CSSCompiler, SassCompiler diff --git a/assetman/parsers/django_parser.py b/assetman/parsers/django_parser.py deleted file mode 100644 index ef8be8b..0000000 --- a/assetman/parsers/django_parser.py +++ /dev/null @@ -1,47 +0,0 @@ -from __future__ import absolute_import, with_statement - -import django.template -import django.template.loader -from assetman.django_assetman.templatetags.assetman_tags import AssetmanNode -from assetman.parsers import base -import logging -from django.conf import settings - - -def get_compiler_class(node): - return base.compiler_map[node.asset_type] - -class DjangoParser(base.TemplateParser): - """ Template parser for parsing and handling django templates """ - - def load_template(self, path): - """ - Loads a template from a full file path. - """ - logging.info('django template path %s (templates %s)', path, settings.TEMPLATE_DIRS) - for p in settings.TEMPLATE_DIRS: - if path.startswith(p): - logging.debug('scoping path to django template %s -> %s', path, path[len(p)+1]) - path = path[len(p)+1:] - break - self.template = django.template.loader.get_template(path) - self.path = path - - def get_compilers(self): - """ - Finds any {% assetman foo %} blocks in the given compiled - Template object and yields insantiated AssetCompiler instances for each - block. - """ - logging.debug("djangoparser.get_compilers %s", self.path) - for node in self.template.nodelist.get_nodes_by_type(AssetmanNode): - compiler_cls = get_compiler_class(node) - logging.debug('node %r %r', node, compiler_cls) - if self.settings.get('verbose'): - print self.path, node, compiler_cls, node.get_all_text() - yield compiler_cls(node.get_all_text(), - self.template_path, - src_path=self.template_path, - settings=self.settings) - - diff --git a/assetman/parsers/tornado_parser.py b/assetman/parsers/tornado_parser.py index 277da80..fafcfe0 100644 --- a/assetman/parsers/tornado_parser.py +++ b/assetman/parsers/tornado_parser.py @@ -1,4 +1,4 @@ -from __future__ import absolute_import, with_statement + import os import tornado.template diff --git a/assetman/settings.py b/assetman/settings.py index 23cd58c..3107eeb 100644 --- a/assetman/settings.py +++ b/assetman/settings.py @@ -1,10 +1,7 @@ -from __future__ import absolute_import, with_statement + import os -try: - import json -except ImportError: - import simplejson as json # pyflakes.ignore +import json example_settings = { # Assetman needs to be able to point at assets to be served by us and by a diff --git a/assetman/tests/django_templates/django_test_template.html b/assetman/tests/django_templates/django_test_template.html deleted file mode 100644 index 790e7fd..0000000 --- a/assetman/tests/django_templates/django_test_template.html +++ /dev/null @@ -1,19 +0,0 @@ -{% load assetman_tags %} - - - {% assetman include_css %} - test.css - {% endassetman %} - {% assetman include_less %} - test.less - {% endassetman %} - - -
-

This is only a test

-
- {% assetman include_js %} - test.js - {% endassetman %} - - diff --git a/assetman/tests/django_test_settings.py b/assetman/tests/django_test_settings.py deleted file mode 100644 index 7861b0f..0000000 --- a/assetman/tests/django_test_settings.py +++ /dev/null @@ -1,36 +0,0 @@ -# All defaults. -import os - -HERE = os.path.abspath(os.path.dirname(__file__)) - -INSTALLED_APPS = [ - 'assetman.django_assetman', -] - -TEMPLATE_DIRS = [ - os.path.join(HERE,"django_templates") -] - -ASSETMAN_SETTINGS = { - 'enable_static_compilation': True, - 'static_url_prefix': 'STATIC', - 'local_cdn_url_prefix': 'CDN', - 'compiled_asset_root': '/tmp', -} - -# Logging configuration. -# See http://docs.djangoproject.com/en/dev/topics/logging for -# more details on how to customize your logging configuration. - -LOGGING = { - 'version': 1, - 'disable_existing_loggers': False, - 'loggers': { - 'django': { - 'handlers': [], - 'level': 'DEBUG', - 'propagate': True, - }, - }, -} - diff --git a/assetman/tests/test_compiler.py b/assetman/tests/test_compiler.py index 83a77dc..fb1d7de 100644 --- a/assetman/tests/test_compiler.py +++ b/assetman/tests/test_compiler.py @@ -1,5 +1,5 @@ -from __future__ import with_statement -import test_shunt # pyflakes.ignore + +from . import test_shunt # pyflakes.ignore import contextlib @@ -16,21 +16,20 @@ def get_settings(**opts): logging.info('temp dir %s', COMPILED_ASSET_DIR) assetman_settings = Settings( compiled_asset_root=COMPILED_ASSET_DIR, - static_dir='static_dir', - static_url_prefix='/static/', - tornado_template_dirs=['tornado_templates'], - django_template_dirs=[], - # django_template_dirs=['django_templates'], + static_dir="./assetman/tests/static_dir", + static_url_prefix="/static/", + tornado_template_dirs=["./assetman/tests/tornado_templates"], template_extension="html", - test_needs_compile=opts.get('test_needs_compile', True), + test_needs_compile=opts.get("test_needs_compile", True), 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/bin/lessc'), + 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/ aws_username=None, + java_bin="/usr/bin/java", ) return assetman_settings @@ -50,8 +49,8 @@ def run_compiler(test_needs_compile=True, **opts): return manifest def test_needs_compile(): - main_files = ['test.css', 'test.less', 'test.js'] - dependency_files = ['dependency.png'] + main_files = ["test.css", "test.less", "test.js"] + dependency_files = ["dependency.png"] try: manifest = run_compiler() raise Exception("should need compile") @@ -92,7 +91,7 @@ def temporarily_alter_contents(path, data): contents = open(path).read() open(path, 'a').write(data) yield - print 'undoing alter contents! %d' % len(contents) + print('undoing alter contents! %d' % len(contents)) open(path, 'w').write(contents) # diff --git a/assetman/tests/test_django_templates.py b/assetman/tests/test_django_templates.py deleted file mode 100644 index d453544..0000000 --- a/assetman/tests/test_django_templates.py +++ /dev/null @@ -1,62 +0,0 @@ -import unittest -import test_shunt # pyflakes.ignore - -import django.template -from assetman.compilers import JSCompiler, LessCompiler, CSSCompiler -from assetman.parsers.django_parser import DjangoParser -import assetman.tools -from assetman.settings import Settings - -class TestDjangoTemplateParser(unittest.TestCase): - - TEST_TEMPLATE_PATH = 'django_test_template.html' - - def test_get_parser_returns_django_template_parser(self): - settings = Settings(static_dir="assetman/tests/") - parser = assetman.tools.get_parser(self.TEST_TEMPLATE_PATH, 'django_template', settings) - assert parser is not None - - def test_loads_template_from_path(self): - parser = DjangoParser(self.TEST_TEMPLATE_PATH) - assert parser.template - - def test_returns_asset_blocks_from_template(self): - parser = DjangoParser(self.TEST_TEMPLATE_PATH) - compilers = list(parser.get_compilers()) - - assert compilers - - 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 - - def test_template_rendering_without_cdn(self): - parser = DjangoParser(self.TEST_TEMPLATE_PATH) - template = parser.template - context = django.template.context.Context({}) - result = template.render(context) - self.assertIn('