Skip to content

Commit 88eb9cc

Browse files
authored
PY-314 Code generation for neptune-api (#190)
* neptune-api codegen * Configure linting for the generated code * check in neptune-api-spec to the repo * code review * Add README files to generated directories * Remove the source README.md file from docker/rofiles/neptune_api * Move neptune-api-spec to src/neptune_query/generated * formatting fix * Adding src/neptune_api_codegen/README.md * Exclude generated/neptune_api_spec and generated/README.md from building Python package
1 parent e865be0 commit 88eb9cc

Some content is hidden

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

44 files changed

+24481
-10
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,5 @@ poetry.lock
136136
# pytest-benchmark
137137
.benchmarks
138138
benchmark_results.json
139+
140+
/tmp/

.pre-commit-config.yaml

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
1-
exclude: ^src/neptune_query/generated/
1+
exclude: /generated/neptune_api/proto/|/generated/neptune_api_spec/
22
repos:
3-
- repo: https://github.com/pre-commit/pre-commit-hooks
4-
rev: v6.0.0
3+
- repo: https://github.com/psf/black
4+
rev: 25.12.0
55
hooks:
6-
- id: check-yaml
7-
- id: end-of-file-fixer
8-
- id: trailing-whitespace
6+
- id: black
7+
args: [--config, pyproject.toml]
98
- repo: https://github.com/pycqa/isort
109
rev: 7.0.0
1110
hooks:
1211
- id: isort
1312
args: [--settings-path, pyproject.toml]
14-
- repo: https://github.com/psf/black
15-
rev: 25.12.0
13+
- repo: https://github.com/astral-sh/ruff-pre-commit
14+
rev: v0.4.9
1615
hooks:
17-
- id: black
18-
args: [--config, pyproject.toml]
16+
- name: codegen-ruff
17+
id: ruff
18+
args: [--fix]
19+
files: ^src/neptune_query/generated/.*py$
20+
- name: codegen-ruff-format
21+
id: ruff-format
22+
files: ^src/neptune_query/generated/.*py$
23+
- repo: https://github.com/pycqa/isort
24+
rev: 7.0.0
25+
hooks:
26+
- name: codegen-isort
27+
id: isort
28+
args: [--settings-path, pyproject.toml]
29+
files: /generated/neptune_api/
1930
- repo: https://github.com/pycqa/flake8
2031
rev: 7.0.0
2132
hooks:
@@ -27,6 +38,12 @@ repos:
2738
- id: insert-license
2839
files: ^src/neptune_query.*[^/]+\.py$
2940
args: [ "--license-filepath", ".github/license_header.txt", "--allow-past-years"]
41+
- repo: https://github.com/pre-commit/pre-commit-hooks
42+
rev: v6.0.0
43+
hooks:
44+
- id: check-yaml
45+
- id: end-of-file-fixer
46+
- id: trailing-whitespace
3047
- repo: https://github.com/pre-commit/mirrors-mypy
3148
rev: v1.19.1
3249
hooks:
@@ -35,5 +52,22 @@ repos:
3552
pass_filenames: false
3653
additional_dependencies:
3754
- attrs
55+
- httpx
56+
- types-PyJWT
57+
- grpcio-tools
58+
- types-Pygments
59+
- types-protobuf
60+
- repo: https://github.com/pycqa/isort
61+
rev: 5.13.2
62+
hooks:
63+
- id: isort
64+
args: [--settings-path, pyproject.toml]
65+
- repo: https://github.com/Lucas-C/pre-commit-hooks
66+
rev: v1.5.4
67+
hooks:
68+
- id: insert-license
69+
files: ^src/neptune_query/generated/.*py$
70+
args: [ "--license-filepath", ".github/license_header.txt", "--allow-past-years"]
71+
3872
default_language_version:
3973
python: python3

pyproject.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ keywords = [
5656
"ML Model Store",
5757
"ML Metadata Store",
5858
]
59+
exclude = [
60+
"src/neptune_query/generated/neptune_api_spec/**",
61+
"src/neptune_query/generated/README.md",
62+
]
5963
packages = [
6064
{ include = "neptune_query", from = "src" },
6165
]
@@ -81,12 +85,19 @@ exclude = '''
8185

8286
[tool.isort]
8387
profile = "black"
88+
split_on_trailing_comma = false
8489
line_length = 120
8590
force_grid_wrap = 2
8691

8792
[tool.flake8]
8893
max-line-length = 120
94+
# E203: whitespace before ':' - conflicts with black
95+
# E501: line too long
8996
extend-ignore = "E203"
97+
per-file-ignores = """
98+
src/neptune_api_codegen/docker/rofiles/neptune_api/client.py:E501
99+
src/neptune_query/generated/neptune_api/*:E501
100+
"""
90101

91102
[tool.mypy]
92103
mypy_path = "src/"
@@ -110,3 +121,11 @@ markers = [
110121
env_files = [
111122
".env",
112123
]
124+
125+
# This is for neptune-api generated code only. We may remove this later
126+
[tool.ruff]
127+
line-length = 120
128+
target-version = "py38"
129+
130+
[tool.ruff.lint]
131+
select = ["F", "UP"]

src/neptune_api_codegen/README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# neptune_api_codegen
2+
3+
Utility for generating Neptune API bindings and local API spec used by `neptune_query`.
4+
It orchestrates Dockerized generators to:
5+
6+
- copy OpenAPI (swagger) and Protobuf sources from the private Neptune backend repository
7+
- build a unified OpenAPI document
8+
- generate Python client code from OpenAPI
9+
- generate Python modules from `.proto` definitions
10+
- place artifacts under `src/neptune_query/generated/`
11+
12+
See also: `src/neptune_query/generated/README.md` for a map of generated outputs.
13+
14+
## Prerequisites
15+
- Docker installed and running (required to build images and run generators)
16+
- Git installed (used to embed the backend commit reference)
17+
- Access to the Neptune backend repository (cloned locally)
18+
19+
## Quick start
20+
From the `neptune-query` repository root:
21+
22+
```
23+
poetry run python -m neptune_api_codegen.cli
24+
```
25+
26+
By default this performs a dry-run:
27+
- copies swagger/proto inputs from the backend repo into a temporary work dir
28+
- generates OpenAPI, Python client code, and Python protobuf modules there
29+
- removes the temporary dir afterwards
30+
31+
To apply the change to `src/neptune_query/generated/`, run with `--update`:
32+
33+
```
34+
poetry run python -m neptune_api_codegen.cli --update
35+
```
36+
37+
To keep the temporary directory for inspection:
38+
39+
```
40+
poetry run python -m neptune_api_codegen.cli --keep-tmpdir
41+
```
42+
43+
## Temporary working directory
44+
A unique working directory is created under `./tmp/` per run, for example:
45+
46+
```
47+
./tmp/neptune-api__20260114_141229_2195/
48+
├── api_spec/ # swagger + proto copied from backend + GIT_REF
49+
└── generated_python/ # openapi client + protobuf python generated here
50+
```
51+
52+
If `--keep-tmpdir` is not used, the work directory is removed.
53+
54+
## Backend repository detection
55+
If `--neptune-repo-path` is not provided, the tool attempts to auto-detect the Neptune backend repository
56+
on your local filesystem next to this project (../neptune).
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#
2+
# Copyright (c) 2025, Neptune Labs Sp. z o.o.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.

0 commit comments

Comments
 (0)