From 6c451a8f8792c32f8afc06b6088640c4baba6685 Mon Sep 17 00:00:00 2001 From: Michael Howitz Date: Thu, 13 Feb 2025 11:10:43 +0100 Subject: [PATCH 1/4] Drop support for Python 3.7, 3.8. --- CHANGES.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 3d7f7ea..c15791a 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,7 +5,7 @@ 5.2 (unreleased) ================ -- Nothing changed yet. +- Drop support for Python 3.7, 3.8. 5.1 (2024-02-08) From c160e7f8b801a5964e489bfb85b6f8e8cc461069 Mon Sep 17 00:00:00 2001 From: Michael Howitz Date: Thu, 13 Feb 2025 11:10:43 +0100 Subject: [PATCH 2/4] Add support for Python 3.13. --- CHANGES.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index c15791a..4e9ecd1 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,6 +5,8 @@ 5.2 (unreleased) ================ +- Add support for Python 3.13. + - Drop support for Python 3.7, 3.8. From 49d352b0589bc189bb9474b0541f1872c736f17d Mon Sep 17 00:00:00 2001 From: Michael Howitz Date: Thu, 13 Feb 2025 11:12:19 +0100 Subject: [PATCH 3/4] Configuring for pure-python --- .github/workflows/pre-commit.yml | 36 ++++++++++++++++++++++ .github/workflows/tests.yml | 30 +++++++++++------- .meta.toml | 2 +- .pre-commit-config.yaml | 28 +++++++++++++++++ CONTRIBUTING.md | 2 +- MANIFEST.in | 1 + pyproject.toml | 21 +++++++++++++ setup.cfg | 2 -- tox.ini | 53 +++++++++----------------------- 9 files changed, 122 insertions(+), 53 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 0000000..ff77ae6 --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,36 @@ +# 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: + permissions: + contents: read + pull-requests: write + 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@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd #v3.0.1 + with: + extra_args: --all-files --show-diff-on-failure + env: + PRE_COMMIT_COLOR: always + - uses: pre-commit-ci/lite-action@5d6cc0eb514c891a40562a58a8e71576c5c7fb43 #v1.1.0 + if: always() + with: + msg: Apply pre-commit code formatting diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 69b6494..0a7f136 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,35 +12,39 @@ on: jobs: build: + permissions: + contents: read + pull-requests: write strategy: # We want to see all failures: fail-fast: false matrix: os: - - ["ubuntu", "ubuntu-20.04"] + - ["ubuntu", "ubuntu-latest"] config: # [Python version, tox env] - - ["3.9", "release-check"] - - ["3.9", "lint"] - - ["3.7", "py37"] - - ["3.8", "py38"] - - ["3.9", "py39"] - - ["3.10", "py310"] - - ["3.11", "py311"] - - ["3.12", "py312"] + - ["3.11", "release-check"] + - ["3.9", "py39"] + - ["3.10", "py310"] + - ["3.11", "py311"] + - ["3.12", "py312"] + - ["3.13", "py313"] - ["pypy-3.10", "pypy3"] - - ["3.9", "docs"] - - ["3.9", "coverage"] + - ["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 name: ${{ matrix.config[1] }} steps: - uses: actions/checkout@v4 + with: + persist-credentials: false - name: Set up Python uses: actions/setup-python@v5 with: python-version: ${{ matrix.config[0] }} + allow-prereleases: true - name: Pip cache uses: actions/cache@v4 with: @@ -54,7 +58,11 @@ jobs: python -m pip install --upgrade pip pip install tox - name: Test + if: ${{ !startsWith(runner.os, 'Mac') }} run: tox -e ${{ matrix.config[1] }} + - name: Test (macOS) + if: ${{ startsWith(runner.os, 'Mac') }} + run: tox -e ${{ matrix.config[1] }}-universal2 - name: Coverage if: matrix.config[1] == 'coverage' run: | diff --git a/.meta.toml b/.meta.toml index 19bb029..20ea499 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 = "17113b94" +commit-id = "18bd2267" [python] with-pypy = true diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..55afc3d --- /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: "6.0.0" + hooks: + - id: isort + - repo: https://github.com/hhatto/autopep8 + rev: "v2.3.2" + hooks: + - id: autopep8 + args: [--in-place, --aggressive, --aggressive] + - repo: https://github.com/asottile/pyupgrade + rev: v3.19.1 + hooks: + - id: pyupgrade + args: [--py39-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/CONTRIBUTING.md b/CONTRIBUTING.md index 31d95f0..0ab12fe 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,7 +1,7 @@ +--> # Contributing to zopefoundation projects The projects under the zopefoundation GitHub organization are open source and diff --git a/MANIFEST.in b/MANIFEST.in index 5c34d98..d1584aa 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/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..12b0848 --- /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 <= 75.6.0"] +build-backend = "setuptools.build_meta" + +[tool.coverage.run] +branch = true +source = ["zope.pagetemplate"] + +[tool.coverage.report] +fail_under = 98 +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.cfg b/setup.cfg index 8d3ae24..044981d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,7 +1,5 @@ # Generated from: # https://github.com/zopefoundation/meta/tree/master/config/pure-python -[bdist_wheel] -universal = 0 [flake8] doctests = 1 diff --git a/tox.ini b/tox.ini index e82e8ce..5e5b1d7 100644 --- a/tox.ini +++ b/tox.ini @@ -5,12 +5,11 @@ minversion = 3.18 envlist = release-check lint - py37 - py38 py39 py310 py311 py312 + py313 pypy3 docs coverage @@ -20,9 +19,7 @@ usedevelop = true package = wheel wheel_build_env = .pkg deps = -setenv = - py312: VIRTUALENV_PIP=23.1.2 - py312: PIP_REQUIRE_VIRTUALENV=0 + setuptools <= 75.6.0 commands = zope-testrunner --test-path=src {posargs:-vc} sphinx-build -b doctest -d {envdir}/.cache/doctrees docs {envdir}/.cache/doctest @@ -30,11 +27,18 @@ extras = test docs untrusted + +[testenv:setuptools-latest] +basepython = python3 +deps = + git+https://github.com/pypa/setuptools.git\#egg=setuptools + [testenv:release-check] description = ensure that the distribution is ready to release basepython = python3 skip_install = true deps = + setuptools <= 75.6.0 twine build check-manifest @@ -48,23 +52,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 @@ -79,28 +74,10 @@ basepython = python3 allowlist_externals = mkdir deps = - coverage + coverage[toml] commands = mkdir -p {toxinidir}/parts/htmlcov coverage run -m zope.testrunner --test-path=src {posargs:-vc} coverage run -a -m sphinx -b doctest -d {envdir}/.cache/doctrees docs {envdir}/.cache/doctest - coverage html --ignore-errors - coverage report --ignore-errors --show-missing --fail-under=98 - -[coverage:run] -branch = True -source = zope.pagetemplate - -[coverage:report] -precision = 2 -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 From beece95085a8462946a5dcdb82f74c570ce53b53 Mon Sep 17 00:00:00 2001 From: Michael Howitz Date: Thu, 13 Feb 2025 11:12:47 +0100 Subject: [PATCH 4/4] Update Python version support. --- docs/conf.py | 118 +++++++++++---------- setup.py | 7 +- src/zope/pagetemplate/engine.py | 4 +- src/zope/pagetemplate/pagetemplate.py | 2 +- src/zope/pagetemplate/tests/test_engine.py | 2 +- src/zope/pagetemplate/tests/test_ptfile.py | 6 +- 6 files changed, 72 insertions(+), 67 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index eb480a9..e547541 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- # # zope.index documentation build configuration file, created by # sphinx-quickstart on Thu Jan 29 11:31:12 2015. @@ -13,21 +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('zope.pagetemplate')[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 @@ -47,7 +49,7 @@ source_suffix = '.rst' # The encoding of source files. -#source_encoding = 'utf-8-sig' +# source_encoding = 'utf-8-sig' # The master toctree document. master_doc = 'index' @@ -67,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. @@ -81,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 +115,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 = 'zopepagetemplatedoc' @@ -192,43 +194,43 @@ # -- Options for LaTeX output --------------------------------------------- latex_elements = { -# The paper size ('letterpaper' or 'a4paper'). -#'papersize': 'letterpaper', + # The paper size ('letterpaper' or 'a4paper'). + # 'papersize': 'letterpaper', -# The font size ('10pt', '11pt' or '12pt'). -#'pointsize': '10pt', + # The font size ('10pt', '11pt' or '12pt'). + # 'pointsize': '10pt', -# Additional stuff for the LaTeX preamble. -#'preamble': '', + # Additional stuff for the LaTeX preamble. + # 'preamble': '', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - ('index', 'zopeindex.tex', 'zope.pagetemplate Documentation', - 'Zope Foundation and Contributors', 'manual'), + ('index', 'zopeindex.tex', 'zope.pagetemplate Documentation', + 'Zope Foundation and Contributors', 'manual'), ] # 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 --------------------------------------- @@ -241,7 +243,7 @@ ] # If true, show URL addresses after external links. -#man_show_urls = False +# man_show_urls = False # -- Options for Texinfo output ------------------------------------------- @@ -250,22 +252,26 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - ('index', 'zopepagetemplate', 'zope.pagetemplate Documentation', - 'Zope Foundation and Contributors', 'zopepagetemplate', 'One line description of project.', - 'Miscellaneous'), + ('index', + 'zopepagetemplate', + 'zope.pagetemplate Documentation', + 'Zope Foundation and Contributors', + 'zopepagetemplate', + 'One line description of project.', + 'Miscellaneous'), ] # 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. diff --git a/setup.py b/setup.py index ad4ef31..9e0c672 100644 --- a/setup.py +++ b/setup.py @@ -55,12 +55,11 @@ def read(*rnames): 'License :: OSI Approved :: Zope Public License', 'Programming Language :: Python', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9', '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', 'Programming Language :: Python :: Implementation :: PyPy', 'Natural Language :: English', @@ -69,11 +68,11 @@ def read(*rnames): 'Framework :: Zope :: 3', ], url='https://github.com/zopefoundation/zope.pagetemplate', - license='ZPL 2.1', + license='ZPL-2.1', packages=find_packages('src'), package_dir={'': 'src'}, namespace_packages=['zope'], - python_requires='>=3.7', + python_requires='>=3.9', extras_require={ 'test': TESTS_REQUIRE, 'untrusted': [ diff --git a/src/zope/pagetemplate/engine.py b/src/zope/pagetemplate/engine.py index 9b61498..b717a32 100644 --- a/src/zope/pagetemplate/engine.py +++ b/src/zope/pagetemplate/engine.py @@ -43,7 +43,7 @@ def guarded_getitem(ob, index): return ob[index] guarded_getitem = ProxyFactory(guarded_getitem) HAVE_UNTRUSTED = True -except ImportError: # pragma: no cover +except ModuleNotFoundError: # pragma: no cover HAVE_UNTRUSTED = False # PyPy doesn't support assigning to '__builtins__', even when using eval() @@ -509,7 +509,7 @@ class TraversableModuleImporter(SimpleModuleImporter): def traverse(self, name, further_path): try: return self[name] - except ImportError: + except ModuleNotFoundError: raise TraversalError(self, name) diff --git a/src/zope/pagetemplate/pagetemplate.py b/src/zope/pagetemplate/pagetemplate.py index 9c875ec..fc9c793 100644 --- a/src/zope/pagetemplate/pagetemplate.py +++ b/src/zope/pagetemplate/pagetemplate.py @@ -243,7 +243,7 @@ def _cook(self): try: self._v_errors = [ "Compilation failed", - "{}.{}: {}".format(etype.__module__, etype.__name__, e) + f"{etype.__module__}.{etype.__name__}: {e}" ] finally: del e diff --git a/src/zope/pagetemplate/tests/test_engine.py b/src/zope/pagetemplate/tests/test_engine.py index cd5371c..ced592c 100644 --- a/src/zope/pagetemplate/tests/test_engine.py +++ b/src/zope/pagetemplate/tests/test_engine.py @@ -116,7 +116,7 @@ def test_evaluate_error(self): def test_evaluate_interpreter_not_importable(self): ctx = self._makeOne() ctx.evaluateInlineCode = True - with self.assertRaises(ImportError): + with self.assertRaises(ModuleNotFoundError): ctx.evaluateCode('lang', 'code') def test_evaluate_interpreter_not_found(self): diff --git a/src/zope/pagetemplate/tests/test_ptfile.py b/src/zope/pagetemplate/tests/test_ptfile.py index 7e62111..5cd2f27 100644 --- a/src/zope/pagetemplate/tests/test_ptfile.py +++ b/src/zope/pagetemplate/tests/test_ptfile.py @@ -141,7 +141,7 @@ def test_html_default_encoding(self): b"\xd0\xa2\xd0\xb5\xd1\x81\xd1\x82" b"") rendered = pt() - self.assertTrue(isinstance(rendered, str)) + self.assertIsInstance(rendered, str) self.assertEqual(rendered.strip(), ("" "\u0422\u0435\u0441\u0442" @@ -156,7 +156,7 @@ def test_html_encoding_by_meta(self): b' content="text/html; charset=windows-1251">' b"</head></html>") rendered = pt() - self.assertTrue(isinstance(rendered, str)) + self.assertIsInstance(rendered, str) self.assertEqual(rendered.strip(), ("<html><head><title>" "\u0422\u0435\u0441\u0442" @@ -171,7 +171,7 @@ def test_xhtml(self): b' content="text/html; charset=windows-1251"/>' b"</head></html>") rendered = pt() - self.assertTrue(isinstance(rendered, str)) + self.assertIsInstance(rendered, str) self.assertEqual(rendered.strip(), ("<html><head><title>" "\u0422\u0435\u0441\u0442"