Skip to content

ci: Add support for testing Python 3.12-3.14 #331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@ jobs:

runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11-dev"]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14-dev"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install pip==20.0.2
pip install pip==25.1.0
pip install -r requirements.txt
python setup.py bdist_wheel
python -m build --wheel
pip install dist/*.whl
- name: Test with pytest
run: |
cd tests/ && py.test --cov jmespath --cov-report term-missing
cd tests/ && python -m pytest --cov jmespath --cov-report term-missing
14 changes: 11 additions & 3 deletions jmespath/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

"""
import random
import threading

from jmespath import lexer
from jmespath.compat import with_repr_method
Expand Down Expand Up @@ -74,6 +75,7 @@ class Parser(object):
# _CACHE dict.
_CACHE = {}
_MAX_SIZE = 128
_CACHE_LOCK = threading.Lock()

def __init__(self, lookahead=2):
self.tokenizer = None
Expand All @@ -87,7 +89,7 @@ def parse(self, expression):
return cached
parsed_result = self._do_parse(expression)
self._CACHE[expression] = parsed_result
if len(self._CACHE) > self._MAX_SIZE:
if self._is_cache_full():
self._free_cache_entries()
return parsed_result

Expand Down Expand Up @@ -488,9 +490,15 @@ def _raise_parse_error_maybe_eof(self, expected_type, token):
raise exceptions.ParseError(
lex_position, actual_value, actual_type, message)

def _is_cache_full(self):
return len(self._CACHE) > self._MAX_SIZE

def _free_cache_entries(self):
for key in random.sample(list(self._CACHE.keys()), int(self._MAX_SIZE / 2)):
self._CACHE.pop(key, None)
with self._CACHE_LOCK:
if self._is_cache_full():
cache_keys = list(self._CACHE.keys())
for key in random.sample(cache_keys, int(len(cache_keys)/2)):
self._CACHE.pop(key, None)

@classmethod
def purge(cls):
Expand Down
13 changes: 8 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
wheel==0.38.1
pytest==6.2.5
wheel==0.45.1
pytest==8.4.1
pytest-cov==3.0.0
hypothesis==3.1.0 ; python_version < '3.8'
hypothesis==5.5.4 ; python_version == '3.8'
hypothesis==5.35.4 ; python_version == '3.9'
hypothesis==5.35.4

# Setuptools is no longer provided by default in Python 3.12+
setuptools==71.1.0 ; python_version >= '3.12'
packaging==24.1 ; python_version >= '3.12'
build==1.2.2.post1
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,20 @@
scripts=['bin/jp.py'],
packages=find_packages(exclude=['tests']),
license='MIT',
python_requires='>=3.7',
python_requires='>=3.9',
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'Natural Language :: English',
'License :: OSI Approved :: MIT 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 :: 3.14',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
],
Expand Down
16 changes: 3 additions & 13 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
[tox]
envlist = py26,py27,py33,py34,py35,py36,py37,pypy
envlist = py39,py310,py311,py312,py313,py314

[testenv]
commands = nosetests
commands = python -m pytest tests
deps =
nose
mock

[testenv:py26]
commands = nosetests
deps =
nose
mock
unittest2
ordereddict
simplejson
pytest