Skip to content

Commit

Permalink
Tiny fixes (code style by flake8) and badges in the readme
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkoryukov committed Nov 29, 2016
1 parent 263234f commit 41cc8de
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 26 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ cache:
pip: true

python:
- "2.6"
# - "2.6"
- "2.7"

install:
- pip install PyMeta3
- pip install coverage
- pip install codecov
#- pip install flake8
- pip install flake8

script:
- flake8
- coverage run tests.py

after_success:
Expand Down
18 changes: 10 additions & 8 deletions pybars/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
# established at this point, and setup.py will use a version of next-$(revno).
# If the releaselevel is 'final', then the tarball will be major.minor.micro.
# Otherwise it is major.minor.micro~$(revno).

from pybars._compiler import (
Compiler,
strlist,
Scope,
PybarsError
)

__version__ = '0.9.2'
__version_info__ = (0, 9, 2, 'final', 0)

Expand All @@ -37,12 +45,6 @@
'PybarsError'
]

from pybars._compiler import (
Compiler,
strlist,
Scope,
PybarsError
)


log = lambda value: None
def log(value):
return None
20 changes: 10 additions & 10 deletions pybars/_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@

"""The compiler for pybars."""

import re
import sys
from types import ModuleType
import linecache

import pybars
import pybars._templates
from pymeta.grammar import OMeta

__all__ = [
'Compiler',
Expand All @@ -25,14 +33,6 @@

__metaclass__ = type

import re
import sys
from types import ModuleType
import linecache

import pybars
import pybars._templates
from pymeta.grammar import OMeta

# This allows the code to run on Python 2 and 3 by
# creating a consistent reference for the appropriate
Expand Down Expand Up @@ -154,7 +154,7 @@
| "" => ''
| "this" => ''
pathseg ::= <anything>:symbol => u''.join(symbol)
"""
""" # noqa: E501
compile_grammar = compile_grammar.format(str_class=str_class.__name__)


Expand Down Expand Up @@ -759,7 +759,7 @@ def _extract_word(self, source, position):
boundry = re.search('}}|}|\s|$', source[position:])
end_offset = boundry.end() if boundry.group(0).startswith('}') else boundry.start()

return source[position-start_offset:position+end_offset]
return source[position - start_offset:position + end_offset]

def _generate_code(self, source):
"""
Expand Down
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# pybars3 - Handlebars.js for Python 3 and 2

[![Build Status](https://travis-ci.org/wbond/pybars3.svg?branch=master)](https://travis-ci.org/wbond/pybars3)
[![Codecov](https://codecov.io/gh/wbond/pybars3/branch/master/graph/badge.svg)](https://codecov.io/gh/wbond/pybars3)

Pybars3 provides a template system for Python which is compatible with
Handlebars.js. It is a fork of the pybars project that adds Python 3
compatibility and numerous features from Handlebars.js 2.0.
Expand Down
11 changes: 11 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[flake8]

# E128 continuation line under-indented for visual indent
# E131 continuation line unaligned for hanging indent
# E123 closing bracket does not match indentation of opening bracket's line
ignore = E123, E128, E131

exclude = libs
max-line-length = 160
count=True
statistics=True
4 changes: 2 additions & 2 deletions tests.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import sys
import unittest

from tests.test__compiler import TestCompiler
from tests.test_acceptance import TestAcceptance
from tests.test__compiler import TestCompiler # noqa: F401
from tests.test_acceptance import TestAcceptance # noqa: F401

if len(sys.argv) >= 2 and sys.argv[1] == '--debug':
import pybars
Expand Down
2 changes: 1 addition & 1 deletion tests/test__compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@


def render(source, context, helpers=None, partials=None, knownHelpers=None,
knownHelpersOnly=False):
knownHelpersOnly=False):
compiler = Compiler()
template = compiler.compile(source)
# For real use, partials is a dict of compiled templates; but for testing
Expand Down
5 changes: 2 additions & 3 deletions tests/test_acceptance.py
Original file line number Diff line number Diff line change
Expand Up @@ -1619,7 +1619,6 @@ def test_if_else(self):
self.assertRender(template, {'goodbye': False}, u"Hello")
self.assertRender(template, {'hello': 'hello'}, u"Hello")


def test_if_with_function_argument(self):
template = u"{{#if goodbye}}GOODBYE {{/if}}cruel {{world}}!"

Expand Down Expand Up @@ -2170,7 +2169,7 @@ def test_GH_158__Using_array_index_twice_breaks_the_template(self):
self.assertRender(template, context, result)

def test_bug_reported_by__fat_where_lambdas_weren_t_being_properly_resolved(self):
template = u"<strong>This is a slightly more complicated {{thing}}.</strong>.\n{{! Just ignore this business. }}\nCheck this out:\n{{#hasThings}}\n<ul>\n{{#things}}\n<li class={{className}}>{{word}}</li>\n{{/things}}</ul>.\n{{/hasThings}}\n{{^hasThings}}\n\n<small>Nothing to check out...</small>\n{{/hasThings}}"
template = u"<strong>This is a slightly more complicated {{thing}}.</strong>.\n{{! Just ignore this business. }}\nCheck this out:\n{{#hasThings}}\n<ul>\n{{#things}}\n<li class={{className}}>{{word}}</li>\n{{/things}}</ul>.\n{{/hasThings}}\n{{^hasThings}}\n\n<small>Nothing to check out...</small>\n{{/hasThings}}" # noqa: E501
context = {
'thing': lambda this: "blah",
'things': [
Expand All @@ -2189,7 +2188,7 @@ def test_bug_reported_by__fat_where_lambdas_weren_t_being_properly_resolved(self
],
'hasThings': lambda this: True
}
result = u"<strong>This is a slightly more complicated blah.</strong>.\n\nCheck this out:\n\n<ul>\n\n<li class=one>@fat</li>\n\n<li class=two>@dhg</li>\n\n<li class=three>@sayrer</li>\n</ul>.\n\n"
result = u"<strong>This is a slightly more complicated blah.</strong>.\n\nCheck this out:\n\n<ul>\n\n<li class=one>@fat</li>\n\n<li class=two>@dhg</li>\n\n<li class=three>@sayrer</li>\n</ul>.\n\n" # noqa: E501

self.assertRender(template, context, result)

Expand Down

0 comments on commit 41cc8de

Please sign in to comment.