diff --git a/.github/workflows/test-publish.yaml b/.github/workflows/test-publish.yaml index 85278799..a1f9b2ca 100644 --- a/.github/workflows/test-publish.yaml +++ b/.github/workflows/test-publish.yaml @@ -9,25 +9,37 @@ jobs: run-tests: env: not_in_conda: "[]" - not_in_aarch64: "['3.5', 'pypy3.7']" + not_in_aarch64: "['3.5']" strategy: matrix: - os: [ubuntu-latest, macos-12, windows-latest] - python-version: ["2.7", "3.5", "3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "pypy3.7"] + os: [ubuntu-latest, macos-latest, windows-latest] + python-version: ["2.7", "3.5", "3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "=3.9[build=*_pypy]"] + exclude: + - os: windows-latest + python-version: "2.7" + - os: macos-latest + python-version: "2.7" + - os: macos-latest + python-version: "3.5" + - os: macos-latest + python-version: "3.6" + - os: macos-latest + python-version: "3.7" + - os: macos-latest + python-version: "=3.9[build=*_pypy]" + - os: windows-latest + python-version: "=3.9[build=*_pypy]" include: - os: ubuntu-latest os-name: Linux pip-cache-path: ~/.cache/pip - - os: macos-12 + - os: macos-latest os-name: MacOS pip-cache-path: ~/Library/Caches/pip - os: windows-latest os-name: w32 pip-cache-path: ~\AppData\Local\pip\Cache - exclude: - - os: windows-latest - python-version: "pypy3.7" name: Python ${{ matrix.python-version }} @ ${{ matrix.os-name }} runs-on: ${{ matrix.os }} @@ -35,9 +47,10 @@ jobs: steps: # Setup Python/pip - uses: actions/checkout@v4 - - uses: s-weigand/setup-conda@v1 + - uses: conda-incubator/setup-miniconda@v3 with: - conda-channels: conda-forge + channels: conda-forge, conda-forge/label/python_rc + miniforge-version: latest python-version: ${{ matrix.python-version }} if: ${{ !contains(fromJSON(env.not_in_conda), matrix.python-version) }} # Python 3.7 is needed for ghactions-release script @@ -55,12 +68,15 @@ jobs: with: python-version: ${{ matrix.python-version }} if: ${{ contains(fromJSON(env.not_in_conda), matrix.python-version) }} + - uses: actions/cache@v3 + with: + path: ~/conda_pkgs_dir + key: ${{ runner.os }}-conda - name: Cache pip uses: actions/cache@v3 with: path: ${{ matrix.pip-cache-path }} key: ${{ runner.os }}-pip - # Setup tox - name: Install dependencies run: | @@ -69,33 +85,35 @@ jobs: python -m pip install --upgrade pip setuptools wheel pip --version pip install --upgrade virtualenv "tox >= 3.15, < 4" + shell: bash -el {0} - name: Set TOXENV run: | + python -c " import os, sys ld_library_path = None if hasattr(sys, 'pypy_version_info'): - toxenv = 'pypy3' + toxenv = 'pypy3' else: - pyver = '%d%d' % tuple(sys.version_info[:2]) - if os.name == 'posix': - if pyver == '27': # Python 2.7 on Linux requires `$LD_LIBRARY_PATH` - ld_library_path = os.path.join( - os.path.dirname(os.path.dirname(sys.executable)), 'lib') - toxenv = 'py%s' % pyver - if os.name == 'posix': - toxenv += ',py%s-flake8' % pyver + pyver = '%d%d' % tuple(sys.version_info[:2]) + if (pyver == '27') and (os.name == 'posix'): # Python 2.7 on Linux requires `$LD_LIBRARY_PATH` + ld_library_path = os.path.join( + os.path.dirname(os.path.dirname(sys.executable)), 'lib') + toxenv = 'py%s' % pyver + if os.name == 'posix': + toxenv += ',py%s-flake8' % pyver with open(os.environ['GITHUB_ENV'], 'a') as f: - if ld_library_path: - f.write('LD_LIBRARY_PATH=' + ld_library_path + '\n') - f.write('TOXENV=' + toxenv + '\n') - print(toxenv) - shell: python + if ld_library_path: + f.write('LD_LIBRARY_PATH=' + ld_library_path + '\n') + f.write('TOXENV=' + toxenv + '\n') + " + shell: bash -el {0} - name: Run tox run: | python -c "import os; print(os.environ['TOXENV'])" tox --version tox + shell: bash -el {0} - name: Build and publish sdist and wheel on Unix run: | diff --git a/Cheetah/ImportManager.py b/Cheetah/ImportManager.py index 67fa7b03..17ab4808 100644 --- a/Cheetah/ImportManager.py +++ b/Cheetah/ImportManager.py @@ -449,6 +449,7 @@ def importHook(self, name, globals=None, locals=None, _self_doimport = self.doimport threaded = self.threaded for context in contexts: + i = 0 ctx = context for i in range(len(nmparts)): nm = nmparts[i] @@ -507,6 +508,7 @@ def importHook(self, name, globals=None, locals=None, def doimport(self, nm, parentnm, fqname): # Not that nm is NEVER a dotted name at this point + mod = None if parentnm: parent = sys.modules[parentnm] if hasattr(parent, '__path__'): @@ -525,7 +527,10 @@ def doimport(self, nm, parentnm, fqname): try: mod = director.getmod(nm) except RecursionError: - mod = __oldimport__(nm) # noqa: F821 undefined name + try: + mod = __oldimport__(nm) # noqa: F821 undefined name + except RecursionError: + pass if mod: break if mod: diff --git a/Cheetah/Tests/SyntaxAndOutput.py b/Cheetah/Tests/SyntaxAndOutput.py index 9d84c8f3..d5dd6900 100755 --- a/Cheetah/Tests/SyntaxAndOutput.py +++ b/Cheetah/Tests/SyntaxAndOutput.py @@ -3072,6 +3072,19 @@ def test1(self): "0") +class MatchObject(OutputTest): + def test1(self): + """re Match objects implement both attribute access and index access; + match[2] is equivalent to match.group(2). + That confuses NameMapper and requires special handling. + """ + self.verify( + r"""#import re +#set $match = re.match(r'(.*)\s(\(\w+\))', 'test (add)') +$match.group(2)""", + "(add)") + + class CGI(OutputTest): """CGI scripts with(out) the CGI environment and with(out) GET variables. """ diff --git a/Cheetah/c/_namemapper.c b/Cheetah/c/_namemapper.c index b7481421..52a9293a 100644 --- a/Cheetah/c/_namemapper.c +++ b/Cheetah/c/_namemapper.c @@ -192,7 +192,10 @@ static PyObject *PyNamemapper_valueForName(PyObject *obj, char *nameChunks[], in } else { #if PY_VERSION_HEX >= 0x030d0000 if ((PyErr_Occurred() != NULL) && - (PyErr_ExceptionMatches(PyExc_TypeError))) { + ( + PyErr_ExceptionMatches(PyExc_IndexError) || + PyErr_ExceptionMatches(PyExc_TypeError) + )) { /* Python 3.13+ don't like testing 'str1'['str2']. The error must be silenced to continue testing getattr('str1', 'str2'). */ diff --git a/SetupConfig.py b/SetupConfig.py index f70b3c3e..ae724d1e 100644 --- a/SetupConfig.py +++ b/SetupConfig.py @@ -61,6 +61,7 @@ Programming Language :: Python :: 3.10 Programming Language :: Python :: 3.11 Programming Language :: Python :: 3.12 + Programming Language :: Python :: 3.13 Topic :: Internet :: WWW/HTTP Topic :: Internet :: WWW/HTTP :: Dynamic Content Topic :: Internet :: WWW/HTTP :: Site Management diff --git a/devscripts/git-hooks/post-checkout b/devscripts/git-hooks/post-checkout index d7f92d4e..4cfcb9cf 100755 --- a/devscripts/git-hooks/post-checkout +++ b/devscripts/git-hooks/post-checkout @@ -10,9 +10,4 @@ if [ "$new_branch" = 1 ]; then # if branch was changed - remove old bytecode files and outdated docs find . -name '*.py[co]' -delete && rm -rf docs/_build/html docs/html -fi && - -python -m compileall -q -x '\.tox/' . && -python -O -m compileall -q -x '\.tox/' . - -exit 0 +fi diff --git a/devscripts/git-hooks/post-merge b/devscripts/git-hooks/post-merge deleted file mode 100755 index 2df0670c..00000000 --- a/devscripts/git-hooks/post-merge +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -# post-merge hook that compiles python files to byte code - -python -m compileall -q -x '\.tox/' . && -python -O -m compileall -q -x '\.tox/' . - -exit 0 diff --git a/devscripts/git-hooks/post-rewrite b/devscripts/git-hooks/post-rewrite deleted file mode 100755 index 59efb3dc..00000000 --- a/devscripts/git-hooks/post-rewrite +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -# post-rewrite hook that compiles python files to byte code - -python -m compileall -q -x '\.tox/' . && -python -O -m compileall -q -x '\.tox/' . - -exit 0 diff --git a/docs/news.rst b/docs/news.rst index f360974c..d821b913 100644 --- a/docs/news.rst +++ b/docs/news.rst @@ -16,17 +16,26 @@ Bug fixes: in ``PyMapping_HasKeyString`` under Python 3.13+ caused by ``_namemapper`` looking up a key in a non-dictionary. + - Fixed ``_namemapper.c``: Silence ``IndexError`` when testing + ``name[attr]``. Some objects like ``re.MatchObject`` implement both + attribute access and index access. This confuses ``NameMapper`` because + it expects ``name[attr]`` to raise ``TypeError`` for objects that don't + implement mapping protocol. + - Fixed mapping test in ``NameMapper.py``: Python 3.13 brough a new mapping type ``FrameLocalsProxy``. + - Fixed another ``RecursionError`` in ``ImportHooks`` under PyPy3. + Tests: - tox: Run tests under Python 3.13. CI: - - GHActions: Temporary run tests on macos-12. See - https://github.com/s-weigand/setup-conda/issues/432 for the reason. + - CI(GHActions): Switch to ``setup-miniconda``. + + - CI(GHActions): Run tests under Python 3.13. 3.3.3.post1 (2024-02-28) ------------------------