Skip to content

Commit 16801dd

Browse files
author
Francesco Faraone
committed
LITE-21943
Add support for python’s list of dict filtering.
1 parent 2fff841 commit 16801dd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2625
-212
lines changed

.coveragerc

-5
This file was deleted.

.github/workflows/build.yml

+9-7
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@ jobs:
2626
python-version: ${{ matrix.python-version }}
2727
- name: Install dependencies
2828
run: |
29-
pip install -r requirements/dev.txt
30-
pip install -r requirements/test.txt
29+
python -m pip install --upgrade pip
30+
pip install poetry
31+
poetry install
3132
- name: Linting
3233
run: |
33-
flake8
34+
poetry run flake8
3435
- name: Testing
3536
run: |
36-
python setup.py test
37+
poetry run pytest
3738
sonar:
3839
name: Quality Analysis by sonar
3940
needs: [build]
@@ -49,11 +50,12 @@ jobs:
4950
python-version: '3.10'
5051
- name: Install dependencies
5152
run: |
52-
pip install -r requirements/dev.txt
53-
pip install -r requirements/test.txt
53+
python -m pip install --upgrade pip
54+
pip install poetry
55+
poetry install
5456
- name: Testing
5557
run: |
56-
python setup.py test
58+
poetry run pytest
5759
- name: Fix coverage report for Sonar
5860
run: |
5961
sed -i 's/\/home\/runner\/work\/lib-rql\/lib-rql\//\/github\/workspace\//g' ./tests/reports/coverage.xml

.github/workflows/deploy.yml

+18-25
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Deploy Python-RQL library
1+
name: Publish Python-RQL library
22

