telefonicasc / tcjexl

Recubrimiento de la librería de jexl incluyendo un conjunto de transformaciones por defecto
GNU Affero General Public License v3.0
1 stars 0 forks source link

tcjexl

Coverage Status

This is a wrapper of the pyjexl library, including a set of default transformations (detailed in this section)

Current version of the tcjexl library embeds the pyjexl code (as in 0.3.0 release) in order to apply some fixes. Ideally, the fix should be applied on the upstream library (in this sense, ve have created this PR) but it hasn't been merged yet at the moment of writing this by pyjexl mantainers. Hopefully, if at some moment the fix is applied on pyjexl we could simplify this (it would be a matter of rollback this PR and set the proper pyjexl dependency, e.g. pyjexl==0.4.0)

Example:

from tcjexl import JEXL

jexl = JEXL()

context = {"a": 5, "b": 7, "c": "a TEXT String"}

print(jexl.evaluate('a+b', context))
print(jexl.evaluate('c|lowercase', context))

Result:

12
a text string

Using simulated time

By default, the current time reference used by date related transformations is system current time. However, this can be changed using the positional argument now in the JEXL constructor to specify a function that returns a datetime object to be used as current time.

For instance, if we want to set current time to November 13th, 2020 at 6:24:58am we can use:

from tcjexl import JEXL
import datetime

def simulated_time():
    return datetime.datetime(2020, 11, 13, 6, 24, 58, 000, tzinfo=datetime.timezone.utc)

jexl = JEXL(now=simulated_time)

print(jexl.evaluate('0|currentTimeIso', {}))

Result:

2020-11-13T06:24:58.000Z

Included transformations

NOTE: JEXL pipeline is needed even if the transformation doesn't need an parameter to work (e.g. currentTime that provides the current system time and doesn't need and argument). In this case, we use 0| for these cases (e.g. 0|currentTime).

Math related transformations

String related transformations

List related transformations

Date related transformations

Interpolation transformations

Miscelaneous transformations

Packaging

python3 setup.py sdist bdist_wheel

Uploading package to pypi repository

Once the package has been build as explained in the previous section it can be uploaded to pypi repository.

First, install the twine tool:

pip install twine

Next, run:

twine upload dist/tcjexl-x.y.z.tar.gz

You need to be registered at https://pypi.org with permissions at https://pypi.org/project/tcjexl/, as during the upload process you will be prompted to provide your user and password.

Changelog

0.2.0 (March 11th, 2024)

0.1.0 (March 6th, 2024)