A parser for Logical Query Protocol (LQP) S-expressions into Protobuf
Project description
python-tools
A command-line tool to parse Logical Query Protocol (LQP) S-expressions into Protobuf binary and JSON formats.
Usage
usage: lqp [-h] [-v] [--no-validation] [--bin] [--json] [--out] input
Parse LQP S-expression into Protobuf binary and JSON files.
positional arguments:
input directory holding .lqp files, or a single .lqp file
options:
-h, --help show this help message and exit
-v, --version show program's version number and exit
--no-validation don't validate parsed LQP
--bin encode emitted ProtoBuf into binary
--json encode emitted ProtoBuf into JSON
--out write emitted binary or JSON to stdout
Examples
lqp --no-validation --bin --json foo/bar.lqp
Will create two files in foo/ named bar.bin and bar.json containing the binary and JSON encodings of the parsed ProtoBuf.
In this case, the parser will not go through the client-side validations we do to check for well-formed LQP.
lqp --bin --json foo
This will look for .lqp files both at the top-level and inside an lqp subdirectory.
Then it will organize the generated binary and JSON into folders, as well as the original found files. So, for example, if foo has this structure:
foo/
| bar.lqp
| lqp/
| | baz.lqp
Then after executing the above command, it should have this structure:
foo/
| bin/
| | bar.bin
| | baz.bin
| json/
| | bar.json
| | baz.json
| lqp/
| | bar.lqp
| | baz.lqp
lqp --bin --out foo.lqp
Will write the ProtoBuf binary parsed from the foo.lqp to stdout. The result can be piped
into the desired output file, e.g., lqp --bin --out foo.lqp > foo.bin.
Setup
It is recommended to use a Python virtualenv. Set one up in the python-tools directory
by:
cd python-tools
python -m venv .venv
Then activate the virtual environment:
source .venv/bin/activate
Build
Install preprequisites:
pip install pip build setuptools wheel
Then build the module itself:
python -m build
Install locally:
pip install [--user] [--force-reinstall] dist/lqp-0.1.0-py3-none-any.whl
Running tests
Within python-tools,
Setup:
python -m pip install -e ".[test]"
python -m pip install pyrefly
Running tests:
python -m pytest
To add testcases, add a .lqp file to the tests/test_files/lqp subdirectory. New
files get picked up automatically. To generate or update the corresponding output files
(binary, debug mode, and pretty-printing snapshots), run pytest --snapshot-update.
Type checking:
pyrefly check
Formatting
The LQP S-expression syntax was chosen to align with that of the Clojure programming language, in order to leverage the existing tools in that ecosystem. LQP syntax should be formatted via cljfmt with the following configuration:
;; .cljfmt.edn
{:indents {#re ".*" [[:inner 0]]}
:remove-surrounding-whitespace? false
:remove-trailing-whitespace? false
:remove-consecutive-blank-lines? false}
This configuration is explained here and simply works better for LQP, which does not have many of the Clojure keywords that are treated as special cases during formatting by default.
See the next section for an easy way to integrate cljfmt into your VSCode workflow.
VSCode
Editing nested S-expressions by hand can get a little tedious, which is why
paredit is an established tool in the Clojure world. To
integrate paredit and cljfmt into your VSCode workflow, just install the Calva
extension and follow the configuration
guide to use the cljfmt configuration pasted
in the previous section.
Out-of-the-box, Calva also runs a Clojure linter, which of course does not know what to do
with LQP, resulting in lots of squiggly lines. For that reason, it is also advisable to
create the following config file at .lsp/config.edn from the project root:
;; .lsp/config.edn
{:linters {:clj-kondo {:level :off}}}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lqp-0.1.19.tar.gz.
File metadata
- Download URL: lqp-0.1.19.tar.gz
- Upload date:
- Size: 41.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35959eebae71cb07d550254e04e9e6500cf9f98c6fd4fe4cf99cdc4b0ac369c4
|
|
| MD5 |
08fbfdcb406a4cee7c55c07ec283815d
|
|
| BLAKE2b-256 |
1f60261977d546f9e09efda5d2aa8893e717f25bff76561e19f9a95eec31ca19
|
File details
Details for the file lqp-0.1.19-py3-none-any.whl.
File metadata
- Download URL: lqp-0.1.19-py3-none-any.whl
- Upload date:
- Size: 39.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a4dcac4e0c6b5e9837c0d9292b3ea31444e4274f91f7f0f7ab387aa71791e12
|
|
| MD5 |
0aba4097b7a6533b8bc2bb0dce20f61e
|
|
| BLAKE2b-256 |
6cb8c123804fea5bfa7c2ef6a64873b8e910cec233054deca7b14122c7f1e7e3
|