Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Python version support. #124

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated from:
# https://github.com/zopefoundation/meta/tree/master/config/pure-python
name: pre-commit

on:
pull_request:
push:
branches:
- master
# Allow to run this workflow manually from the Actions tab
workflow_dispatch:

env:
FORCE_COLOR: 1

jobs:
pre-commit:
name: linting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
- uses: pre-commit/action@v3.0.1
with:
extra_args: --all-files --show-diff-on-failure
env:
PRE_COMMIT_COLOR: always
- uses: pre-commit-ci/lite-action@v1.0.2
if: always()
with:
msg: Apply pre-commit code formatting
19 changes: 10 additions & 9 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ jobs:
- ["ubuntu", "ubuntu-latest"]
config:
# [Python version, tox env]
- ["3.11", "release-check"]
- ["3.11", "lint"]
- ["3.8", "py38"]
- ["3.9", "py39"]
- ["3.10", "py310"]
- ["3.11", "py311"]
- ["3.12", "py312"]
- ["3.11", "docs"]
- ["3.11", "coverage"]
- ["3.11", "release-check"]
- ["3.8", "py38"]
- ["3.9", "py39"]
- ["3.10", "py310"]
- ["3.11", "py311"]
- ["3.12", "py312"]
- ["3.13", "py313"]
- ["3.11", "docs"]
- ["3.11", "coverage"]

runs-on: ${{ matrix.os[1] }}
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
Expand All @@ -39,6 +39,7 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.config[0] }}
allow-prereleases: true
- name: Pip cache
uses: actions/cache@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .meta.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# https://github.com/zopefoundation/meta/tree/master/config/pure-python
[meta]
template = "pure-python"
commit-id = "994c74d7"
commit-id = "f317618e"

[python]
with-windows = false
Expand Down
28 changes: 28 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated from:
# https://github.com/zopefoundation/meta/tree/master/config/pure-python
minimum_pre_commit_version: '3.6'
repos:
- repo: https://github.com/pycqa/isort
rev: "5.13.2"
hooks:
- id: isort
- repo: https://github.com/hhatto/autopep8
rev: "v2.3.1"
hooks:
- id: autopep8
args: [--in-place, --aggressive, --aggressive]
- repo: https://github.com/asottile/pyupgrade
rev: v3.17.0
hooks:
- id: pyupgrade
args: [--py38-plus]
- repo: https://github.com/isidentical/teyit
rev: 0.4.3
hooks:
- id: teyit
- repo: https://github.com/PyCQA/flake8
rev: "7.1.1"
hooks:
- id: flake8
additional_dependencies:
- flake8-debugger == 4.1.2
8 changes: 4 additions & 4 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ Changelog
5.2 (unreleased)
----------------

- Improve Italian translation
(`#121 <https://github.com/zopefoundation/z3c.form/pull/121>`_)
- Drop support for Python 3.7.

- Add support for Python 3.12.
- Add support for Python 3.12, 3.13.

- Drop support for Python 3.7.
- Improve Italian translation
(`#121 <https://github.com/zopefoundation/z3c.form/pull/121>`_)

- Add basque (eu) translation.

Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ include *.rst
include *.txt
include buildout.cfg
include tox.ini
include .pre-commit-config.yaml

recursive-include docs *.py
recursive-include docs *.rst
Expand Down
103 changes: 57 additions & 46 deletions benchmark/benchmark/tests.py
Original file line number Diff line number Diff line change
@@ -1,81 +1,89 @@
import os
import unittest
import time
import sys
import random
import sys
import time
import unittest
from imp import reload

reload(sys)
sys.setdefaultencoding('utf-8')

import zope.configuration.xmlconfig
import zope.interface
import z3c.pt
import z3c.ptcompat.engine
import zope.component
import zope.component.globalregistry
import zope.configuration.xmlconfig
import zope.interface
import zope.schema
from zope.pagetemplate.interfaces import IPageTemplateEngine
from zope.browserpage.viewpagetemplatefile import ViewPageTemplateFile

import z3c.pt
import z3c.ptcompat.engine
from z3c.pt.pagetemplate import ViewPageTemplateFile as z3cViewPageTemplateFile
from zope.browserpage.viewpagetemplatefile import ViewPageTemplateFile
from zope.pagetemplate.interfaces import IPageTemplateEngine

from z3c.form import field
from z3c.form import form
from z3c.form import term
from z3c.form import field
from z3c.form import tests
from z3c.form import testing
from z3c.form import tests


reload(sys)
sys.setdefaultencoding('utf-8')


def benchmark(title):
def decorator(f):
def wrapper(*args):
print "==============================="
print title
print "==============================="
print("===============================")
print(title)
print("===============================")
return f(*args)
return wrapper
return decorator


def timing(func, *args, **kwargs):
t1 = t2 = time.time()
i = 0
while t2 - t1 < 3:
func(*args, **kwargs)
i += 1
t2 = time.time()
return 100*(t2-t1)/i
return 100 * (t2 - t1) / i


class ISmallForm(zope.interface.Interface):
name = zope.schema.TextLine(
title=u"Name",
description=u"Please enter your first and last name.")
title="Name",
description="Please enter your first and last name.")

