Skip to content

Commit

Permalink
Merge pull request #3 from cloudblue/add-filter-class
Browse files Browse the repository at this point in the history
LITE-21943 - Add support for python’s list of dict filtering.
  • Loading branch information
ffaraoneim authored Feb 16, 2022
2 parents 2fff841 + 16801dd commit a8f5b47
Show file tree
Hide file tree
Showing 45 changed files with 2,625 additions and 212 deletions.
5 changes: 0 additions & 5 deletions .coveragerc

This file was deleted.

16 changes: 9 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install -r requirements/dev.txt
pip install -r requirements/test.txt
python -m pip install --upgrade pip
pip install poetry
poetry install
- name: Linting
run: |
flake8
poetry run flake8
- name: Testing
run: |
python setup.py test
poetry run pytest
sonar:
name: Quality Analysis by sonar
needs: [build]
Expand All @@ -49,11 +50,12 @@ jobs:
python-version: '3.10'
- name: Install dependencies
run: |
pip install -r requirements/dev.txt
pip install -r requirements/test.txt
python -m pip install --upgrade pip
pip install poetry
poetry install
- name: Testing
run: |
python setup.py test
poetry run pytest
- name: Fix coverage report for Sonar
run: |
sed -i 's/\/home\/runner\/work\/lib-rql\/lib-rql\//\/github\/workspace\//g' ./tests/reports/coverage.xml
Expand Down
43 changes: 18 additions & 25 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy Python-RQL library
name: Publish Python-RQL library

on:
push:
Expand All @@ -21,36 +21,29 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install -r requirements/dev.txt
pip install -r requirements/test.txt
pip install twine
python -m pip install --upgrade pip
pip install poetry
poetry install
- name: Linting
run: |
flake8
poetry run flake8
- name: Testing
run: |
python setup.py test
- name: Fix coverage report for Sonar
run: |
sed -i 's/\/home\/runner\/work\/lib-rql\/lib-rql\//\/github\/workspace\//g' ./tests/reports/coverage.xml
- name: SonarCloud
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- name: Wait sonar to process report
uses: jakejarvis/wait-action@master
poetry run pytest
- name: Extract tag name
uses: actions/github-script@v3
id: tag
with:
time: '15s'
- name: SonarQube Quality Gate check
uses: sonarsource/sonarqube-quality-gate-action@master
timeout-minutes: 5
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- name: Publish to PyPI
github-token: ${{ secrets.GITHUB_TOKEN }}
result-encoding: string
script: |
return context.payload.ref.replace(/refs\/tags\//, '')
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
poetry version ${{ steps.tag.outputs.result }}
poetry build
poetry publish -u $TWINE_USERNAME -p $TWINE_PASSWORD
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ dist/

tests/reports/
.coverage

.devcontainer

htmlcov/
docs/_build
45 changes: 0 additions & 45 deletions .travis.yml

This file was deleted.

5 changes: 0 additions & 5 deletions MANIFEST.in

This file was deleted.

118 changes: 95 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,54 @@
Python RQL
==========
# Python RQL


[![pyversions](https://img.shields.io/pypi/pyversions/lib-rql.svg)](https://pypi.org/project/lib-rql/)
[![PyPi Status](https://img.shields.io/pypi/v/lib-rql.svg)](https://pypi.org/project/lib-rql/)
[![PyPI status](https://img.shields.io/pypi/status/lib-rql.svg)](https://pypi.org/project/lib-rql/)
[![PyPI Downloads](https://img.shields.io/pypi/dm/lib-rql)](https://pypi.org/project/lib-rql/)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=lib-rql&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=lib-rql)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=lib-rql&metric=coverage)](https://sonarcloud.io/summary/new_code?id=lib-rql)

RQL
---


## Introduction

RQL (Resource query language) is designed for modern application development. It is built for the web, ready for NoSQL, and highly extensible with simple syntax.
This is a query language fast and convenient database interaction. RQL was designed for use in URLs to request object-style data structures.

[RQL Reference](https://connect.cloudblue.com/community/api/rql/)

Notes
-----
## Install

`Python RQL` can be installed from [pypi.org](https://pypi.org/project/lib-rql/) using pip:

```
$ pip install lib-rql
```

## Documentation

[`Python RQL` documentation](https://lib-rql.readthedocs.io/en/latest/) is hosted on the _Read the Docs_ service.


## Projects using Python RQL

`Django RQL` is the Django app, that adds RQL filtering to your application.

Visit the [Django RQL](https://github.com/cloudblue/django-rql) project repository for more informations.


## Notes

Parsing is done with [Lark](https://github.com/lark-parser/lark) ([cheatsheet](https://lark-parser.readthedocs.io/en/latest/lark_cheatsheet.pdf)).
The current parsing algorithm is [LALR(1)](https://www.wikiwand.com/en/LALR_parser) with standard lexer.

Supported operators
=============================
0. Values with whitespaces or special characters, like ',' need to have "" or ''
1. Supported date format is ISO8601: 2019-02-12
2. Supported datetime format is ISO8601: 2019-02-12T10:02:00 / 2019-02-12T10:02Z / 2019-02-12T10:02:00+03:00


## Supported operators

1. Comparison (eq, ne, gt, ge, lt, le, like, ilike, search)
2. List (in, out)
3. Logical (and, or, not)
Expand All @@ -31,8 +58,11 @@ Supported operators
7. Tuple (t)


Example
=======
## Examples

### Parsing a RQL query


```python
from py_rql import parse
from py_rql.exceptions import RQLFilterError
Expand All @@ -43,27 +73,66 @@ except RQLFilterError:
pass
```

Notes
=====
0. Values with whitespaces or special characters, like ',' need to have "" or ''
1. Supported date format is ISO8601: 2019-02-12
2. Supported datetime format is ISO8601: 2019-02-12T10:02:00 / 2019-02-12T10:02Z / 2019-02-12T10:02:00+03:00

### Filter a list of dictionaries

```python
from py_rql.constants import FilterTypes
from py_rql.filter_cls import FilterClass


class BookFilter(FilterClass):
FILTERS = [
{
'filter': 'title',
},
{
'filter': 'author.name',
},
{
'filter': 'status',
},
{
'filter': 'pages',
'type': FilterTypes.INT,
},
{
'filter': 'featured',
'type': FilterTypes.BOOLEAN,
},
{
'filter': 'publish_date',
'type': FilterTypes.DATETIME,
},
]

filters = BookFilter()

query = 'eq(title,Practical Modern JavaScript)'
results = list(filters.filter(query, DATA))

print(results)

query = 'or(eq(pages,472),lt(pages,400))'
results = list(filters.filter(query, DATA))

print(results)
```


Development
===========
## Development


1. Python 3.6+
0. Install dependencies `requirements/dev.txt`
0. Install dependencies `pip install poetry && poetry install`

Testing
=======
## Testing

1. Python 3.6+
0. Install dependencies `requirements/test.txt`
0. Install dependencies `pip install poetry && poetry install`

Check code style: `flake8`
Run tests: `pytest`
Check code style: `poetry run flake8`
Run tests: `poetry run pytest`

Tests reports are generated in `tests/reports`.
* `out.xml` - JUnit test results
Expand All @@ -72,3 +141,6 @@ Tests reports are generated in `tests/reports`.
To generate HTML coverage reports use:
`--cov-report html:tests/reports/cov_html`

## License

`Python RQL` is released under the [Apache License Version 2.0](https://www.apache.org/licenses/LICENSE-2.0).
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
Loading

0 comments on commit a8f5b47

Please sign in to comment.