Skip to content

Commit dca1ee6

Browse files
committed
Configuring for pure-python
1 parent 1ac4f0f commit dca1ee6

File tree

11 files changed

+226
-150
lines changed

11 files changed

+226
-150
lines changed

.github/workflows/pre-commit.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Generated from:
2+
# https://github.com/zopefoundation/meta/tree/master/config/pure-python
3+
name: pre-commit
4+
5+
on:
6+
pull_request:
7+
push:
8+
branches:
9+
- master
10+
# Allow to run this workflow manually from the Actions tab
11+
workflow_dispatch:
12+
13+
env:
14+
FORCE_COLOR: 1
15+
16+
jobs:
17+
pre-commit:
18+
name: linting
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v4
22+
- uses: actions/setup-python@v5
23+
with:
24+
python-version: 3.x
25+
- uses: pre-commit/[email protected]
26+
with:
27+
extra_args: --all-files --show-diff-on-failure
28+
env:
29+
PRE_COMMIT_COLOR: always
30+
- uses: pre-commit-ci/[email protected]
31+
if: always()
32+
with:
33+
msg: Apply pre-commit code formatting

.github/workflows/tests.yml

+10-9
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ jobs:
2020
- ["ubuntu", "ubuntu-latest"]
2121
config:
2222
# [Python version, tox env]
23-
- ["3.11", "release-check"]
24-
- ["3.11", "lint"]
25-
- ["3.8", "py38"]
26-
- ["3.9", "py39"]
27-
- ["3.10", "py310"]
28-
- ["3.11", "py311"]
29-
- ["3.12", "py312"]
30-
- ["3.11", "docs"]
31-
- ["3.11", "coverage"]
23+
- ["3.11", "release-check"]
24+
- ["3.8", "py38"]
25+
- ["3.9", "py39"]
26+
- ["3.10", "py310"]
27+
- ["3.11", "py311"]
28+
- ["3.12", "py312"]
29+
- ["3.13", "py313"]
30+
- ["3.11", "docs"]
31+
- ["3.11", "coverage"]
3232

3333
runs-on: ${{ matrix.os[1] }}
3434
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
@@ -39,6 +39,7 @@ jobs:
3939
uses: actions/setup-python@v5
4040
with:
4141
python-version: ${{ matrix.config[0] }}
42+
allow-prereleases: true
4243
- name: Pip cache
4344
uses: actions/cache@v4
4445
with:

.meta.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# https://github.com/zopefoundation/meta/tree/master/config/pure-python
33
[meta]
44
template = "pure-python"
5-
commit-id = "994c74d7"
5+
commit-id = "f317618e"
66

77
[python]
88
with-windows = false

.pre-commit-config.yaml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Generated from:
2+
# https://github.com/zopefoundation/meta/tree/master/config/pure-python
3+
minimum_pre_commit_version: '3.6'
4+
repos:
5+
- repo: https://github.com/pycqa/isort
6+
rev: "5.13.2"
7+
hooks:
8+
- id: isort
9+
- repo: https://github.com/hhatto/autopep8
10+
rev: "v2.3.1"
11+
hooks:
12+
- id: autopep8
13+
args: [--in-place, --aggressive, --aggressive]
14+
- repo: https://github.com/asottile/pyupgrade
15+
rev: v3.17.0
16+
hooks:
17+
- id: pyupgrade
18+
args: [--py38-plus]
19+
- repo: https://github.com/isidentical/teyit
20+
rev: 0.4.3
21+
hooks:
22+
- id: teyit
23+
- repo: https://github.com/PyCQA/flake8
24+
rev: "7.1.1"
25+
hooks:
26+
- id: flake8
27+
additional_dependencies:
28+
- flake8-debugger == 4.1.2

MANIFEST.in

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ include *.rst
55
include *.txt
66
include buildout.cfg
77
include tox.ini
8+
include .pre-commit-config.yaml
89

910
recursive-include docs *.py
1011
recursive-include docs *.rst

benchmark/benchmark/tests.py

+57-46
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,89 @@
11
import os
2-
import unittest
3-
import time
4-
import sys
52
import random
3+
import sys
4+
import time
5+
import unittest
6+
from imp import reload
67