address = zope.schema.TextLine(
title=u"Address",
description=u"Please enter a valid address.")
title="Address",
description="Please enter a valid address.")


class ILargeDataSetsForm(zope.interface.Interface):
lucky_numer = zope.schema.Choice(
range(500),
title=u"Lucky number",
description=u"Choose your lucky number.")
title="Lucky number",
description="Choose your lucky number.")

favorite_letters = zope.schema.Set(
title=u"Favorite letter",
description=u"Choose your favorite letter.",
title="Favorite letter",
description="Choose your favorite letter.",
value_type=zope.schema.Choice(
["".join(chr(random.randint(65, 90)) for i in range(10))]
["".join(chr(random.randint(65, 90)) for i in range(10))]
))


def build_many_fields(size):
for i in range(size):
name = "".join(chr(random.randint(65, 90)) for i in range(10))
yield zope.schema.TextLine(
__name__=name,
description=u"This field renders %s" % name,
title=u"Title of %s" % name.capitalize())
description="This field renders %s" % name,
title="Title of %s" % name.capitalize())


IManyFields = tuple(build_many_fields(500))


class BaseTestCase(unittest.TestCase):
def _setUp(suite):
testing.setUp(suite)
Expand All @@ -91,13 +99,14 @@ def enableZ3CPT():
"""Enable z3c.pt engine"""
base = zope.component.globalregistry.base
base.registerUtility(z3c.ptcompat.engine.Program, IPageTemplateEngine,
name=u'', event=False)
name='', event=False)


def disableZ3CPT():
"""Disable z3c.pt engine"""
base = zope.component.globalregistry.base
base.unregisterUtility(z3c.ptcompat.engine.Program, IPageTemplateEngine,
name=u'')
name='')


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

@benchmark(u"Small add-form (update/render)")
@benchmark("Small add-form (update/render)")
def testSmallForm(self):
context = object()
request = testing.TestRequest()
Expand All @@ -122,11 +131,11 @@ def testSmallForm(self):
t_z3c = self.benchmark(enableZ3CPT, f_z3c)
t_zope = self.benchmark(disableZ3CPT, f_zope)

print "z3c.pt: %.3f" % t_z3c
print "zope.pagetemplate: %.3f" % t_zope
print " %.2fX" % (t_zope/t_z3c)
print("z3c.pt: %.3f" % t_z3c)
print("zope.pagetemplate: %.3f" % t_zope)
print(" %.2fX" % (t_zope / t_z3c))

@benchmark(u"Large data sets (update/render)")
@benchmark("Large data sets (update/render)")
def testLargeDataSets(self):
context = object()
request = testing.TestRequest()
Expand All @@ -139,11 +148,11 @@ def testLargeDataSets(self):
t_z3c = self.benchmark(enableZ3CPT, f_z3c)
t_zope = self.benchmark(disableZ3CPT, f_zope)

print "z3c.pt: %.3f" % t_z3c
print "zope.pagetemplate: %.3f" % t_zope
print " %.2fX" % (t_zope/t_z3c)
print("z3c.pt: %.3f" % t_z3c)
print("zope.pagetemplate: %.3f" % t_zope)
print(" %.2fX" % (t_zope / t_z3c))

@benchmark(u"Many fields (update/render)")
@benchmark("Many fields (update/render)")
def testManyFields(self):
context = object()
request = testing.TestRequest()
Expand All @@ -156,9 +165,9 @@ def testManyFields(self):
t_z3c = self.benchmark(enableZ3CPT, f_z3c)
t_zope = self.benchmark(disableZ3CPT, f_zope)

print "z3c.pt: %.3f" % t_z3c
print "zope.pagetemplate: %.3f" % t_zope
print " %.2fX" % (t_zope/t_z3c)
print("z3c.pt: %.3f" % t_z3c)
print("zope.pagetemplate: %.3f" % t_zope)
print(" %.2fX" % (t_zope / t_z3c))

def benchmark(self, prep, func, *args):
self._setUp()
Expand All @@ -169,10 +178,12 @@ def benchmark(self, prep, func, *args):
self._tearDown()
return t


def test_suite():
return unittest.TestSuite((
unittest.makeSuite(BenchmarkTestCase),
))
unittest.defaultTestLoader.loadTestsFromTestCase(BenchmarkTestCase),
))


if __name__ == "__main__":
unittest.main(defaultTest="test_suite")
18 changes: 10 additions & 8 deletions benchmark/setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from setuptools import setup, find_packages
from setuptools import find_packages
from setuptools import setup


version = '0.1'

Expand All @@ -8,18 +10,18 @@
long_description="""\
""",
keywords='',
author = "Malthe Borch and the Zope Community",
author_email = "zope-dev@zope.org",
author="Malthe Borch and the Zope Community",
author_email="zope-dev@zope.org",
url='',
license='',
packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
include_package_data=True,
zip_safe=False,
install_requires=[
'zope.app.pagetemplate',
'zope.schema',
'z3c.form',
'z3c.pt',
'z3c.ptcompat',
'zope.app.pagetemplate',
'zope.schema',
'z3c.form',
'z3c.pt',
'z3c.ptcompat',
],
)
Loading