Skip to content

Commit f046223

Browse files
authored
Merge pull request #144 from danthedeckie/1.0.0
1.0.0 - Time for a new updated release, and call this iteration stable.
2 parents 2a12b58 + 0fe45bb commit f046223

File tree

9 files changed

+220
-105
lines changed

9 files changed

+220
-105
lines changed

Diff for: .github/workflows/ci.yml

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Codecov
1+
name: CI
22
on: [push]
33
jobs:
44
lint:
@@ -18,7 +18,14 @@ jobs:
1818
strategy:
1919
matrix:
2020
os: [ubuntu-latest, windows-latest]
21-
python: ['2.7', '3.7', '3.8', '3.9', '3.10', '3.11', '3.12-dev', 'pypy-3.8']
21+
python:
22+
- '3.9'
23+
- '3.10'
24+
- '3.11'
25+
- '3.12'
26+
- '3.13'
27+
- 'pypy-3.9'
28+
- 'pypy-3.10'
2229
env:
2330
OS: ${{ matrix.os }}
2431
PYTHON: ${{ matrix.python }}
@@ -29,13 +36,16 @@ jobs:
2936
uses: actions/setup-python@master
3037
with:
3138
python-version: ${{ matrix.python }}
39+
allow-prereleases: true
40+
3241
- name: Generate Report
3342
run: |
3443
pip install coverage
3544
coverage run -m test_simpleeval
3645
coverage xml
3746
- name: Upload to codecov
38-
uses: codecov/codecov-action@v2
47+
uses: codecov/codecov-action@v4.0.1
3948
with:
4049
files: coverage.xml
50+
token: ${{ secrets.CODECOV_TOKEN }}
4151
verbose: true

Diff for: LICENCE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
simpleeval - Copyright (c) 2013-2017 Daniel Fairhead
1+
simpleeval - Copyright (c) 2013-2024 Daniel Fairhead
22

33
(MIT Licence)
44

Diff for: Makefile

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
test:
2-
python test_simpleeval.py
2+
python -Werror test_simpleeval.py
33

44
autotest:
55
find . -name \*.py -not -path .\/.v\* | entr make test
@@ -22,11 +22,10 @@ coverage:
2222
coverage run test_simpleeval.py
2323

2424
lint:
25-
black --check --diff simpleeval.py test_simpleeval.py
26-
isort --check-only --diff simpleeval.py test_simpleeval.py
27-
pylint simpleeval.py test_simpleeval.py
25+
ruff check simpleeval.py test_simpleeval.py
26+
ruff format --check simpleeval.py test_simpleeval.py
2827
mypy simpleeval.py test_simpleeval.py
2928

3029
format:
31-
black simpleeval.py test_simpleeval.py
32-
isort simpleeval.py test_simpleeval.py
30+
ruff check --fix-only simpleeval.py test_simpleeval.py
31+
ruff format simpleeval.py test_simpleeval.py

Diff for: README.rst

+52-23
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
simpleeval (Simple Eval)
22
========================
33

4-
.. image:: https://github.com/danthedeckie/simpleeval/actions/workflows/ci.yml/badge.svg?branch=gh-actions-build
4+
.. |build-status| image:: https://github.com/danthedeckie/simpleeval/actions/workflows/ci.yml/badge.svg?branch=gh-actions-build
55
:target: https://github.com/danthedeckie/simpleeval/actions/
66
:alt: Build Status
77

8-
.. image:: https://codecov.io/gh/danthedeckie/simpleeval/branch/master/graph/badge.svg?token=isRnN1yrca
8+
.. |code-coverage| image:: https://codecov.io/gh/danthedeckie/simpleeval/branch/master/graph/badge.svg?token=isRnN1yrca
99
:target: https://codecov.io/gh/danthedeckie/simpleeval
10-
:alt: Code Coverage
10+
:alt: Code Coverage Status
1111

12-
.. image:: https://badge.fury.io/py/simpleeval.svg
12+
.. |pypi-version| image:: https://badge.fury.io/py/simpleeval.svg
1313
:target: https://badge.fury.io/py/simpleeval
1414
:alt: PyPI Version
1515