7-
reload(sys)
8-
sys.setdefaultencoding('utf-8')
9-
10-
import zope.configuration.xmlconfig
11-
import zope.interface
8+
import z3c.pt
9+
import z3c.ptcompat.engine
1210
import zope.component
1311
import zope.component.globalregistry
12+
import zope.configuration.xmlconfig
13+
import zope.interface
1414
import zope.schema
15-
from zope.pagetemplate.interfaces import IPageTemplateEngine
16-
from zope.browserpage.viewpagetemplatefile import ViewPageTemplateFile
17-
18-
import z3c.pt
19-
import z3c.ptcompat.engine
2015
from z3c.pt.pagetemplate import ViewPageTemplateFile as z3cViewPageTemplateFile
16+
from zope.browserpage.viewpagetemplatefile import ViewPageTemplateFile
17+
from zope.pagetemplate.interfaces import IPageTemplateEngine
2118

19+
from z3c.form import field
2220
from z3c.form import form
2321
from z3c.form import term
24-
from z3c.form import field
25-
from z3c.form import tests
2622
from z3c.form import testing
23+
from z3c.form import tests
24+
25+
26+
reload(sys)
27+
sys.setdefaultencoding('utf-8')
28+
2729

2830
def benchmark(title):
2931
def decorator(f):
3032
def wrapper(*args):
31-
print "==============================="
32-
print title
33-
print "==============================="
33+
print("===============================")
34+
print(title)
35+
print("===============================")
3436
return f(*args)
3537
return wrapper
3638
return decorator
3739

40+
3841
def timing(func, *args, **kwargs):
3942
t1 = t2 = time.time()
4043
i = 0
4144
while t2 - t1 < 3:
4245
func(*args, **kwargs)
4346
i += 1
4447
t2 = time.time()
45-
return 100*(t2-t1)/i
48+
return 100 * (t2 - t1) / i
49+
4650

4751
class ISmallForm(zope.interface.Interface):
4852
name = zope.schema.TextLine(
49-
title=u"Name",
50-
description=u"Please enter your first and last name.")
53+
title="Name",
54+
description="Please enter your first and last name.")
5155

5256
address = zope.schema.TextLine(
53-
title=u"Address",
54-
description=u"Please enter a valid address.")
57+
title="Address",
58+
description="Please enter a valid address.")
59+
5560

5661
class ILargeDataSetsForm(zope.interface.Interface):
5762
lucky_numer = zope.schema.Choice(
5863
range(500),
59-
title=u"Lucky number",
60-
description=u"Choose your lucky number.")
64+
title="Lucky number",
65+
description="Choose your lucky number.")
6166

6267
favorite_letters = zope.schema.Set(
63-
title=u"Favorite letter",
64-
description=u"Choose your favorite letter.",
68+
title="Favorite letter",
69+
description="Choose your favorite letter.",
6570
value_type=zope.schema.Choice(
66-
["".join(chr(random.randint(65, 90)) for i in range(10))]
71+
["".join(chr(random.randint(65, 90)) for i in range(10))]
6772
))
6873

74+
6975
def build_many_fields(size):
7076
for i in range(size):
7177
name = "".join(chr(random.randint(65, 90)) for i in range(10))
7278
yield zope.schema.TextLine(
7379
__name__=name,
74-
description=u"This field renders %s" % name,
75-
title=u"Title of %s" % name.capitalize())
80+
description="This field renders %s" % name,
81+
title="Title of %s" % name.capitalize())
82+
7683

7784
IManyFields = tuple(build_many_fields(500))
7885

86+
7987
class BaseTestCase(unittest.TestCase):
8088
def _setUp(suite):
8189
testing.setUp(suite)
@@ -91,13 +99,14 @@ def enableZ3CPT():
9199
"""Enable z3c.pt engine"""
92100
base = zope.component.globalregistry.base
93101
base.registerUtility(z3c.ptcompat.engine.Program, IPageTemplateEngine,
94-
name=u'', event=False)
102+
name='', event=False)
103+
95104

96105
def disableZ3CPT():
97106
"""Disable z3c.pt engine"""
98107
base = zope.component.globalregistry.base
99108
base.unregisterUtility(z3c.ptcompat.engine.Program, IPageTemplateEngine,
100-
name=u'')
109+
name='')
101110

102111

