Skip to content

Commit 94f650b

Browse files
author
ffaraoneim
authored
Merge pull request #1 from cloudblue/migration/LITE-22101
LITE-22101 Extracted RQL core from Django-RQL library
2 parents 8969f78 + d460ebc commit 94f650b

31 files changed

+1245
-0
lines changed

.coveragerc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[run]
2+
branch = True
3+
4+
[xml]
5+
output = tests/reports/coverage.xml

.github/workflows/build.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Build Python-RQL library
2+
3+
on:
4+
push:
5+
branches: '*'
6+
tags:
7+
- '*'
8+
pull_request:
9+
branches: [ master ]
10+
11+
jobs:
12+
build:
13+
name: Build and test on Python ${{ matrix.python-version }}
14+
runs-on: ubuntu-latest
15+
strategy:
16+
matrix:
17+
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
18+
steps:
19+
- name: Checkout project
20+
uses: actions/checkout@v2
21+
with:
22+
fetch-depth: 0
23+
- name: Set up Python ${{ matrix.python-version }}
24+
uses: actions/setup-python@v2
25+
with:
26+
python-version: ${{ matrix.python-version }}
27+
- name: Install dependencies
28+
run: |
29+
pip install -r requirements/dev.txt
30+
pip install -r requirements/test.txt
31+
- name: Linting
32+
run: |
33+
flake8
34+
- name: Testing
35+
run: |
36+
python setup.py test
37+
sonar:
38+
name: Quality Analysis by sonar
39+
needs: [build]
40+
runs-on: ubuntu-latest
41+
steps:
42+
- name: Checkout project
43+
uses: actions/checkout@v2
44+
with:
45+
fetch-depth: 0
46+
- name: Set up Python 3.10
47+
uses: actions/setup-python@v2
48+
with:
49+
python-version: '3.10'
50+
- name: Install dependencies
51+
run: |
52+
pip install -r requirements/dev.txt
53+
pip install -r requirements/test.txt
54+
- name: Testing
55+
run: |
56+
python setup.py test
57+
- name: Fix coverage report for Sonar
58+
run: |
59+
sed -i 's/\/home\/runner\/work\/lib-rql\/lib-rql\//\/github\/workspace\//g' ./tests/reports/coverage.xml
60+
- name: SonarCloud
61+
uses: SonarSource/sonarcloud-github-action@master
62+
env:
63+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
64+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
65+
- name: Wait sonar to process report
66+
uses: jakejarvis/wait-action@master
67+
with:
68+
time: '15s'
69+
- name: SonarQube Quality Gate check
70+
uses: sonarsource/sonarqube-quality-gate-action@master
71+
timeout-minutes: 5
72+
env:
73+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

.github/workflows/deploy.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Deploy Python-RQL library
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
python-version: [3.8]
14+
steps:
15+
- uses: actions/checkout@v2
16+
with:
17+
fetch-depth: 0
18+
- name: Set up Python ${{ matrix.python-version }}
19+
uses: actions/setup-python@v2
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
- name: Install dependencies
23+
run: |
24+
pip install -r requirements/dev.txt
25+
pip install -r requirements/test.txt
26+
pip install twine
27+
- name: Linting
28+
run: |
29+
flake8
30+
- name: Testing
31+
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
43+
with:
44+
time: '120s'
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
51+
env:
52+
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
53+
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
54+
run: |
55+
python setup.py sdist bdist_wheel
56+
twine upload dist/*

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
__pycache__/
2+
.pytest_cache
3+
*.py[cod]
4+
venv*/
5+
6+
build/
7+
dist/
8+
*.egg-info
9+
.eggs
10+
11+
.idea
12+
13+
tests/reports/
14+
.coverage