16-
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
17-
:target: https://github.com/psf/black
16+
.. |python-versions| image:: https://img.shields.io/badge/python-3.9_%7C_3.10_%7C_3.11_%7C_3.12_%7C_3.13_%7C_PyPy3.9_%7C_PyPy3.10-blue
17+
:alt: Static Badge
1818

19-
.. image:: https://img.shields.io/badge/linting-pylint-yellowgreen
20-
:target: https://github.com/PyCQA/pylint
19+
.. |pypi-monthly-downloads| image:: https://img.shields.io/pypi/dm/SimpleEval
20+
:alt: PyPI - Downloads
21+
22+
.. |formatting-with-ruff| image:: https://img.shields.io/badge/-ruff-black?logo=lightning&logoColor=%2300ff00&link=https%3A%2F%2Fdocs.astral.sh%2Fruff%2F
23+
:alt: Static Badge
24+
25+
|build-status| |code-coverage| |pypi-version| |python-versions| |pypi-monthly-downloads| |formatting-with-ruff|
2126

2227

2328
A single file library for easily adding evaluatable expressions into
@@ -157,7 +162,7 @@ The ``^`` operator is often mistaken for a exponent operator, not the bitwise
157162
operation that it is in python, so if you want ``3 ^ 2`` to equal ``9``, you can
158163
replace the operator like this:
159164

160-
.. code-block:: python
165+
.. code-block:: pycon
161166
162167
>>> import ast
163168
>>> from simpleeval import safe_power
@@ -200,15 +205,15 @@ If Expressions
200205

201206
You can use python style ``if x then y else z`` type expressions:
202207

203-
.. code-block:: python
208+
.. code-block:: pycon
204209
205210
>>> simple_eval("'equal' if x == y else 'not equal'",
206211
names={"x": 1, "y": 2})
207212
'not equal'
208213
209214
which, of course, can be nested:
210215

211-
.. code-block:: python
216+
.. code-block:: pycon
212217
213218
>>> simple_eval("'a' if 1 == 2 else 'b' if 2 == 3 else 'c'")
214219
'c'
@@ -219,15 +224,15 @@ Functions
219224

220225
You can define functions which you'd like the expresssions to have access to:
221226

222-
.. code-block:: python
227+
.. code-block:: pycon
223228
224229
>>> simple_eval("double(21)", functions={"double": lambda x:x*2})
225230
42
226231
227232
You can define "real" functions to pass in rather than lambdas, of course too,
228233
and even re-name them so that expressions can be shorter
229234

230-
.. code-block:: python
235+
.. code-block:: pycon
231236
232237
>>> def double(x):
233238
return x * 2
@@ -246,13 +251,13 @@ are provided in the ``DEFAULT_FUNCTIONS`` dict:
246251
+----------------+--------------------------------------------------+
247252
| ``float(x)`` | Convert ``x`` to a ``float``. |
248253
+----------------+--------------------------------------------------+
249-
| ``str(x)`` | Convert ``x`` to a ``str`` (``unicode`` in py2) |
254+
| ``str(x)`` | Convert ``x`` to a ``str`` |
250255
+----------------+--------------------------------------------------+
251256

252257
If you want to provide a list of functions, but want to keep these as well,
253258
then you can do a normal python ``.copy()`` & ``.update``:
254259

