Andriy Kornatskyy avatar Andriy Kornatskyy committed 2cba00c

Introduced make target qa; fixed issues reported.

Comments (0)

Files changed (8)

-.SILENT: clean env po doctest-cover test doc release upload
-.PHONY: clean env po doctest-cover test doc release upload
+.SILENT: clean env po doctest-cover qa test doc release upload
+.PHONY: clean env po doctest-cover qa test doc release upload
 
 VERSION=2.7
 PYPI=http://pypi.python.org/simple
 		rotate --match=$(VERSION).egg --keep=1 --dist-dir=$(DIST_DIR) \
 		upload;
 
+qa:
+	if [ "$$(echo $(VERSION) | sed 's/\.//')" -eq 27 ]; then \
+		flake8 --max-complexity 10 demos doc src setup.py && \
+		pep8 demos doc src setup.py ; \
+	fi
+
 test:
 	$(PYTEST) -q -x --pep8 --doctest-modules \
 		src/wheezy/template

demos/bigtable/bigtable.py

 s = PY3 and str or unicode
 
 ctx = {
-    'table': [dict(a=1,b=2,c=3,d=4,e=5,f=6,g=7,h=8,i=9,j=10)
-          for x in range(1000)]
+    'table': [dict(a=1, b=2, c=3, d=4, e=5, f=6, g=7, h=8, i=9, j=10)
+              for x in range(1000)]
 }
 
 
 
 if PY3:
     def test_list_append():
-        b = []; w = b.append
+        b = []
+        w = b.append
         table = ctx['table']
         w('<table>\n')
         for row in table:
         w('</table>')
         return ''.join(b)
 else:
-    def test_list_append():
-        b = []; w = b.append
+    def test_list_append():  # noqa
+        b = []
+        w = b.append
         table = ctx['table']
         w(u'<table>\n')
         for row in table:
 
 if PY3:
     def test_list_extend():
-        b = []; e = b.extend
+        b = []
+        e = b.extend
         table = ctx['table']
         e(('<table>\n',))
         for row in table:
         e(('</table>',))
         return ''.join(b)
 else:
-    def test_list_extend():
-        b = []; e = b.extend
+    def test_list_extend():  # noqa
+        b = []
+        e = b.extend
         table = ctx['table']
         e((u'<table>\n',))
         for row in table:
     {% endfor %}
 </table>
 """))
+
     def test_jinja2():
         return jinja2_template.render(ctx)
 
     {% end %}
 </table>
 """))
+
     def test_tornado():
         return tornado_template.generate(**ctx).decode('utf8')
 
     % endfor
 </table>
 """))
+
     def test_mako():
         return mako_template.render(**ctx)
 
     <?py #end ?>
 </table>
 """))
+
     def test_tenjin():
         return tenjin_template.render(ctx, helpers)
 
     {{ pass }}
 </table>
 """)), '', 'exec')
+
     def test_web2py():
         response = DummyResponse()
         exec(web2py_template, {}, dict(response=response, **ctx))
     {% endfor %}
 </table>
 """))
