Skip to content

Commit

Permalink
Allow to use the package with Python 3.11. (#223)
Browse files Browse the repository at this point in the history
Caution: No security audit has been done so far as Python 3.11 does not
have a final version, yet.

This commit is a quick hack to get tests running:

Python 3.11 requires coverage >= 6 which is not supported by
coverage-python-version, so we cannot use it any longer resulting
in a drop of the coverage as Python 2 compatibility code no longer
gets excluded from coverage.

The only sane way to fix this mess is to drop Python 2 support.
  • Loading branch information
Michael Howitz committed Apr 13, 2022
1 parent ac81a60 commit e034c2f
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 28 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Expand Up @@ -29,6 +29,7 @@ jobs:
- ["3.8", "py38"]
- ["3.9", "py39"]
- ["3.10", "py310"]
- ["3.11.0-alpha.6", "py311"]
- ["3.9", "docs"]
- ["3.9", "coverage"]
- ["3.9", "py39-datetime"]
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -28,4 +28,5 @@ lib64
log/
parts/
pyvenv.cfg
testing.log
var/
6 changes: 2 additions & 4 deletions .meta.toml
Expand Up @@ -2,15 +2,15 @@
# https://github.com/zopefoundation/meta/tree/master/config/pure-python
[meta]
template = "pure-python"
commit-id = "886173bf647a6e80a985544c32053c932b1949e2"
commit-id = "3a251aab94eff9cf2aa2fd87d7266593251e4b76"

[python]
with-pypy = false
with-legacy-python = true
with-docs = true
with-sphinx-doctests = true
with-windows = true
with-future-python = false
with-future-python = true

[tox]
use-flake8 = true
Expand Down Expand Up @@ -41,8 +41,6 @@ testenv-additional = [
"deps =",
" coverage",
" coverage-python-version",
" # Until repoze.sphinx.autointerface supports Sphinx 4.x we cannot use it:",
" Sphinx < 4",
" -cconstraints.txt",
"setenv =",
" COVERAGE_FILE=.coverage",
Expand Down
3 changes: 2 additions & 1 deletion CHANGES.rst
Expand Up @@ -4,7 +4,8 @@ Changes
5.3 (unreleased)
----------------

- Nothing changed yet.
- Allow to use the package with Python 3.11 -- Caution: No security audit has
been done so far.


5.2 (2021-11-19)
Expand Down
23 changes: 23 additions & 0 deletions CONTRIBUTING.md
@@ -0,0 +1,23 @@
<!--
Generated from:
https://github.com/zopefoundation/meta/tree/master/config/pure-python
-->
# Contributing to zopefoundation projects

The projects under the zopefoundation GitHub organization are open source and
welcome contributions in different forms:

* bug reports
* code improvements and bug fixes
* documentation improvements
* pull request reviews

For any changes in the repository besides trivial typo fixes you are required
to sign the contributor agreement. See
https://www.zope.dev/developer/becoming-a-committer.html for details.

Please visit our [Developer
Guidelines](https://www.zope.dev/developer/guidelines.html) if you'd like to
contribute code changes and our [guidelines for reporting
bugs](https://www.zope.dev/developer/reporting-bugs.html) if you want to file a
bug report.
1 change: 1 addition & 0 deletions MANIFEST.in
@@ -1,5 +1,6 @@
# Generated from:
# https://github.com/zopefoundation/meta/tree/master/config/pure-python
include *.md
include *.rst
include *.txt
include buildout.cfg
Expand Down
9 changes: 6 additions & 3 deletions constraints.txt
Expand Up @@ -3,8 +3,11 @@
# Pin Versions / Version Ranges if necessary.
isort >= 4.3.2
# Needed for Appveyor as long as PY2 is supported:
pytest < 5
pytest-html < 2
pytest < 5 ; python_version < '3.11'
# Python 3.11 needs pytest > 5
pytest >= 5 ; python_version >= '3.11'
# coverage 6+ no longer supports Python 2 and coverage results of older
# versions cannot not combined with newer ones:
coverage < 6
coverage < 6; python_version < '3.11'
# Python 3.11 requires coverage >= 6,
coverage >= 6; python_version >= '3.11'
11 changes: 11 additions & 0 deletions setup.cfg
Expand Up @@ -19,3 +19,14 @@ ignore =
docs/_build/html/_sources/roadmap/*
docs/_build/html/_sources/upgrade_dependencies/*
docs/_build/html/_sources/usage/*

[isort]
force_single_line = True
combine_as_imports = True
sections = FUTURE,STDLIB,THIRDPARTY,ZOPE,FIRSTPARTY,LOCALFOLDER
known_third_party = six, docutils, pkg_resources
known_zope =
known_first_party =
default_section = ZOPE
line_length = 79
lines_after_imports = 2
6 changes: 3 additions & 3 deletions setup.py
Expand Up @@ -13,11 +13,11 @@
##############################################################################
"""Setup for RestrictedPython package"""

import os

from setuptools import find_packages
from setuptools import setup

import os


def read(*rnames):
with open(os.path.join(os.path.dirname(__file__), *rnames)) as f:
Expand Down Expand Up @@ -70,7 +70,7 @@ def read(*rnames):
package_dir={'': 'src'},
install_requires=[
],
python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <3.11", # NOQA: E501
python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <3.12", # NOQA: E501
tests_require=tests_require,
extras_require={
'test': tests_require,
Expand Down
4 changes: 2 additions & 2 deletions src/RestrictedPython/Eval.py
Expand Up @@ -12,11 +12,11 @@
##############################################################################
"""Restricted Python Expressions."""

import ast

from ._compat import IS_PY2
from .compile import compile_restricted_eval

import ast


if IS_PY2: # pragma: PY2
from string import maketrans
Expand Down
6 changes: 3 additions & 3 deletions src/RestrictedPython/compile.py
@@ -1,11 +1,11 @@
import ast
import warnings
from collections import namedtuple

from RestrictedPython._compat import IS_CPYTHON
from RestrictedPython._compat import IS_PY2
from RestrictedPython.transformer import RestrictingNodeTransformer

import ast
import warnings


CompileResult = namedtuple(
'CompileResult', 'code, errors, warnings, used_names')
Expand Down
8 changes: 4 additions & 4 deletions src/RestrictedPython/transformer.py
Expand Up @@ -22,16 +22,16 @@
# http://docs.plone.org/develop/styleguide/python.html


import ast
import contextlib
import textwrap

from ._compat import IS_PY2
from ._compat import IS_PY3
from ._compat import IS_PY34_OR_GREATER
from ._compat import IS_PY35_OR_GREATER
from ._compat import IS_PY38_OR_GREATER

import ast
import contextlib
import textwrap


# For AugAssign the operator must be converted to a string.
IOPERATOR_TO_STR = {
Expand Down
24 changes: 16 additions & 8 deletions tox.ini
Expand Up @@ -11,6 +11,7 @@ envlist =
py38
py39
py310
py311
docs
coverage
py39-datetime
Expand All @@ -22,7 +23,7 @@ deps =
datetime: DateTime
-cconstraints.txt
pytest-cov
coverage-python-version
!py311: coverage-python-version
setenv =
COVERAGE_FILE=.coverage.{envname}
commands =
Expand All @@ -41,8 +42,6 @@ allowlist_externals =
deps =
coverage
coverage-python-version
# Until repoze.sphinx.autointerface supports Sphinx 4.x we cannot use it:
Sphinx < 4
-cconstraints.txt
setenv =
COVERAGE_FILE=.coverage
Expand All @@ -56,15 +55,25 @@ depends = py27,py35,py36,py37,py38,py39,py39-datetime,py310,coverage
[testenv:lint]
basepython = python3
skip_install = true
commands =
isort --check-only --diff {toxinidir}/src {toxinidir}/setup.py
flake8 src setup.py
check-manifest
check-python-versions
deps =
flake8
check-manifest
check-python-versions >= 0.19.1
wheel
flake8
isort

[testenv:isort-apply]
basepython = python3
commands_pre =
deps =
isort
commands =
flake8 src setup.py
check-manifest
check-python-versions
isort {toxinidir}/src {toxinidir}/setup.py []

[testenv:docs]
basepython = python3
Expand Down Expand Up @@ -96,7 +105,6 @@ commands =

[coverage:run]
branch = True
plugins = coverage_python_version
source = RestrictedPython

[coverage:report]
Expand Down

0 comments on commit e034c2f

Please sign in to comment.