.travis.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
dist: trusty
2+
language: python
3+
matrix:
4+
include:
5+
- os: linux
6+
python: 3.6
7+
dist: xenial
8+
sudo: true
9+
- os: linux
10+
python: 3.7
11+
dist: xenial
12+
sudo: true
13+
env: BUILD=PYPI
14+
- os: linux
15+
python: 3.8
16+
dist: xenial
17+
sudo: true
18+
install:
19+
- pip install -r requirements/dev.txt
20+
- pip install -r requirements/test.txt
21+
- pip install pytest-cov
22+
script:
23+
- flake8
24+
- python setup.py test
25+
- sonar-scanner
26+
after_success:
27+
- bash <(curl -s https://codecov.io/bash)
28+
addons:
29+
sonarcloud:
30+
organization: cloudbluesonarcube
31+
token:
32+
secure: VJcQOn8TekNPIEn/vnf4fHGZoHha1hoeIVGGT9sYHfqe6zjofbQqAaGO3HMVR7Oliqxe1GQkiw2g+J5YdnRSvqqt2B6EPRiJXJW2jF0irwZ+zsrs/h5LcnQvp6KcIEjC9XmYh3gtkL7GF4Afola0Co4kic7+G2icExKE9JZCfEPExIgjZ6tkx74i0sIbUpdVNas8ODiPwXYcia0DBBh/1NT6p0X4wduSsWEC98rkxWZEyqtMLgL9hkO8TyihnNxsPCpK+ocyAtVmBG0P52A7iGHOi3JjzxVOQXntXhutdJsFXs+wcnFZfKHZf5lwfSKuY45DBr6s5iXo7mWADau3TJ2WeKasK/Bs20iLu2yJArNVqCAKqyA92YBRltowxYlNt3ewK6NrMyETvK0GVzrnBet0jVBfWPztJYi5HdUQZjfHMOiFE4k2kX1sWWI3uSDMS03vppzwo3T+InaZoj/fJaqsOGXMSlkRyKWa8jeK6556pYKo784WdYthijR2sOxdLck19ZaeplI+t3Pre9mGPlKw1gn/TqCPfQaFstYwede4qk+OzPthfDJh/jSobQgHiGhq9C0vzAn+ftSAEYJupNRt33uX18NSf2nH6N9mBaBF7cuSZrWTKmR1D00f4laIv5w+hI/xVq079BJe9xdK0gtxfZcdGMUowILcA+i2PV4=
33+
deploy:
34+
skip_cleanup: true
35+
skip_existing: true
36+
provider: pypi
37+
user: "__token__"
38+
password:
39+
secure: Wzg60u6udwzVIfquCwyge0x0VFPKMvfi0k/lavgJ4dAIpSRJeZESn9gTPnE8nwmDlK7LLezfHGVZnV94428zthzh3CmeLbMx+eD1l7s5/x0s/FJa6Y1AvO+q82N6AmjkstCFcyhliTL6c39X4sQUpN/CQb1Xo0la7qlooFjXf4UvRD3KTnLi4LbQZ5iAp7eLFFYyfRfP8k8IpCWBzt8vWPmQzL9V+xfS7lt4wk/VOeX0wyTNoSPoSnsTI5bBLc6KhxUweGMdIvGgpEL2QvJ3kL4nnAB31NJ6/wJhHp5busTzNruMFnRMwlIjjVIN6PIpjZ7G1qBP3o19vwLkpZ3DT3ALZexZoeBZtIxxmWoQr4i5D4OGeHRKVOHD7SOELOGp1jvmhMilkNtJwFjtozuBOoJSk0W+Ie1fimPK3WJkTjtJZ1vHf6K3cuV8Ejul7C2Qy9Y8qojyfcQY4EwVriZvRKaCnMfNal6swJrpdYoDIsnZFC8u5jTsWPJCiS60XZbcWv6X/i9kZD/R+OHyDZJ4T4fSVprZ4WQysAKUNoLjftCxGlvUz3ir+D20cRO378kdvNar8XzUhKcaUC5anm+8NvjAKxLEWxo5Eklegg+sBlBF/kJSOVVhJ/KrqHlisaX1UhsZs2Pl3MO+eXRGIrHoeRCoBBrulg9Kb6hYKx2l7b8=
40+
on:
41+
tags: true
42+
all_branches: true
43+
distributions: sdist
44+
condition: "$BUILD = PYPI"
45+
repo: cloudblue/lib-rql

MANIFEST.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
include LICENSE
2+
include README.md
3+
include requirements/dev.txt
4+
include requirements/test.txt
5+
prune tests

README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
Python RQL
2+
==========
3+
![pyversions](https://img.shields.io/pypi/pyversions/lib-rql.svg)
4+
[![PyPi Status](https://img.shields.io/pypi/v/lib-rql.svg)](https://pypi.org/project/lib-rql/)
5+
[![codecov](https://codecov.io/gh/cloudblue/lib-rql/branch/master/graph/badge.svg)](https://codecov.io/gh/cloudblue/lib-rql)
6+
[![PyPI status](https://img.shields.io/pypi/status/lib-rql.svg)](https://pypi.python.org/pypi/lib-rql/)
7+
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=lib-rql&metric=alert_status)](https://sonarcloud.io/dashboard?id=lib-rql)
8+
9+
RQL
10+
---
11+
12+
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.
13+
This is a query language fast and convenient database interaction. RQL was designed for use in URLs to request object-style data structures.
14+
15+
[RQL Reference](https://connect.cloudblue.com/community/api/rql/)
16+
17+
Notes
18+
-----
19+
20+
Parsing is done with [Lark](https://github.com/lark-parser/lark) ([cheatsheet](https://lark-parser.readthedocs.io/en/latest/lark_cheatsheet.pdf)).
21+
The current parsing algorithm is [LALR(1)](https://www.wikiwand.com/en/LALR_parser) with standard lexer.
22+
23+
Supported operators
24+
=============================
25+
1. Comparison (eq, ne, gt, ge, lt, le, like, ilike, search)
26+
2. List (in, out)
27+
3. Logical (and, or, not)
28+
4. Constants (null(), empty())
29+
5. Ordering (ordering)
30+
6. Select (select)
31+
7. Tuple (t)
32+
33+
34+
Example
35+
=======
36+
```python
37+
from py_rql import parse
38+
from py_rql.exceptions import RQLFilterError
39+
40+
try:
41+
tree = parse('eq(key,value)')
42+
except RQLFilterError:
43+
pass
44+
```
45+
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
51+
52+
53+
Development
54+
===========
55+
56+
1. Python 3.6+
57+
0. Install dependencies `requirements/dev.txt`
58+
59+
Testing
60+
=======
61+
62+
1. Python 3.6+
63+
0. Install dependencies `requirements/test.txt`
64+
65+
Check code style: `flake8`
66+
Run tests: `pytest`
67+
68+
Tests reports are generated in `tests/reports`.
69+
* `out.xml` - JUnit test results
70+
* `coverage.xml` - Coverage xml results
71+
72+
To generate HTML coverage reports use:
73+
`--cov-report html:tests/reports/cov_html`
74+

py_rql/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#
2+
# Copyright © 2022 Ingram Micro Inc. All rights reserved.
3+
#
4+
5+
from py_rql.parser import RQLParser
6+
7+
8+
def parse(query):
9+
""" Parses RQL query string into a syntax tree.
10+
11+
:param str query: RQL query
12+
:return: Parsed tree
13+
:rtype: lark.Tree
14+
:raises: py_rql.exceptions.RQLFilterError
15+
"""
16+
return RQLParser.parse_query(query)

0 commit comments

Comments
 (0)