Skip to content

Commit

Permalink
add generate_proto.sh script
Browse files Browse the repository at this point in the history
  • Loading branch information
Michał Sośnicki committed Nov 29, 2024
1 parent 4766351 commit 660f7df
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ repos:
- grpcio-tools
- types-Pygments
- types-protobuf
exclude: "^src/neptune_api/proto/"
exclude: "^src/(neptune_api|neptune_retrieval_api)/proto/"
default_language_version:
python: python3
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,12 @@ Things to know:

Run the following command to regenerate the OpenAPI client:
```bash
scripts/update.sh https://<deployment>.neptune.ai
scripts/generate_client.sh https://<deployment>.neptune.ai
```

## Update protobuf model

Generating the protobuf model requires access to the proto files. They are not available publicly as of now.
```bash
scripts/generate_proto.sh "$HOME/Projects/neptune"
```
File renamed without changes.
46 changes: 46 additions & 0 deletions scripts/generate_proto.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash

set -euxo pipefail

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
SRC_DIR="${SCRIPT_DIR}/../src"
NEPTUNE_PROJECT_DIR="${1:-}"

if [ -z "${NEPTUNE_PROJECT_DIR}" ]; then
echo "Usage: $0 <neptune_project_dir>"
exit 1
fi

python -m grpc_tools.protoc \
--python_out="${SRC_DIR}/neptune_api/proto" \
--mypy_out="${SRC_DIR}/neptune_api/proto" \
--proto_path="${NEPTUNE_PROJECT_DIR}/libs/models/leaderboard-proto/src/main/proto" \
"${NEPTUNE_PROJECT_DIR}/libs/models/leaderboard-proto/src/main/proto/neptune_pb/ingest/v1/"*".proto" \
"${NEPTUNE_PROJECT_DIR}/libs/models/leaderboard-proto/src/main/proto/neptune_pb/ingest/v1/pub/"*".proto"

python -m grpc_tools.protoc \
--python_out="${SRC_DIR}/neptune_retrieval_api/proto" \
--mypy_out="${SRC_DIR}/neptune_retrieval_api/proto" \
--proto_path="${NEPTUNE_PROJECT_DIR}/libs/models/leaderboard-proto/src/main/proto" \
"${NEPTUNE_PROJECT_DIR}/libs/models/leaderboard-proto/src/main/proto/neptune_pb/api/model/"*".proto"

protol --create-package --in-place \
--python-out "${SRC_DIR}/neptune_api/proto" \
protoc \
--proto-path "${NEPTUNE_PROJECT_DIR}/libs/models/leaderboard-proto/src/main/proto" \
"${NEPTUNE_PROJECT_DIR}/libs/models/leaderboard-proto/src/main/proto/neptune_pb/ingest/v1/"*".proto" \
"${NEPTUNE_PROJECT_DIR}/libs/models/leaderboard-proto/src/main/proto/neptune_pb/ingest/v1/pub/"*".proto"

protol --create-package --in-place \
--python-out "${SRC_DIR}/neptune_retrieval_api/proto" \
protoc \
--proto-path "${NEPTUNE_PROJECT_DIR}/libs/models/leaderboard-proto/src/main/proto" \
"${NEPTUNE_PROJECT_DIR}/libs/models/leaderboard-proto/src/main/proto/neptune_pb/api/model/"*".proto"

for file in $(find "${SRC_DIR}/neptune_api/proto" -name "*.py" -not -name 'descriptor_pool.py'); do
sed -i "" "s/from google.protobuf import descriptor_pool/from neptune_api.proto import descriptor_pool/" "${file}"
done

for file in $(find "${SRC_DIR}/neptune_retrieval_api/proto" -name "*.py" -not -name 'descriptor_pool.py'); do
sed -i "" "s/from google.protobuf import descriptor_pool/from neptune_retrieval_api.proto import descriptor_pool/" "${file}"
done
14 changes: 0 additions & 14 deletions scripts/update_descriptor_pool.sh

This file was deleted.

0 comments on commit 660f7df

Please sign in to comment.