103112
class BenchmarkTestCase(BaseTestCase):
@@ -109,7 +118,7 @@ class SimpleForm(form.AddForm):
109118
os.path.join(tests.__path__[0], 'simple_edit.pt'))
110119
return SimpleForm
111120

112-
@benchmark(u"Small add-form (update/render)")
121+
@benchmark("Small add-form (update/render)")
113122
def testSmallForm(self):
114123
context = object()
115124
request = testing.TestRequest()
@@ -122,11 +131,11 @@ def testSmallForm(self):
122131
t_z3c = self.benchmark(enableZ3CPT, f_z3c)
123132
t_zope = self.benchmark(disableZ3CPT, f_zope)
124133

125-
print "z3c.pt: %.3f" % t_z3c
126-
print "zope.pagetemplate: %.3f" % t_zope
127-
print " %.2fX" % (t_zope/t_z3c)
134+
print("z3c.pt: %.3f" % t_z3c)
135+
print("zope.pagetemplate: %.3f" % t_zope)
136+
print(" %.2fX" % (t_zope / t_z3c))
128137

129-
@benchmark(u"Large data sets (update/render)")
138+
@benchmark("Large data sets (update/render)")
130139
def testLargeDataSets(self):
131140
context = object()
132141
request = testing.TestRequest()
@@ -139,11 +148,11 @@ def testLargeDataSets(self):
139148
t_z3c = self.benchmark(enableZ3CPT, f_z3c)
140149
t_zope = self.benchmark(disableZ3CPT, f_zope)
141150

142-
print "z3c.pt: %.3f" % t_z3c
143-
print "zope.pagetemplate: %.3f" % t_zope
144-
print " %.2fX" % (t_zope/t_z3c)
151+
print("z3c.pt: %.3f" % t_z3c)
152+
print("zope.pagetemplate: %.3f" % t_zope)
153+
print(" %.2fX" % (t_zope / t_z3c))
145154

146-
@benchmark(u"Many fields (update/render)")
155+
@benchmark("Many fields (update/render)")
147156
def testManyFields(self):
148157
context = object()
149158
request = testing.TestRequest()
@@ -156,9 +165,9 @@ def testManyFields(self):
156165
t_z3c = self.benchmark(enableZ3CPT, f_z3c)
157166
t_zope = self.benchmark(disableZ3CPT, f_zope)
158167

159-
print "z3c.pt: %.3f" % t_z3c
160-
print "zope.pagetemplate: %.3f" % t_zope
161-
print " %.2fX" % (t_zope/t_z3c)
168+
print("z3c.pt: %.3f" % t_z3c)
169+
print("zope.pagetemplate: %.3f" % t_zope)
170+
print(" %.2fX" % (t_zope / t_z3c))
162171

163172
def benchmark(self, prep, func, *args):
164173
self._setUp()
@@ -169,10 +178,12 @@ def benchmark(self, prep, func, *args):
169178
self._tearDown()
170179
return t
171180

181+
172182
def test_suite():
173183
return unittest.TestSuite((
174-
unittest.makeSuite(BenchmarkTestCase),
175-
))
184+
unittest.defaultTestLoader.loadTestsFromTestCase(BenchmarkTestCase),
185+
))
186+
176187

177188
if __name__ == "__main__":
178189
unittest.main(defaultTest="test_suite")

benchmark/setup.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from setuptools import setup, find_packages
1+
from setuptools import find_packages
2+
from setuptools import setup
3+
24

35
version = '0.1'
46

@@ -8,18 +10,18 @@
810
long_description="""\
911
""",
1012
keywords='',
11-
author = "Malthe Borch and the Zope Community",
12-
author_email = "[email protected]",
13+
author="Malthe Borch and the Zope Community",
14+
author_email="[email protected]",
1315
url='',
1416
license='',
1517
packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
1618
include_package_data=True,
1719
zip_safe=False,
1820
install_requires=[
19-
'zope.app.pagetemplate',
20-
'zope.schema',
21-
'z3c.form',
22-
'z3c.pt',
23-
'z3c.ptcompat',
21+
'zope.app.pagetemplate',
22+
'zope.schema',
23+
'z3c.form',
24+
'z3c.pt',
25+
'z3c.ptcompat',
2426
],
2527
)

0 commit comments

Comments
 (0)