255-
.. code-block:: python
260+
.. code-block:: pycon
256261
257262
>>> my_functions = simpleeval.DEFAULT_FUNCTIONS.copy()
258263
>>> my_functions.update(
@@ -267,15 +272,15 @@ Names
267272
Sometimes it's useful to have variables available, which in python terminology
268273
are called 'names'.
269274

270-
.. code-block:: python
275+
.. code-block:: pycon
271276
272277
>>> simple_eval("a + b", names={"a": 11, "b": 100})
273278
111
274279
275280
You can also hand the handling of names over to a function, if you prefer:
276281

277282

278-
.. code-block:: python
283+
.. code-block:: pycon
279284
280285
>>> def name_handler(node):
281286
return ord(node.id[0].lower(a))-96
@@ -284,9 +289,34 @@ You can also hand the handling of names over to a function, if you prefer:
284289
3
285290
286291
That was a bit of a silly example, but you could use this for pulling values
287-
from a database or file, say, or doing some kind of caching system.
292+
from a database or file, looking up spreadsheet cells, say, or doing some kind of caching system.
288293

289-
The two default names that are provided are ``True`` and ``False``. So if you want to provide your own names, but want ``True`` and ``False`` to keep working, either provide them yourself, or ``.copy()`` and ``.update`` the ``DEFAULT_NAMES``. (See functions example above).
294+
In general, when it attempts to find a variable by name, if it cannot find one,
295+
then it will look in the ``functions`` for a function of that name. If you want your name handler
296+
function to return an "I can't find that name!", then it should raise a ``simpleeval.NameNotDefined``
297+
exception. Eg:
298+
299+
.. code-block:: pycon
300+
301+
>>> def name_handler(node):
302+
... if node.id[0] == 'a':
303+
... return 21
304+
... raise NameNotDefined(node.id[0], "Not found")
305+
...
306+
... simple_eval('a + a', names=name_handler, functions={"b": 100})
307+
308+
42
309+
310+
>>> simple_eval('a + b', names=name_handler, functions={'b': 100})
311+
121
312+
313+
(Note: in that example, putting a number directly into the ``functions`` dict was done just to
314+
show the fall-back to functions. Normally only put actual callables in there.)
315+
316+
317+
The two default names that are provided are ``True`` and ``False``. So if you want to provide
318+
your own names, but want ``True`` and ``False`` to keep working, either provide them yourself,
319+
or ``.copy()`` and ``.update`` the ``DEFAULT_NAMES``. (See functions example above).
290320

291321
Creating an Evaluator Class
292322
---------------------------
@@ -296,7 +326,7 @@ evaluations, you can create a SimpleEval object, and pass it expressions each
296326
time (which should be a bit quicker, and certainly more convenient for some use
297327
cases):
298328

299-
.. code-block:: python
329+
.. code-block:: pycon
300330
301331
>>> s = SimpleEval()
302332
@@ -375,7 +405,7 @@ comprehensions.
375405
Since the primary intention of this library is short expressions - an extra 'sweetener' is
376406
enabled by default. You can access a dict (or similar's) keys using the .attr syntax:
377407

378-
.. code-block:: python
408+
.. code-block:: pycon
379409
380410
>>> simple_eval("foo.bar", names={"foo": {"bar": 42}})
381411
42
@@ -405,8 +435,7 @@ and then use ``EvalNoMethods`` instead of the ``SimpleEval`` class.
405435
Other...
406436
--------
407437

408-
The library supports python 3 - but should be mostly compatible (and tested before 0.9.11)
409-
with python 2.7 as well.
438+
The library supports Python 3.9 and higher.
410439

411440
Object attributes that start with ``_`` or ``func_`` are disallowed by default.
412441
If you really need that (BE CAREFUL!), then modify the module global

Diff for: pyproject.toml

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ build-backend = "setuptools.build_meta"
66
line-length = 99
77
target-version = ['py310']
88

9+
[tool.ruff]
10+
line-length = 99
11+
912
[tool.isort]
1013
combine_as_imports = true
1114
float_to_top = true

Diff for: requirements/dev.txt

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
black==23.1.0
2-
isort==5.10.1
3-
pylint==2.12.2
4-
mypy==0.931
1+
ruff==0.6.9
2+
mypy==1.11.2

Diff for: setup.cfg

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
[metadata]
22
name = simpleeval
3-
version = 0.9.13
3+
version = 1.0.0
44
author = Daniel Fairhead
55
author_email = danthedeckie@gmail.com
66
description = A simple, safe single expression evaluator library.
77
keywords = eval, simple, expression, parse, ast
88
url = https://github.com/danthedeckie/simpleeval
9+
license = MIT
910
long_description = file: README.rst
1011
long_description_content_type = text/x-rst
1112
classifiers =
12-
Development Status :: 4 - Beta
13+
Development Status :: 5 - Production/Stable
1314
Intended Audience :: Developers
1415
License :: OSI Approved :: MIT License
1516
Topic :: Software Development :: Libraries :: Python Modules
1617
Programming Language :: Python
1718

1819
[options]
1920
py_modules = simpleeval
20-
21-
[bdist_wheel]
22-
universal=1
21+
python_requires = >=3.9
2322

2423
[pycodestyle]
2524
max_line_length = 99

0 commit comments

Comments
 (0)