Skip to content

Commit

Permalink
Black the code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Howitz committed Dec 21, 2018
1 parent 5e29b21 commit 98a13cf
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 99 deletions.
6 changes: 6 additions & 0 deletions .travis.yml
Expand Up @@ -7,6 +7,12 @@ python:
- 3.6
- pypy
- pypy3
matrix:
include:
- python: 3.6
name: "Flake8"
install: pip install -U flake8
script: flake8 --doctests src tools setup.py
install:
- pip install -U pip setuptools
- pip install -U coverage coveralls
Expand Down
92 changes: 43 additions & 49 deletions setup.py
Expand Up @@ -16,65 +16,59 @@
import os
from setuptools import setup, find_packages


def read(*rnames):
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()

TESTS_REQUIRE = [
'zope.configuration',
'zope.testing',
'zope.testrunner',
]

TESTS_REQUIRE = ["zope.configuration", "zope.testing", "zope.testrunner"]

setup(
name='z3c.ptcompat',
version='2.1.1.dev0',
description='Zope-compatible page template engine based on Chameleon.',
long_description='\n\n'.join((
'.. contents::',
read('README.rst'),
read('CHANGES.rst'),
)),
name="z3c.ptcompat",
version="2.1.1.dev0",
description="Zope-compatible page template engine based on Chameleon.",
long_description="\n\n".join(
(".. contents::", read("README.rst"), read("CHANGES.rst"))
),
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
'Intended Audience :: Developers',
'License :: OSI Approved :: Zope Public License',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: Implementation',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Natural Language :: English',
'Operating System :: OS Independent',
'Topic :: Software Development :: Libraries :: Python Modules',
'Framework :: Plone',
'Framework :: Zope2',
'Framework :: Zope :: 3',
"Development Status :: 5 - Production/Stable",
"Environment :: Web Environment",
"Intended Audience :: Developers",
"License :: OSI Approved :: Zope Public License",
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: Implementation",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Natural Language :: English",
"Operating System :: OS Independent",
"Topic :: Software Development :: Libraries :: Python Modules",
"Framework :: Plone",
"Framework :: Zope2",
"Framework :: Zope :: 3",
],
keywords='zpt template zope',
url='https://github.com/zopefoundation/z3c.ptcompat',
author='Zope Corporation and Contributors',
author_email='zope-dev@zope.org',
license='ZPL',
packages=find_packages('src'),
package_dir={'': 'src'},
namespace_packages=['z3c'],
keywords="zpt template zope",
url="https://github.com/zopefoundation/z3c.ptcompat",
author="Zope Corporation and Contributors",
author_email="zope-dev@zope.org",
license="ZPL",
packages=find_packages("src"),
package_dir={"": "src"},
namespace_packages=["z3c"],
include_package_data=True,
zip_safe=False,
install_requires=[
'setuptools',
'z3c.pt >= 3.0.0a1',
'zope.pagetemplate >= 3.6.2',
'zope.traversing',
"setuptools",
"z3c.pt >= 3.0.0a1",
"zope.pagetemplate >= 3.6.2",
"zope.traversing",
],
extras_require={
'test': TESTS_REQUIRE,
},
extras_require={"test": TESTS_REQUIRE},
tests_require=TESTS_REQUIRE,
test_suite='z3c.ptcompat.tests.test_suite',
test_suite="z3c.ptcompat.tests.test_suite",
)
2 changes: 1 addition & 1 deletion src/z3c/__init__.py
@@ -1 +1 @@
__import__('pkg_resources').declare_namespace(__name__) # pragma: no cover
__import__("pkg_resources").declare_namespace(__name__) # pragma: no cover
1 change: 0 additions & 1 deletion src/z3c/ptcompat/__init__.py
Expand Up @@ -13,4 +13,3 @@
##############################################################################

__docformat__ = "reStructuredText"

7 changes: 3 additions & 4 deletions src/z3c/ptcompat/engine.py
Expand Up @@ -34,15 +34,14 @@ def __conform__(self, iface):
@implementer(IPageTemplateProgram)
@provider(IPageTemplateEngine)
class Program(object):

def __init__(self, template):
self.template = template

def __call__(self, context, macros, tal=True, **options):
if not tal:
return self.template.body

context.vars['repeat'] = TraversableRepeatDict(context.repeat_vars)
context.vars["repeat"] = TraversableRepeatDict(context.repeat_vars)

return self.template.render(**context.vars)

Expand All @@ -51,7 +50,7 @@ def cook(cls, source_file, text, engine, content_type):
# Chameleon doesn't like to have a 'filename' of None;
# see https://github.com/zopefoundation/z3c.ptcompat/issues/2
template = ChameleonPageTemplate(
text, filename=source_file or '<string>', keep_body=True,
)
text, filename=source_file or "<string>", keep_body=True
)

return cls(template), template.macros
7 changes: 5 additions & 2 deletions src/z3c/ptcompat/tests.py
Expand Up @@ -8,16 +8,19 @@ def setUp(self):
import z3c.ptcompat
import zope.component.testing
import zope.configuration.xmlconfig

zope.component.testing.setUp(self)
zope.configuration.xmlconfig.XMLConfig(
'configure.zcml', z3c.ptcompat)()
"configure.zcml", z3c.ptcompat
)()

