From 945be8539e174a55e75cb9542aef893adfb7ddde Mon Sep 17 00:00:00 2001 From: Michael Howitz Date: Fri, 20 Dec 2024 08:40:12 +0100 Subject: [PATCH] Add support for Python 3.13. (#124) --- .github/workflows/pre-commit.yml | 33 ++++++++++ .github/workflows/tests.yml | 19 +++--- .meta.toml | 2 +- .pre-commit-config.yaml | 28 +++++++++ CHANGES.rst | 8 +-- MANIFEST.in | 1 + benchmark/benchmark/tests.py | 103 +++++++++++++++++-------------- benchmark/setup.py | 18 +++--- docs/conf.py | 97 +++++++++++++++-------------- pyproject.toml | 21 +++++++ setup.py | 1 + tox.ini | 53 +++++----------- 12 files changed, 230 insertions(+), 154 deletions(-) create mode 100644 .github/workflows/pre-commit.yml create mode 100644 .pre-commit-config.yaml create mode 100644 pyproject.toml diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 00000000..0f06e163 --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -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 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 30bb6498..f8f824e9 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 @@ -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: diff --git a/.meta.toml b/.meta.toml index 20529b4d..1389b0db 100644 --- a/.meta.toml +++ b/.meta.toml @@ -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 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..7ab398cc --- /dev/null +++ b/.pre-commit-config.yaml @@ -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 diff --git a/CHANGES.rst b/CHANGES.rst index f93e4ab7..fd9cbc11 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,12 +5,12 @@ Changelog 5.2 (unreleased) ---------------- -- Improve Italian translation - (`#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 `_) - Add basque (eu) translation. diff --git a/MANIFEST.in b/MANIFEST.in index 938572bc..b759684f 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -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 diff --git a/benchmark/benchmark/tests.py b/benchmark/benchmark/tests.py index 7be93222..46ea22ed 100644 --- a/benchmark/benchmark/tests.py +++ b/benchmark/benchmark/tests.py @@ -1,40 +1,43 @@ 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 @@ -42,40 +45,45 @@ def timing(func, *args, **kwargs): 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) @@ -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): @@ -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() @@ -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() @@ -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() @@ -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() @@ -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") diff --git a/benchmark/setup.py b/benchmark/setup.py index 6df2492f..a5bcd5d2 100644 --- a/benchmark/setup.py +++ b/benchmark/setup.py @@ -1,4 +1,6 @@ -from setuptools import setup, find_packages +from setuptools import find_packages +from setuptools import setup + version = '0.1' @@ -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', ], ) diff --git a/docs/conf.py b/docs/conf.py index 24dd8da1..64f22b9c 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- # # z3c.form documentation build configuration file, created by # sphinx-quickstart on Thu Jan 29 11:31:12 2015. @@ -13,22 +12,24 @@ # All configuration values have a default; values that are commented out # serve to show the default. -import sys import os +import sys + import pkg_resources + sys.path.append(os.path.abspath('../src')) rqmt = pkg_resources.require('z3c.form')[0] # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. -#sys.path.insert(0, os.path.abspath('.')) +# sys.path.insert(0, os.path.abspath('.')) # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. -#needs_sphinx = '1.0' +# needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom @@ -48,7 +49,7 @@ source_suffix = {'.rst': 'restructuredtext'} # The encoding of source files. -#source_encoding = 'utf-8-sig' +# source_encoding = 'utf-8-sig' # The master toctree document. master_doc = 'index' @@ -68,13 +69,13 @@ # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. -#language = None +# language = None # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: -#today = '' +# today = '' # Else, today_fmt is used as the format for a strftime call. -#today_fmt = '%B %d, %Y' +# today_fmt = '%B %d, %Y' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. @@ -82,27 +83,27 @@ # The reST default role (used for this markup: `text`) to use for all # documents. -#default_role = None +# default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. -#add_function_parentheses = True +# add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). -#add_module_names = True +# add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. -#show_authors = False +# show_authors = False # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' # A list of ignored prefixes for module index sorting. -#modindex_common_prefix = [] +# modindex_common_prefix = [] # If true, keep warnings as "system message" paragraphs in the built documents. -#keep_warnings = False +# keep_warnings = False # -- Options for HTML output ---------------------------------------------- @@ -113,77 +114,77 @@ # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. -#html_theme_options = {} +# html_theme_options = {} # Add any paths that contain custom themes here, relative to this directory. -#html_theme_path = [] +# html_theme_path = [] # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". -#html_title = None +# html_title = None # A shorter title for the navigation bar. Default is the same as html_title. -#html_short_title = None +# html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. -#html_logo = None +# html_logo = None # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. -#html_favicon = None +# html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -#html_static_path = ['_static'] +# html_static_path = ['_static'] # Add any extra paths that contain custom files (such as robots.txt or # .htaccess) here, relative to this directory. These files are copied # directly to the root of the documentation. -#html_extra_path = [] +# html_extra_path = [] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. -#html_last_updated_fmt = '%b %d, %Y' +# html_last_updated_fmt = '%b %d, %Y' # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. -#html_use_smartypants = True +# html_use_smartypants = True # Custom sidebar templates, maps document names to template names. -#html_sidebars = {} +# html_sidebars = {} # Additional templates that should be rendered to pages, maps page names to # template names. -#html_additional_pages = {} +# html_additional_pages = {} # If false, no module index is generated. -#html_domain_indices = True +# html_domain_indices = True # If false, no index is generated. -#html_use_index = True +# html_use_index = True # If true, the index is split into individual pages for each letter. -#html_split_index = False +# html_split_index = False # If true, links to the reST sources are added to the pages. -#html_show_sourcelink = True +# html_show_sourcelink = True # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. -#html_show_sphinx = True +# html_show_sphinx = True # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. -#html_show_copyright = True +# html_show_copyright = True # If true, an OpenSearch description file will be output, and all pages will # contain a tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. -#html_use_opensearch = '' +# html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). -#html_file_suffix = None +# html_file_suffix = None # Output file base name for HTML help builder. htmlhelp_basename = 'z3cformdoc' @@ -192,13 +193,13 @@ latex_elements = { # The paper size ('letterpaper' or 'a4paper'). - #'papersize': 'letterpaper', + # 'papersize': 'letterpaper', # The font size ('10pt', '11pt' or '12pt'). - #'pointsize': '10pt', + # 'pointsize': '10pt', # Additional stuff for the LaTeX preamble. - #'preamble': '', + # 'preamble': '', } # Grouping the document tree into LaTeX files. List of tuples @@ -211,23 +212,23 @@ # The name of an image file (relative to this directory) to place at the top of # the title page. -#latex_logo = None +# latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. -#latex_use_parts = False +# latex_use_parts = False # If true, show page references after internal links. -#latex_show_pagerefs = False +# latex_show_pagerefs = False # If true, show URL addresses after external links. -#latex_show_urls = False +# latex_show_urls = False # Documents to append as an appendix to all manuals. -#latex_appendices = [] +# latex_appendices = [] # If false, no module index is generated. -#latex_domain_indices = True +# latex_domain_indices = True # -- Options for manual page output --------------------------------------- @@ -237,7 +238,7 @@ ['Zope Foundation and Contributors'], 1)] # If true, show URL addresses after external links. -#man_show_urls = False +# man_show_urls = False # -- Options for Texinfo output ------------------------------------------- @@ -251,16 +252,16 @@ ] # Documents to append as an appendix to all manuals. -#texinfo_appendices = [] +# texinfo_appendices = [] # If false, no module index is generated. -#texinfo_domain_indices = True +# texinfo_domain_indices = True # How to display URL addresses: 'footnote', 'no', or 'inline'. -#texinfo_show_urls = 'footnote' +# texinfo_show_urls = 'footnote' # If true, do not generate a @detailmenu in the "Top" node's menu. -#texinfo_no_detailmenu = False +# texinfo_no_detailmenu = False # Example configuration for intersphinx: refer to the Python standard library. intersphinx_mapping = { diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..d2bd5213 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,21 @@ +# +# Generated from: +# https://github.com/zopefoundation/meta/tree/master/config/pure-python + +[build-system] +requires = ["setuptools < 74"] +build-backend = "setuptools.build_meta" + +[tool.coverage.run] +branch = true +source = ["z3c.form"] + +[tool.coverage.report] +fail_under = 95 +precision = 2 +ignore_errors = true +show_missing = true +exclude_lines = ["pragma: no cover", "pragma: nocover", "except ImportError:", "raise NotImplementedError", "if __name__ == '__main__':", "self.fail", "raise AssertionError", "raise unittest.Skip"] + +[tool.coverage.html] +directory = "parts/htmlcov" diff --git a/setup.py b/setup.py index 0eea88e1..8a2e894f 100644 --- a/setup.py +++ b/setup.py @@ -53,6 +53,7 @@ def read(*rnames): 'Programming Language :: Python :: 3.10', 'Programming Language :: Python :: 3.11', 'Programming Language :: Python :: 3.12', + 'Programming Language :: Python :: 3.13', 'Programming Language :: Python :: Implementation :: CPython', 'Natural Language :: English', 'Operating System :: OS Independent', diff --git a/tox.ini b/tox.ini index 155aa046..2ccffc29 100644 --- a/tox.ini +++ b/tox.ini @@ -10,6 +10,7 @@ envlist = py310 py311 py312 + py313 docs coverage @@ -18,21 +19,25 @@ usedevelop = true package = wheel wheel_build_env = .pkg deps = - setuptools < 69 + setuptools < 74 zope.testrunner -setenv = - py312: VIRTUALENV_PIP=23.1.2 - py312: PIP_REQUIRE_VIRTUALENV=0 commands = zope-testrunner --test-path=src {posargs:-vc} extras = test +[testenv:setuptools-latest] +basepython = python3 +deps = + git+https://github.com/pypa/setuptools.git\#egg=setuptools + zope.testrunner + [testenv:release-check] description = ensure that the distribution is ready to release basepython = python3 skip_install = true deps = + setuptools < 74 twine build check-manifest @@ -46,23 +51,14 @@ commands = twine check dist/* [testenv:lint] +description = This env runs all linters configured in .pre-commit-config.yaml basepython = python3 skip_install = true deps = - isort - flake8 -commands = - isort --check-only --diff {toxinidir}/src {toxinidir}/setup.py - flake8 src setup.py - -[testenv:isort-apply] -basepython = python3 -skip_install = true + pre-commit commands_pre = -deps = - isort commands = - isort {toxinidir}/src {toxinidir}/setup.py [] + pre-commit run --all-files --show-diff-on-failure [testenv:docs] basepython = python3 @@ -78,29 +74,10 @@ basepython = python3 allowlist_externals = mkdir deps = - coverage + coverage[toml] zope.testrunner commands = mkdir -p {toxinidir}/parts/htmlcov coverage run -m zope.testrunner --test-path=src {posargs:-vc} - coverage html --ignore-errors - coverage report --show-missing --fail-under=95 - -[coverage:run] -branch = True -source = z3c.form - -[coverage:report] -precision = 2 -ignore_errors = True -exclude_lines = - pragma: no cover - pragma: nocover - except ImportError: - raise NotImplementedError - if __name__ == '__main__': - self.fail - raise AssertionError - -[coverage:html] -directory = parts/htmlcov + coverage html + coverage report