Skip to content

Commit

Permalink
Lint the code.
Browse files Browse the repository at this point in the history
Add support for Python 3.7, 3.8, 3.9, and 3.10.
Drop support for Python 3.4.
  • Loading branch information
Michael Howitz committed Dec 1, 2021
1 parent a324868 commit 4576804
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 47 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Changelog

* Port code and tests to Python 3 instead of using no longer supported 2to3.

* Add support for Python 3.7, 3.8, 3.9, and 3.10.

* Drop support for Python 3.4.


2.1 (2018-07-14)
================
Expand Down
17 changes: 11 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,25 @@
version=version,
description="Buildout recipe to generate a text file from a template",
long_description=(
open("README.rst", "rb").read().decode("utf-8") + "\n\n" +
open(os.path.join("src", "collective", "recipe", "template",
"README.rst"), "rb").read().decode("utf-8") + "\n\n" +
open("CHANGES.rst", "rb").read().decode("utf-8")
open("README.rst", "rb").read().decode("utf-8")
+ "\n\n"
+ open(os.path.join("src", "collective", "recipe", "template",
"README.rst"), "rb").read().decode("utf-8")
+ "\n\n"
+ open("CHANGES.rst", "rb").read().decode("utf-8")
),
classifiers=[
"Framework :: Buildout",
"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 :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Topic :: Software Development :: Libraries :: Python Modules",
],
keywords='template recipe',
Expand All @@ -45,7 +50,7 @@
'zc.buildout',
],
extras_require=dict(
test=['zope.testing', ],
test=['zope.testing', 'zope.testrunner'],
genshi=[genshi_requirement, ],
),
entry_points="""
Expand Down
4 changes: 0 additions & 4 deletions src/collective/recipe/template/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ Now we can run buildout::
>>> print('\n'.join(lines))
Uninstalling template.
Installing template.
...

The template should have been created::

Expand Down Expand Up @@ -371,7 +370,6 @@ built:
Uninstalling template.
Installing other.
Installing template.
...

>>> cat('template')
#
Expand Down Expand Up @@ -403,7 +401,6 @@ Rerun the buildout:
Uninstalling other.
Installing other.
Updating template.
...

The file's mtime is not changed:
>>> getmtime('template') == orig_mtime
Expand All @@ -422,7 +419,6 @@ Rerun the buildout:
Uninstalling other.
Installing other.
Updating template.
...

The file's mtime is changed:
>>> getmtime('template') > orig_mtime
Expand Down
53 changes: 28 additions & 25 deletions src/collective/recipe/template/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,50 +13,55 @@

class Recipe:
def __init__(self, buildout, name, options):
self.buildout=buildout
self.name=name
self.options=options
self.logger=logging.getLogger(self.name)
self.buildout = buildout
self.name = name
self.options = options
self.logger = logging.getLogger(self.name)
self.msg = None

if "input" not in options and "inline" not in options and "url" not in options:
self.logger.error("No input file, inline template, or URL specified.")
raise zc.buildout.UserError("No input file, inline template, or URL specified.")
if ("input" not in options
and "inline" not in options
and "url" not in options):
self.logger.error(
"No input file, inline template, or URL specified.")
raise zc.buildout.UserError(
"No input file, inline template, or URL specified.")

if "output" not in options:
self.logger.error("No output file specified.")
raise zc.buildout.UserError("No output file specified.")

if ("input" in options and "inline" in options or
"input" in options and "url" in options):
"input" in options and "url" in options):
self.logger.error("Too many input sources.")
raise zc.buildout.UserError("Too many input sources.")

self.output=options["output"]
self.input=options.get("input")
self.input_encoding=options.get("input-encoding", "utf-8")
self.output_encoding=options.get("output-encoding", "utf-8")
self.inline=options.get("inline")
self.output = options["output"]
self.input = options.get("input")
self.input_encoding = options.get("input-encoding", "utf-8")
self.output_encoding = options.get("output-encoding", "utf-8")
self.inline = options.get("inline")
self.url = options.get("url")
self.timeout = float(options.get("timeout", 1.0))
self.overwrite = options.get("overwrite", 'true').lower() in TRUE_VALUES
self.overwrite = options.get(
"overwrite", 'true').lower() in TRUE_VALUES
if "inline" in options:
self.source = self.inline.lstrip()
self.mode = None
elif "input" in options and os.path.exists(self.input):
with open(self.input, 'rb') as f:
self.source = f.read().decode(self.input_encoding)
self.mode=stat.S_IMODE(os.stat(self.input).st_mode)
self.mode = stat.S_IMODE(os.stat(self.input).st_mode)
elif "input" in options and self.input.startswith('inline:'):
self.source=self.input[len('inline:'):].lstrip()
self.mode=None
self.source = self.input[len('inline:'):].lstrip()
self.mode = None
elif "url" in options and self._checkurl():
self.source = self.url.read().decode(self.input_encoding)
self.mode=None
self.mode = None
else:
# If the error is not from urllib2
if self.url == None:
msg="Input file '%s' does not exist." % self.input
if self.url is None:
msg = "Input file '%s' does not exist." % self.input
else:
msg = self.msg
self.logger.error(msg)
Expand All @@ -65,8 +70,7 @@ def __init__(self, buildout, name, options):
self._execute()

if "mode" in options:
self.mode=int(options["mode"], 8)

self.mode = int(options["mode"], 8)

def _execute(self):
template = self.source
Expand Down Expand Up @@ -107,12 +111,12 @@ def install(self):
os.chmod(self.output, self.mode)

if self.overwrite:
# prevents deleting after execute buildout after modifying buildout.cfg
# prevents deleting after execute buildout after modifying
# buildout.cfg
self.options.created(self.output)

return self.options.created()


def update(self):
# Variables in other parts might have changed so we may need to do a
# full reinstall.
Expand All @@ -128,7 +132,6 @@ def update(self):
# Output has changed, re-write output file
return self.install()


def createIntermediatePaths(self, path):
parent = os.path.dirname(path)
if os.path.exists(path) or parent == path:
Expand Down
3 changes: 2 additions & 1 deletion src/collective/recipe/template/genshitemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ def _execute(self):
try:
self.result = template.generate(context).render()
except UndefinedError as e:
raise zc.buildout.UserError("Error in template %s:\n%s" % (self.input, e.msg))
raise zc.buildout.UserError(
"Error in template %s:\n%s" % (self.input, e.msg))
20 changes: 9 additions & 11 deletions src/collective/recipe/template/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,20 @@ def setUp(test):
(re.compile('#![^\n]+\n'), ''),
(re.compile(r'-\S+-py\d[.]\d(-\S+)?.egg'),
'-pyN.N.egg',
),
])
),
])


def test_suite():
return unittest.TestSuite([
doctest.DocFileSuite('README.rst',
doctest.DocFileSuite(
'README.rst',
setUp=setUp, tearDown=zc.buildout.testing.buildoutTearDown,
optionflags=doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE,
optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE,
checker=checker),
doctest.DocFileSuite('genshitemplate.rst',
doctest.DocFileSuite(
'genshitemplate.rst',
setUp=setUp, tearDown=zc.buildout.testing.buildoutTearDown,
optionflags=doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE,
optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE,
checker=checker),
])


if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
])

0 comments on commit 4576804

Please sign in to comment.