super(HTMLTests, self).setUp()

class TestProgram(unittest.TestCase):

class TestProgram(unittest.TestCase):
def _makeOne(self, *args):
from z3c.ptcompat.engine import Program

return Program.cook(*args)

def test_call_with_no_tal_returns_template_body(self):
Expand Down
112 changes: 71 additions & 41 deletions tools/update.py
Expand Up @@ -8,36 +8,57 @@
import subprocess

parser = optparse.OptionParser()
parser.add_option("-n", "--dry-run",
action="store_true", dest="dry_run", default=False,
help="Don't actually make any changes.")
parser.add_option("-v", "--verbose",
action="store_true", dest="verbose", default=False,
help="Verbose output.")
parser.add_option(
"-n",
"--dry-run",
action="store_true",
dest="dry_run",
default=False,
help="Don't actually make any changes.",
)
parser.add_option(
"-v",
"--verbose",
action="store_true",
dest="verbose",
default=False,
help="Verbose output.",
)

re_vptf_sub = (
re.compile(
r'^from zope\.app\.pagetemplate(\.viewpagetemplatefile)? import ViewPageTemplateFile$',
re.M),
r'from z3c.ptcompat import ViewPageTemplateFile')
r"^from zope\.app\.pagetemplate(\.viewpagetemplatefile)?"
r" import ViewPageTemplateFile$",
re.M,
),
r"from z3c.ptcompat import ViewPageTemplateFile",
)

re_ptf_sub = (
re.compile(
r'^from zope\.pagetemplate(\.pagetemplatefile)? import PageTemplateFile$',
re.M),
r'from z3c.ptcompat import PageTemplateFile')
r"^from zope\.pagetemplate(\.pagetemplatefile)?"
r" import PageTemplateFile$",
re.M,
),
r"from z3c.ptcompat import PageTemplateFile",
)


def log(msg):
for line in msg.split('\n'):
print ">>> %s" % line
for line in msg.split("\n"):
print(">>> %s" % line)


def status(msg):
for line in msg.split('\n'):
print " %s" % line
for line in msg.split("\n"):
print(" %s" % line)


def main(options, args):
if options.dry_run:
status("Warning: Dry run---no changes will be made to the file-system.")
status(
"Warning: Dry run---no changes will be made to the file-system."
)

path = os.getcwd()
status("Working directory: %s" % path)
Expand All @@ -48,7 +69,7 @@ def main(options, args):
for arg, dirname, names in os.walk(path):
for name in names:
base, ext = os.path.splitext(name)
if ext != '.py':
if ext != ".py":
continue

if options.verbose and count > 0 and count % 500 == 0:
Expand All @@ -65,65 +86,74 @@ def main(options, args):
log("Updating import-statements in %d files..." % len(registry.keys()))

if options.dry_run:
queue = ['patch', '-p0', '--dry-run'],
queue = (["patch", "-p0", "--dry-run"],)
else:
queue = ['patch', '-p0', '--dry-run'], ['patch', '-p0']
queue = ["patch", "-p0", "--dry-run"], ["patch", "-p0"]

for args in queue:
if options.verbose:
args.append('--verbose')
args.append("--verbose")
else:
args.append('--quiet')
args.append("--quiet")

proc = subprocess.Popen(
" ".join(args),
shell=True,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
)
)

diffs = []
for filename, body in registry.iteritems():
if options.verbose:
changes = body.count('+++ ')
status("%s (%d %s)." % (
filename, changes, 'changes' if (changes > 1) else 'change'))
changes = body.count("+++ ")
status(
"%s (%d %s)."
% (
filename,
changes,
"changes" if (changes > 1) else "change",
)
)

diffs.append(body)

if not diffs:
break

output, err = proc.communicate("\n".join(diffs)+'\n')
output, err = proc.communicate("\n".join(diffs) + "\n")

if proc.returncode != 0:
map(status, output.split('\n'))
map(status, output.split("\n"))
status("An error occurred while applying patches.")
break
else:
status("Succesfully patched files.")
if '--dry-run' in args:

if "--dry-run" in args:
status("No files were changed.")

sys.exit(proc.returncode)


def create_diff(filename):
original = open(filename).read()
new = original

# process regular expression substitutions
for exp, replacement in (re_vptf_sub, re_ptf_sub):
new = exp.sub(replacement, new)

if original != new:
return "\n".join(map(str.rstrip, difflib.unified_diff(
original.split('\n'),
new.split('\n'),
filename,
filename)))

return "\n".join(
map(
str.rstrip,
difflib.unified_diff(
original.split("\n"), new.split("\n"), filename, filename
),
)
)


if __name__ == "__main__":
main(*parser.parse_args())


8 changes: 7 additions & 1 deletion tox.ini
@@ -1,6 +1,6 @@
[tox]
envlist =
py27,py34,py35,py36,pypy,pypy3,coverage
flake8,py27,py34,py35,py36,pypy,pypy3,coverage

[testenv]
commands =
Expand All @@ -18,3 +18,9 @@ commands =
deps =
{[testenv]deps}
coverage

[testenv:flake8]
basepython = python3.6
skip_install = true
deps = flake8
commands = flake8 --doctests src tools setup.py

0 comments on commit 98a13cf

Please sign in to comment.