|
1 | 1 | # Developer Guide for cratedb-sqlparse |
2 | 2 |
|
3 | | -About building locally, or using a different CrateDB version. |
| 3 | +Libraries in this repository are not usable without building the necessary files with `setup_grammar.py`, |
| 4 | +this is because the generated parser is not uploaded to the repository. Every target language, e.g: |
| 5 | +Python or JavaScript, needs to be built independently. |
4 | 6 |
|
5 | | -> The generated parser is not uploaded to the repository because it is huge. |
6 | | -> To use the package locally or to build a different version use the build script. |
| 7 | +The build script should not have any side effect, meaning you should be able to re-build with |
| 8 | +a different CrateDB version without any extra work. |
7 | 9 |
|
8 | | -## Setup |
9 | | - |
10 | | -To start things off, bootstrap the sandbox environment. |
| 10 | +## Running the build script. |
11 | 11 |
|
12 | 12 | ### Acquire sources |
13 | 13 | ```shell |
14 | 14 | git clone [email protected]:crate/cratedb-sqlparse.git |
15 | 15 | cd cratedb-sqlparse |
16 | 16 | ``` |
17 | 17 |
|
18 | | -### Install dependencies |
19 | | -``` |
20 | | -pip install -r requirements.txt |
21 | | -``` |
| 18 | +### Setup uv |
| 19 | +[uv](https://docs.astral.sh/uv/) is used across the project and is the recommended dependency tool, both for building the |
| 20 | +project's grammar and the development of the Python target. |
22 | 21 |
|
23 | | -### Generate grammar files |
| 22 | +macOS and Linux: |
24 | 23 | ```shell |
25 | | -poe generate |
| 24 | +curl -LsSf https://astral.sh/uv/install.sh | sh |
26 | 25 | ``` |
27 | 26 |
|
| 27 | +Windows: |
| 28 | +```shell |
| 29 | +powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex" |
| 30 | +``` |
28 | 31 |
|
29 | | -## Running Tests for Python |
30 | | - |
31 | | -First, navigate to the corresponding subdirectory: |
32 | | - |
33 | | - cd cratedb_sqlparse_py |
34 | | - |
35 | | -Verify code by running all linters and software tests: |
36 | | - |
37 | | - poe check |
| 32 | +If those options don't work, see https://docs.astral.sh/uv/getting-started/installation/ |
38 | 33 |
|
39 | | -Run specific tests: |
| 34 | +### Install dependencies |
| 35 | +```shell |
| 36 | +pip install -r requirements.txt |
| 37 | +``` |
40 | 38 |
|
41 | | - pytest -k enricher |
42 | | - pytest -k lexer |
| 39 | +or uv |
43 | 40 |
|
44 | | -Format code: |
| 41 | +```shell |
| 42 | +uv pip install -r requirements.txt |
| 43 | +``` |
45 | 44 |
|
46 | | - poe format |
| 45 | +### Generate grammar files |
47 | 46 |
|
| 47 | +Python: |
| 48 | +```shell |
| 49 | +uv run python setup_grammar.py python |
| 50 | +``` |
48 | 51 |
|
49 | | -## Running Tests for JavaScript |
| 52 | +Javascript: |
| 53 | +```shell |
| 54 | +uv run python setup_grammar.py javascript |
| 55 | +``` |
50 | 56 |
|
51 | | -First, navigate to the corresponding subdirectory: |
| 57 | +Now libraries that were built are ready to use, every library e.g. `cratedb_sqlparse_js` |
| 58 | +are on themselves different projects, with their own dependencies and |
| 59 | +dependency management systems. |
52 | 60 |
|
53 | | - cd cratedb_sqlparse_js |
| 61 | +## Setting up cratedb_sqlparse_py |
54 | 62 |
|
55 | | -Set up project: |
| 63 | +In `./cratedb_sqlparse_py` run |
56 | 64 |
|
57 | | - npm install |
58 | 65 |
|
59 | | -Verify code by running all linters and software tests: |
| 66 | +### Set up dependencies |
60 | 67 |
|
61 | | - npm test |
| 68 | +```shell |
| 69 | +uv sync --all-groups |
| 70 | +``` |
62 | 71 |
|
63 | | -Run specific tests: |
| 72 | +### Run tests |
64 | 73 |
|
65 | | - ??? |
| 74 | +```shell |
| 75 | +uv run pytest |
| 76 | +``` |
66 | 77 |
|
67 | | -Format code: |
| 78 | +### Format code: |
| 79 | +```shell |
| 80 | +uv run poe format |
| 81 | +``` |
| 82 | + |
| 83 | +## Running Tests for JavaScript |
| 84 | +In `./cratedb_sqlparse_js` run: |
68 | 85 |
|
69 | | - ??? |
| 86 | +## Setup dependencies |
| 87 | +```shell |
| 88 | +npm install |
| 89 | +``` |
70 | 90 |
|
| 91 | +## Run tests |
| 92 | +```shell |
| 93 | +npm test |
| 94 | +``` |
71 | 95 |
|
| 96 | +## Releasing libraries. |
| 97 | +Releases are done on GitHub, by creating a [new release](https://github.com/crate/cratedb-sqlparse/releases) |
| 98 | +every library will be built and published. |
72 | 99 |
|
73 | | -## Running a Release |
| 100 | +1. Make sure that in `setup_grammar.py` the CrateDB version matches the one you want. |
| 101 | +2. On GitHub create a new release, creating the appropriate tag and adapting the changelog. |
74 | 102 |
|
75 | 103 | ### Python |
| 104 | +Releases to https://pypi.org/project/cratedb-sqlparse/ |
76 | 105 |
|
77 | 106 | Overview: |
78 | 107 | - Versioning happens automatically based on the `versioningit` package. |
79 | | - You just need to tag the repository. |
80 | | -- Package building and publishing happens automatically, being staged |
81 | | - through GHA to PyPI. |
82 | | - |
83 | | -On branch `main`: |
84 | | -- Add a section for the new version in the `CHANGES.md` file. |
85 | | -- Commit your changes with a message like `Release vx.y.z`. |
86 | | -- Create a tag, and push to remote. |
87 | | - This will trigger a GitHub action which releases the new version to PyPI. |
88 | | - ```shell |
89 | | - git tag v0.0.3 |
90 | | - git push --tags |
91 | | - ``` |
92 | | -- On GitHub, designate a new release, copying in the relevant section |
93 | | - from the CHANGELOG. |
94 | | - https://github.com/crate/cratedb-sqlparse/releases |
95 | 108 |
|
| 109 | +#### Manual release. |
96 | 110 | Optionally, build the package and upload to PyPI manually. |
97 | 111 | ```shell |
98 | | -poe release |
| 112 | +uv run poe release |
99 | 113 | ``` |
100 | 114 |
|
101 | | - |
102 | 115 | ### JavaScript |
| 116 | +Releases to https://www.npmjs.com/package/@cratedb/cratedb-sqlparse |
103 | 117 |
|
104 | 118 | Overview: |
105 | | -- Versioning happens manually on behalf of the `package.json` file. |
106 | | -- Package building and publishing to npmjs.com happens manually, using |
107 | | - the `npm` program. |
108 | | - |
109 | | -On branch `main`: |
110 | | -- Make sure to run `poe generate` on the root folder first. |
111 | | -- Adjust version number in `package.json`. |
112 | | -- Generate `package-lock.json`. |
| 119 | +- Versioning is manual. |
113 | 120 |
|
114 | | - npm install --package-lock-only |
| 121 | +#### Manual release |
| 122 | +Make sure to run `poe generate` on the root folder first and adjust version number in `package.json`. |
115 | 123 |
|
116 | | -- Commit your changes with a message like `Release vx.y.z`. |
117 | | -- Create a tag, and push to remote. |
118 | | -- Build package. |
119 | | - |
120 | | - npm run build |
121 | | - |
122 | | -- Publish package. |
123 | | - |
124 | | - npm login |
125 | | - npm publish |
| 124 | +Then run: |
| 125 | +```shell |
| 126 | +npm install --package-lock-only && |
| 127 | +npm run build && |
| 128 | +npm login && |
| 129 | +npm publish |
| 130 | +``` |
0 commit comments