Skip to content

Commit 4f1d69e

Browse files
committed
Protobuf schema change detected (opensearch-project#271)
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: lucy66hw <178352792+lucy66hw@users.noreply.github.com> Preprocessing - handle unamed additionalproperties (opensearch-project#272) Signed-off-by: xil <fridalu66@gmail.com> Protobuf schema change detected (opensearch-project#273) Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: lucy66hw <178352792+lucy66hw@users.noreply.github.com> Eliminate file name dependencies in Python generated protobuf code Signed-off-by: Karen X <karenxyr@gmail.com> Merge branch 'main' into pythonfile Signed-off-by: Karen X <karenxyr@gmail.com> simplify by reading proto files instead of generated py files Signed-off-by: Karen X <karenxyr@gmail.com> add unit tests Signed-off-by: Karen X <karenxyr@gmail.com> Address security vulnerabilities (opensearch-project#277) Update dependency @eslint/eslintrc to v3.2.0 (opensearch-project#278) Co-authored-by: mend-for-github-com[bot] <50673670+mend-for-github-com[bot]@users.noreply.github.com> Update dependency @eslint/eslintrc to v3.3.0 (opensearch-project#279) Co-authored-by: mend-for-github-com[bot] <50673670+mend-for-github-com[bot]@users.noreply.github.com> Update dependency @eslint/eslintrc to v3.3.1 (opensearch-project#281) Co-authored-by: mend-for-github-com[bot] <50673670+mend-for-github-com[bot]@users.noreply.github.com> More security vulnerabilities (opensearch-project#284) Signed-off-by: karenx <karenx@uber.com> Co-authored-by: karenx <karenx@uber.com> Merge remote-tracking branch 'upstream/main' into test123
1 parent c56a44a commit 4f1d69e

7 files changed

Lines changed: 843 additions & 14 deletions

File tree

.github/workflows/build-protobufs-python.yml

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,36 @@ jobs:
1010

1111
steps:
1212
- uses: actions/checkout@v4
13+
1314
- uses: actions/setup-java@v4
1415
with:
1516
distribution: temurin # Temurin is a distribution of adoptium
1617
java-version: 21
17-
- name: build protobufs python
18-
run: bazel build //:python_schemas //:python_services
18+
19+
- uses: actions/setup-python@v4
20+
with:
21+
python-version: '3.11'
22+
23+
- name: Install Python dependencies
24+
run: |
25+
python -m pip install --upgrade pip
26+
pip install pytest
27+
28+
- name: Run unit tests
29+
run: |
30+
cd tools
31+
python -m pytest test_generate_init_files.py -v --tb=short
32+
33+
- name: Build Python protobufs
34+
run: bazel build //:python_protos_all
35+
36+
- name: Test Python imports
37+
run: |
38+
# Create virtual environment for testing
39+
python -m venv test_env
40+
source test_env/bin/activate
41+
pip install grpcio protobuf
42+
43+
# Run the dedicated test script
44+
export PYTHONPATH=bazel-bin
45+
python tools/python/print_modules.py

BUILD.bazel

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,13 @@ genrule(
9797
)
9898

9999
genrule(
100-
name = "fix_python_imports",
101-
srcs = [":python_schemas", ":python_services", ":generate_pyi_files"],
100+
name = "python_protos_all",
101+
srcs = [
102+
":python_schemas",
103+
":python_services",
104+
":generate_pyi_files",
105+
"tools/generate_init_files.py",
106+
],
102107
outs = [
103108
"opensearch/protobufs/schemas/common_pb2.py",
104109
"opensearch/protobufs/schemas/common_pb2.pyi",
@@ -112,6 +117,8 @@ genrule(
112117
"opensearch/protobufs/services/search_service_pb2.py",
113118
"opensearch/protobufs/services/search_service_pb2.pyi",
114119
"opensearch/protobufs/services/search_service_pb2_grpc.py",
120+
"opensearch/__init__.py",
121+
"opensearch/protobufs/__init__.py",
115122
"opensearch/protobufs/schemas/__init__.py",
116123
"opensearch/protobufs/services/__init__.py",
117124
],
@@ -127,8 +134,8 @@ genrule(
127134
# Find and replace "from protos" with "from opensearch.protobufs" in all files
128135
find $(RULEDIR)/opensearch/protobufs/ -type f -exec sed -i 's/from protos/from opensearch.protobufs/g' {} +
129136
130-
touch $(RULEDIR)/opensearch/protobufs/schemas/__init__.py
131-
touch $(RULEDIR)/opensearch/protobufs/services/__init__.py
137+
python3 tools/generate_init_files.py $(RULEDIR)/opensearch/protobufs/schemas $(RULEDIR)/opensearch/protobufs/services
138+
132139
""",
133140
)
134141

@@ -157,6 +164,6 @@ py_wheel(
157164
platform = "any",
158165
python_requires = ">=3.10",
159166
deps = [
160-
":fix_python_imports",
167+
":python_protos_all",
161168
],
162169
)

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
99
- Add terms aggregation protos ([#268](https://github.com/opensearch-project/opensearch-protobufs/pull/268))
1010
- Preprocessing: Handle unnamed additionalProperties.([#272](https://github.com/opensearch-project/opensearch-protobufs/pull/272))
1111

12+
- Support importing without proto file name knowledge in Python generated protobuf code ([#275](https://github.com/opensearch-project/opensearch-protobufs/pull/275))
13+
1214
### Changed
1315
- Update preprocessing for x-protobuf-excluded ([#266](https://github.com/opensearch-project/opensearch-protobufs/pull/266))
1416
- Fix aggregations protos ([#270](https://github.com/opensearch-project/opensearch-protobufs/pull/270))

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Generate protobuf libraries for your preferred language:
1717
bazel build //:java_protos_all
1818

1919
# Python
20-
bazel build //:python_schemas //:python_services
20+
bazel build //:python_protos_all
2121

2222
# Go
2323
bazel build //:go_protos_all
@@ -109,16 +109,16 @@ SearchResponse response = client.search(request);
109109
### Python
110110

111111
```python
112-
from opensearch.protobufs.schemas import search_pb2
113-
from opensearch.protobufs.services import search_service_pb2
112+
from opensearch.protobufs.schemas import SearchRequest, BulkRequest, IndexDocumentRequest
113+
from opensearch.protobufs.services import SearchServiceStub
114114

115115
# Use generated message types
116-
request = search_pb2.SearchRequest()
116+
request = SearchRequest()
117117
request.query = "elasticsearch"
118118
request.size = 10
119119

120120
# Use generated gRPC clients
121-
client = search_service_pb2.SearchServiceStub(channel)
121+
client = SearchServiceStub(channel)
122122
response = client.Search(request)
123123
```
124124

@@ -135,8 +135,8 @@ bazel-bin/protos/services/*_go_proto_pb/protos/services/*.pb.go
135135
bazel-bin/libjava_protos_all.jar
136136

137137
# Python
138-
bazel-bin/protos/schemas/*_python_proto_pb/protos/schemas/*_pb2.py
139-
bazel-bin/protos/services/*_python_proto_pb/protos/services/*_pb2.py
138+
bazel-bin/opensearch/protobufs/schemas/
139+
bazel-bin/opensearch/protobufs/services/
140140
```
141141

142142
## Intended usage of the repo

0 commit comments

Comments
 (0)