+
     def test_django():
         return django_template.render(Context(ctx))
 
     </tr>
 </table>
 """))
+
     def test_chameleon():
         return chameleon_template.render(**ctx)
 
     from pstats import Stats
     names = globals().keys()
     names = sorted([(name, globals()[name])
-             for name in names if name.startswith('test_')])
+                    for name in names if name.startswith('test_')])
     print("                    msec    rps  tcalls  funcs")
     for name, test in names:
         if test:
 # wheezy.core documentation build configuration file, created by
 # sphinx-quickstart on Fri Sep  9 20:36:50 2011.
 #
-# This file is execfile()d with the current directory set to its containing dir.
+# This file is execfile()d with the current directory set to its containing
+# dir.
 #
 # Note that not all possible configuration values are present in this
 # autogenerated file.
 # All configuration values have a default; values that are commented out
 # serve to show the default.
 
-import sys, os
+import os
+import sys
 
 # If extensions (or modules to document with autodoc) are in another directory,
 # add these directories to sys.path here. If the directory is relative to the
 # documentation root, use os.path.abspath to make it absolute, like shown here.
 #sys.path.insert(0, os.path.abspath('.'))
 sys.path.extend([
-	os.path.abspath(os.path.join('..', 'src'))
+    os.path.abspath(os.path.join('..', 'src'))
 ])
 
-# -- General configuration -----------------------------------------------------
+# -- General configuration ---------------------------------------------------
 
 # If your documentation needs a minimal Sphinx version, state it here.
 #needs_sphinx = '1.0'
 
-# Add any Sphinx extension module names here, as strings. They can be extensions
-# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
+# Add any Sphinx extension module names here, as strings. They can be
+# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
 extensions = [
     'sphinx.ext.autodoc', 'sphinx.ext.doctest',
     'sphinx.ext.coverage', 'sphinx.ext.viewcode'
 # directories to ignore when looking for source files.
 exclude_patterns = ['_build']
 
-# The reST default role (used for this markup: `text`) to use for all documents.
+# The reST default role (used for this markup: `text`) to use for all
+# documents.
 #default_role = None
 
 # If true, '()' will be appended to :func: etc. cross-reference text.
 #modindex_common_prefix = []
 
 
-# -- Options for HTML output ---------------------------------------------------
+# -- Options for HTML output -------------------------------------------------
 
 # The theme to use for HTML and HTML Help pages.  See the documentation for
 # a list of builtin themes.
     'codetextcolor': '#060',
     'bodyfont': 'Georgia, serif',
     'headfont': 'Calibri, sans-serif',
-	'stickysidebar': True,
-	'externalrefs': True
+    'stickysidebar': True,
+    'externalrefs': True
 }
 
 # Add any paths that contain custom themes here, relative to this directory.
 htmlhelp_basename = 'wheezy.templatedoc'
 
 
-# -- Options for LaTeX output --------------------------------------------------
+# -- Options for LaTeX output ------------------------------------------------
 
 # The paper size ('letter' or 'a4').
 #latex_paper_size = 'letter'
 #latex_font_size = '10pt'
 
 # Grouping the document tree into LaTeX files. List of tuples
-# (source start file, target name, title, author, documentclass [howto/manual]).
+# (source start file, target name, title, author, documentclass
+# [howto/manual]).
 latex_documents = [
-  ('index', 'wheezy.template.tex', u'wheezy.template Documentation',
-   u'Andriy Kornatskyy', 'manual'),
+    ('index', 'wheezy.template.tex', u'wheezy.template Documentation',
+     u'Andriy Kornatskyy', 'manual'),
 ]
 
 # The name of an image file (relative to this directory) to place at the top of
 #latex_domain_indices = True
 
 
-# -- Options for manual page output --------------------------------------------
+# -- Options for manual page output ------------------------------------------
 
 # One entry per manual page. List of tuples
 # (source start file, name, description, authors, manual section).
 try:
     from setuptools import setup
 except:
-    from distutils.core import setup
+    from distutils.core import setup  # noqa
 
 README = open(os.path.join(os.path.dirname(__file__), 'README')).read()
 

src/wheezy/template/__init__.py

+
+""" ``template`` package.
+"""
+
+# flake8: noqa
+
 from wheezy.template.engine import Engine
+from wheezy.template.ext.code import CodeExtension
+from wheezy.template.ext.core import CoreExtension
+from wheezy.template.loader import DictLoader
 from wheezy.template.loader import FileLoader
-from wheezy.template.loader import DictLoader
-from wheezy.template.ext.core import CoreExtension
+from wheezy.template.loader import PreprocessLoader

src/wheezy/template/comp.py

 if PY3:  # pragma: nocover
     from _thread import allocate_lock
 else:  # pragma: nocover
-    from thread import allocate_lock
+    from thread import allocate_lock  # noqa
 
 
 try:  # pragma: nocover
 
 except ImportError:  # pragma: nocover
 
-    def adjust_source_lineno(source, name, lineno):
+    def adjust_source_lineno(source, name, lineno):  # noqa
         return source

src/wheezy/template/ext/core.py

                 else:
                     return None
         else:
-            def parse_markup(value):
+            def parse_markup(value):  # noqa
                 if value:
                     return repr(value)
                 else:

src/wheezy/template/loader.py

 
 import os
 import os.path
+import stat
+
+from time import time
 
 
 class FileLoader(object):
     """
     if not enabled:
         return engine
+    return AutoReloadProxy(engine)
 
-    import stat
-    from time import time
 
-    class AutoReloadProxy(object):
+# region: internal details
 
-        def __init__(self, engine):
-            self.engine = engine
-            self.names = {}
+class AutoReloadProxy(object):
 
-        def get_template(self, name):
-            if self.file_changed(name):
-                self.remove(name)
-            return self.engine.get_template(name)
+    def __init__(self, engine):
+        self.engine = engine
+        self.names = {}
 
-        def render(self, name, ctx, local_defs, super_defs):
-            if self.file_changed(name):
-                self.remove(name)
-            return self.engine.render(name, ctx, local_defs, super_defs)
+    def get_template(self, name):
+        if self.file_changed(name):
+            self.remove(name)
+        return self.engine.get_template(name)
 
-        def remove(self, name):
-            self.engine.remove(name)
+    def render(self, name, ctx, local_defs, super_defs):
+        if self.file_changed(name):
+            self.remove(name)
+        return self.engine.render(name, ctx, local_defs, super_defs)
 
-        # region: internal details
+    def remove(self, name):
+        self.engine.remove(name)
 
-        def __getattr__(self, name):
-            return getattr(self.engine, name)
+    # region: internal details
 
-        def file_changed(self, name):
-            try:
-                last_known_stamp = self.names[name]
-                current_time = int(time())
-                if current_time - last_known_stamp <= 2:
-                    return False
-            except KeyError:
-                last_known_stamp = 0
+    def __getattr__(self, name):
+        return getattr(self.engine, name)
 
-            abspath = self.engine.loader.get_fullname(name)
-            if not abspath:
+    def file_changed(self, name):
+        try:
+            last_known_stamp = self.names[name]
+            current_time = int(time())
+            if current_time - last_known_stamp <= 2:
                 return False
+        except KeyError:
+            last_known_stamp = 0
 
-            last_modified_stamp = os.stat(abspath)[stat.ST_MTIME]
-            if last_modified_stamp <= last_known_stamp:
-                return False
-            self.names[name] = last_modified_stamp
-            return True
+        abspath = self.engine.loader.get_fullname(name)
+        if not abspath:
+            return False
 
-    return AutoReloadProxy(engine)
+        last_modified_stamp = os.stat(abspath)[stat.ST_MTIME]
+        if last_modified_stamp <= last_known_stamp:
+            return False
+        self.names[name] = last_modified_stamp
+        return True
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.