From de5fe65c57cb1da51b20a2225ff2f0c3414c959c Mon Sep 17 00:00:00 2001 From: Maurits van Rees Date: Fri, 10 Nov 2023 23:28:23 +0100 Subject: [PATCH 1/4] Replace deprecated cgi.FieldStorage class with a simple one. The ``cgi`` module is deprecated and will be removed in Python 3.13. Instead we now use a simple class that implements only what is needed for the converter. It is only used for converting a ``ZPublisher`` ``FileUpload`` to a ``zope.publisher`` one. --- news/1.bugfix | 3 +++ src/plone/z3cform/converter.py | 19 ++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 news/1.bugfix diff --git a/news/1.bugfix b/news/1.bugfix new file mode 100644 index 0000000..06945d6 --- /dev/null +++ b/news/1.bugfix @@ -0,0 +1,3 @@ +Replace deprecated ``cgi.FieldStorage`` class with a simple one. +This is only used for converting a ``ZPublisher`` ``FileUpload`` to a ``zope.publisher`` one. +[maurits] diff --git a/src/plone/z3cform/converter.py b/src/plone/z3cform/converter.py index e9b353d..60154eb 100644 --- a/src/plone/z3cform/converter.py +++ b/src/plone/z3cform/converter.py @@ -1,10 +1,22 @@ -import cgi import z3c.form.converter import z3c.form.interfaces import zope.publisher.browser import ZPublisher.HTTPRequest +class _SimpleFieldStorage: + """Replacement for cgi.FieldStorage. + + The cgi module is deprecated and will be removed in Python 3.13. + This simple class implements only what is needed for the converter below. + """ + + def __init__(self, value): + self.file = value + self.headers = value.headers + self.filename = value.filename + + class FileUploadDataConverter(z3c.form.converter.FileUploadDataConverter): """Although ZPublisher's and zope.publisher's FileUpload implementations are almost identical, ``FileUploadDataConverter`` @@ -18,10 +30,7 @@ class FileUploadDataConverter(z3c.form.converter.FileUploadDataConverter): def toFieldValue(self, value): """See interfaces.IDataConverter""" if isinstance(value, ZPublisher.HTTPRequest.FileUpload): - fieldstorage = cgi.FieldStorage() - fieldstorage.file = value - fieldstorage.headers = value.headers - fieldstorage.filename = value.filename + fieldstorage = _SimpleFieldStorage(value) value = zope.publisher.browser.FileUpload(fieldstorage) return super().toFieldValue(value) From 9f57faf41b907cb882f215420586c974f59e14d8 Mon Sep 17 00:00:00 2001 From: Maurits van Rees Date: Fri, 10 Nov 2023 23:32:51 +0100 Subject: [PATCH 2/4] dependencychecker: ignore five.pt. We only include its zcml conditionally. --- .meta.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/.meta.toml b/.meta.toml index cf12c85..ff53d60 100644 --- a/.meta.toml +++ b/.meta.toml @@ -10,3 +10,4 @@ check_manifest_ignores = """ "*.cfg", """ codespell_ignores = "fo," +dependencies_ignores = "['five.pt']" From 529e512f456e9de401f5ac0a9d5cdccc5ae470fe Mon Sep 17 00:00:00 2001 From: Maurits van Rees Date: Fri, 10 Nov 2023 23:32:58 +0100 Subject: [PATCH 3/4] Configuring with plone/meta --- .editorconfig | 1 + .github/workflows/meta.yml | 42 +++++++++++++++++++++++++++++++++++++- .gitignore | 4 ++++ .meta.toml | 2 +- .pre-commit-config.yaml | 24 +++++++++++++++------- pyproject.toml | 5 ++++- tox.ini | 31 ++++++++++++++++++++++++++-- 7 files changed, 97 insertions(+), 12 deletions(-) diff --git a/.editorconfig b/.editorconfig index 919b411..8ae05aa 100644 --- a/.editorconfig +++ b/.editorconfig @@ -36,6 +36,7 @@ indent_size = 2 [*.{json,jsonl,js,jsx,ts,tsx,css,less,scss,html}] # Frontend development # 2 space indentation indent_size = 2 +max_line_length = 80 [{Makefile,.gitmodules}] # Tab indentation (no size specified, but view as 4 spaces) diff --git a/.github/workflows/meta.yml b/.github/workflows/meta.yml index a7f25e0..39a164d 100644 --- a/.github/workflows/meta.yml +++ b/.github/workflows/meta.yml @@ -13,6 +13,16 @@ on: - main workflow_dispatch: +## +# To set environment variables for all jobs, add in .meta.toml: +# [github] +# env = """ +# debug: 1 +# image-name: 'org/image' +# image-tag: 'latest' +# """ +## + jobs: qa: uses: plone/meta/.github/workflows/qa.yml@main @@ -22,7 +32,37 @@ jobs: uses: plone/meta/.github/workflows/coverage.yml@main dependencies: uses: plone/meta/.github/workflows/dependencies.yml@main - release-ready: + release_ready: uses: plone/meta/.github/workflows/release_ready.yml@main circular: uses: plone/meta/.github/workflows/circular.yml@main + +## +# To modify the list of default jobs being created add in .meta.toml: +# [github] +# jobs = [ +# "qa", +# "test", +# "coverage", +# "dependencies", +# "release_ready", +# "circular", +# ] +## + +## +# To request that some OS level dependencies get installed +# when running tests/coverage jobs, add in .meta.toml: +# [github] +# os_dependencies = "git libxml2 libxslt" +## + + +## +# Specify additional jobs in .meta.toml: +# [github] +# extra_lines = """ +# another: +# uses: org/repo/.github/workflows/file.yml@main +# """ +## diff --git a/.gitignore b/.gitignore index 81594fd..503e47c 100644 --- a/.gitignore +++ b/.gitignore @@ -6,9 +6,13 @@ *.pyc *.pyo +# translation related +*.mo + # tools related build/ .coverage +.*project coverage.xml dist/ docs/_build diff --git a/.meta.toml b/.meta.toml index ff53d60..011c2c7 100644 --- a/.meta.toml +++ b/.meta.toml @@ -3,7 +3,7 @@ # See the inline comments on how to expand/tweak this configuration file [meta] template = "default" -commit-id = "cfffba8c" +commit-id = "8c30aa23" [pyproject] check_manifest_ignores = """ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7de9fd7..f13d059 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,7 +7,7 @@ ci: repos: - repo: https://github.com/asottile/pyupgrade - rev: v3.4.0 + rev: v3.15.0 hooks: - id: pyupgrade args: [--py38-plus] @@ -16,11 +16,11 @@ repos: hooks: - id: isort - repo: https://github.com/psf/black - rev: 23.3.0 + rev: 23.10.1 hooks: - id: black - repo: https://github.com/collective/zpretty - rev: 3.1.0a2 + rev: 3.1.0 hooks: - id: zpretty @@ -32,7 +32,7 @@ repos: # """ ## - repo: https://github.com/PyCQA/flake8 - rev: 6.0.0 + rev: 6.1.0 hooks: - id: flake8 @@ -44,7 +44,7 @@ repos: # """ ## - repo: https://github.com/codespell-project/codespell - rev: v2.2.4 + rev: v2.2.6 hooks: - id: codespell additional_dependencies: @@ -66,15 +66,25 @@ repos: hooks: - id: pyroma - repo: https://github.com/mgedmin/check-python-versions - rev: "0.21.2" + rev: "0.22.0" hooks: - id: check-python-versions args: ['--only', 'setup.py,pyproject.toml'] - repo: https://github.com/collective/i18ndude - rev: "6.0.0" + rev: "6.1.0" hooks: - id: i18ndude + +## +# Add extra configuration options in .meta.toml: +# [pre_commit] +# i18ndude_extra_lines = """ +# _your own configuration lines_ +# """ +## + + ## # Add extra configuration options in .meta.toml: # [pre_commit] diff --git a/pyproject.toml b/pyproject.toml index eb8b561..3574669 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,9 @@ # Generated from: # https://github.com/plone/meta/tree/master/config/default # See the inline comments on how to expand/tweak this configuration file +[build-system] +requires = ["setuptools>=68.2"] + [tool.towncrier] directory = "news/" filename = "CHANGES.rst" @@ -116,6 +119,7 @@ Zope = [ 'Products.CMFCore', 'Products.CMFDynamicViewFTI', ] python-dateutil = ['dateutil'] +ignore-packages = ['five.pt'] ## # Add extra configuration options in .meta.toml: @@ -125,7 +129,6 @@ python-dateutil = ['dateutil'] # "gitpython = ['git']", # "pygithub = ['github']", # ] -# """ ## [tool.check-manifest] diff --git a/tox.ini b/tox.ini index 85aeefd..8fa4d62 100644 --- a/tox.ini +++ b/tox.ini @@ -32,6 +32,21 @@ commands = echo "Unrecognized environment name {envname}" false +## +# Add extra configuration options in .meta.toml: +# [tox] +# testenv_options = """ +# basepython = /usr/bin/python3.8 +# """ +## + +[testenv:init] +description = Prepare environment +skip_install = true +commands = + echo "Initial setup complete" + + [testenv:format] description = automatically reformat code skip_install = true @@ -58,7 +73,7 @@ deps = build z3c.dependencychecker==2.11 commands = - python -m build --sdist --no-isolation + python -m build --sdist dependencychecker [testenv:dependencies-graph] @@ -86,11 +101,20 @@ set_env = # test_environment_variables = """ # PIP_EXTRA_INDEX_URL=https://my-pypi.my-server.com/ # """ +# +# Set constrain_package_deps .meta.toml: +# [tox] +# constrain_package_deps = "false" ## deps = zope.testrunner -c https://dist.plone.org/release/6.0-dev/constraints.txt + ## +# Specify additional deps in .meta.toml: +# [tox] +# test_deps_additional = "-esources/plonegovbr.portal_base[test]" +# # Specify a custom constraints file in .meta.toml: # [tox] # constraints_file = "https://my-server.com/constraints.txt" @@ -128,6 +152,7 @@ deps = coverage zope.testrunner -c https://dist.plone.org/release/6.0-dev/constraints.txt + commands = coverage run --branch --source plone.z3cform {envbindir}/zope-testrunner --quiet --all --test-path={toxinidir}/src -s plone.z3cform {posargs} coverage report -m --format markdown @@ -144,12 +169,13 @@ deps = build towncrier -c https://dist.plone.org/release/6.0-dev/constraints.txt + commands = # fake version to not have to install the package # we build the change log as news entries might break # the README that is displayed on PyPI towncrier build --version=100.0.0 --yes - python -m build --sdist --no-isolation + python -m build --sdist twine check dist/* [testenv:circular] @@ -171,6 +197,7 @@ deps = pipdeptree pipforester -c https://dist.plone.org/release/6.0-dev/constraints.txt + commands = # Generate the full dependency tree sh -c 'pipdeptree -j > forest.json' From 4cb94be46ae49bc72812231d3804c38956f75072 Mon Sep 17 00:00:00 2001 From: Maurits van Rees Date: Fri, 10 Nov 2023 23:34:36 +0100 Subject: [PATCH 4/4] codespell: re-use -> reuse --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 17a029c..beca017 100644 --- a/README.rst +++ b/README.rst @@ -125,7 +125,7 @@ There are a few other reasons why you may want to use the wrapper view, even in later versions of Zope: * To support both an earlier version of Zope and Zope 2.12+ -* To re-use the same form in multiple views or viewlets +* To reuse the same form in multiple views or viewlets * To use the ``IPageTemplate`` adapter lookup semantics from z3c.form to provide a different default or override template for the overall page layout, while retaining (or indeed customising independently) the default