33
on:
44
push:
@@ -21,36 +21,29 @@ jobs:
2121
python-version: ${{ matrix.python-version }}
2222
- name: Install dependencies
2323
run: |
24-
pip install -r requirements/dev.txt
25-
pip install -r requirements/test.txt
26-
pip install twine
24+
python -m pip install --upgrade pip
25+
pip install poetry
26+
poetry install
2727
- name: Linting
2828
run: |
29-
flake8
29+
poetry run flake8
3030
- name: Testing
3131
run: |
32-
python setup.py test
33-
- name: Fix coverage report for Sonar
34-
run: |
35-
sed -i 's/\/home\/runner\/work\/lib-rql\/lib-rql\//\/github\/workspace\//g' ./tests/reports/coverage.xml
36-
- name: SonarCloud
37-
uses: SonarSource/sonarcloud-github-action@master
38-
env:
39-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40-
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
41-
- name: Wait sonar to process report
42-
uses: jakejarvis/wait-action@master
32+
poetry run pytest
33+
- name: Extract tag name
34+
uses: actions/github-script@v3
35+
id: tag
4336
with:
44-
time: '15s'
45-
- name: SonarQube Quality Gate check
46-
uses: sonarsource/sonarqube-quality-gate-action@master
47-
timeout-minutes: 5
48-
env:
49-
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
50-
- name: Publish to PyPI
37+
github-token: ${{ secrets.GITHUB_TOKEN }}
38+
result-encoding: string
39+
script: |
40+
return context.payload.ref.replace(/refs\/tags\//, '')
41+
- name: Build and publish
5142
env:
5243
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
5344
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
5445
run: |
55-
python setup.py sdist bdist_wheel
56-
twine upload dist/*
46+
poetry version ${{ steps.tag.outputs.result }}
47+
poetry build
48+
poetry publish -u $TWINE_USERNAME -p $TWINE_PASSWORD
49+

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ dist/
1212

1313
tests/reports/
1414
.coverage
15+
16+
.devcontainer
17+
18+
htmlcov/
19+
docs/_build

.travis.yml

-45
This file was deleted.

MANIFEST.in

-5
This file was deleted.

README.md

+95-23
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,54 @@
1-
Python RQL
2-
==========
1+
# Python RQL
2+
3+
34
[![pyversions](https://img.shields.io/pypi/pyversions/lib-rql.svg)](https://pypi.org/project/lib-rql/)
45
[![PyPi Status](https://img.shields.io/pypi/v/lib-rql.svg)](https://pypi.org/project/lib-rql/)
56
[![PyPI status](https://img.shields.io/pypi/status/lib-rql.svg)](https://pypi.org/project/lib-rql/)
7+
[![PyPI Downloads](https://img.shields.io/pypi/dm/lib-rql)](https://pypi.org/project/lib-rql/)
68
[![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)
79
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=lib-rql&metric=coverage)](https://sonarcloud.io/summary/new_code?id=lib-rql)
810

9-
RQL
10-
---
11+
12+
13+
## Introduction
1114

1215
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.
1316
This is a query language fast and convenient database interaction. RQL was designed for use in URLs to request object-style data structures.
1417

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

17-
Notes
18-
-----
20+
## Install
21+
22+
`Python RQL` can be installed from [pypi.org](https://pypi.org/project/lib-rql/) using pip:
23+
24+
```
25+
$ pip install lib-rql
26+
```
27+
28+
## Documentation
29+
30+
[`Python RQL` documentation](https://lib-rql.readthedocs.io/en/latest/) is hosted on the _Read the Docs_ service.
31+
32+
33+
## Projects using Python RQL
34+
35+
`Django RQL` is the Django app, that adds RQL filtering to your application.
36+
37+
Visit the [Django RQL](https://github.com/cloudblue/django-rql) project repository for more informations.
38+
39+
40+
## Notes
1941

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

23-
Supported operators
24-
=============================
45+
0. Values with whitespaces or special characters, like ',' need to have "" or ''
46+
1. Supported date format is ISO8601: 2019-02-12
47+
2. Supported datetime format is ISO8601: 2019-02-12T10:02:00 / 2019-02-12T10:02Z / 2019-02-12T10:02:00+03:00
48+
49+
50+
## Supported operators
51+
2552
1. Comparison (eq, ne, gt, ge, lt, le, like, ilike, search)
2653
2. List (in, out)
2754
3. Logical (and, or, not)
@@ -31,8 +58,11 @@ Supported operators
3158
7. Tuple (t)
3259

3360

34-
Example
35-
=======
61+
## Examples
62+
63+
### Parsing a RQL query
64+
65+
3666
```python
3767
from py_rql import parse
3868
from py_rql.exceptions import RQLFilterError
@@ -43,27 +73,66 @@ except RQLFilterError:
4373
pass
4474
```
4575

46-
Notes
47-
=====
48-
0. Values with whitespaces or special characters, like ',' need to have "" or ''
49-
1. Supported date format is ISO8601: 2019-02-12
50-
2. Supported datetime format is ISO8601: 2019-02-12T10:02:00 / 2019-02-12T10:02Z / 2019-02-12T10:02:00+03:00
76+
77+
### Filter a list of dictionaries
78+
79+
```python
80+
from py_rql.constants import FilterTypes
81+
from py_rql.filter_cls import FilterClass
82+
83+
84+
class BookFilter(FilterClass):
85+
FILTERS = [
86+
{
87+
'filter': 'title',
88+
},
89+
{
90+
'filter': 'author.name',
91+
},
92+
{
93+
'filter': 'status',
94+
},
95+
{
96+
'filter': 'pages',
97+
'type': FilterTypes.INT,
98+
},
99+
{
100+
'filter': 'featured',
101+
'type': FilterTypes.BOOLEAN,
102+
},
103+
{
104+
'filter': 'publish_date',
105+
'type': FilterTypes.DATETIME,
106+
},
107+
]
108+
109+
filters = BookFilter()
110+
111+
query = 'eq(title,Practical Modern JavaScript)'
112+
results = list(filters.filter(query, DATA))
113+
114+
print(results)
115+
116+
query = 'or(eq(pages,472),lt(pages,400))'
117+
results = list(filters.filter(query, DATA))
118+
119+
print(results)
120+
```
51121

52122

53-
Development
54-
===========
123+
## Development
124+
55125

56126
1. Python 3.6+
57-
0. Install dependencies `requirements/dev.txt`
127+
0. Install dependencies `pip install poetry && poetry install`
58128

59-
Testing
60-
=======
129+
## Testing
61130

62131
1. Python 3.6+
63-
0. Install dependencies `requirements/test.txt`
132+
0. Install dependencies `pip install poetry && poetry install`
64133

65-
Check code style: `flake8`
66-
Run tests: `pytest`
134+
Check code style: `poetry run flake8`
135+
Run tests: `poetry run pytest`
67136

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

144+
## License
145+
146+
`Python RQL` is released under the [Apache License Version 2.0](https://www.apache.org/licenses/LICENSE-2.0).

docs/Makefile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= sphinx-build
8+
SOURCEDIR = .
9+
BUILDDIR = _build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

0 commit comments

Comments
 (0)