Skip to content

Commit 1f3be20

Browse files
Publish python wheel to PyPi (opensearch-project#183)
* Additional details for python wheel. Signed-off-by: Finn Carroll <carrofin@amazon.com> * Additional details for python wheel. Signed-off-by: Finn Carroll <carrofin@amazon.com> * Changelog. Signed-off-by: Finn Carroll <carrofin@amazon.com> * Publish to PyPi CI workflow. Signed-off-by: Finn Carroll <carrofin@amazon.com> * Change wheel name to match convention -> opensearch_protobufs Signed-off-by: Finn Carroll <carrofin@amazon.com> * Change package usage to match convention import opensarch.protos -w> import opensearch.protobufs... Signed-off-by: Finn Carroll <carrofin@amazon.com> * Move pypi-publish.yml -> publish-release.yml. Signed-off-by: Finn Carroll <carrofin@amazon.com> * Move to OSB release workflow. May not want to publish on each push to main for python. gradlew tooling may check if a release already exists, python GHA does not have this safeguard. Signed-off-by: Finn Carroll <carrofin@amazon.com> * Update comments. Signed-off-by: Finn Carroll <carrofin@amazon.com> * Move wheel python to 3.10 +. Signed-off-by: Finn Carroll <carrofin@amazon.com> * Remove dedicated python publish workflow. Move into github release. Signed-off-by: Finn Carroll <carrofin@amazon.com> * Move publish workflow to py 3.10. Signed-off-by: Finn Carroll <carrofin@amazon.com> --------- Signed-off-by: Finn Carroll <carrofin@amazon.com>
1 parent 0d01c7e commit 1f3be20

5 files changed

Lines changed: 59 additions & 36 deletions

File tree

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ name: Release drafter
22

33
# Push events to every tag not containing "/"
44
#
5-
# Publish the Java JAR to Maven Local, and create release artifacts:
5+
# Create artifacts for Github release and publish to public repositories
66
# - opensearch-protobufs-java.tar.gz (Java/Maven artifacts)
77
# - opensearch-protobufs-{version}.zip (Raw proto files)
8-
#
8+
# - opensearch_protobufs-{version}-py3-none-any.whl (Python/PyPI artifacts)
9+
910
on:
1011
push:
1112
tags:
@@ -37,20 +38,30 @@ jobs:
3738
java-version: 21
3839
distribution: 'temurin'
3940
cache: gradle
41+
- name: Set up Python 3
42+
uses: actions/setup-python@v3
43+
with:
44+
python-version: '3.10'
4045
- name: Build with Gradle
4146
run: |
4247
./tools/java/package_proto_jar.sh -c true -s false
4348
./gradlew --no-daemon -Dbuild.snapshot=false publishCreatePublicationToLocalRepoRepository
4449
tar -C build -cvf "opensearch-protobufs-java.tar.gz" repository
45-
4650
- name: Create protobuf zip
4751
run: ./tools/package_proto_zip.sh
48-
52+
- name: Build python with bazel
53+
run: |
54+
mkdir -p dist
55+
bazel build //:opensearch_protos_wheel
56+
mv bazel-bin/opensearch_protobufs-*-py3-none-any.whl dist/
57+
- name: Publish python artifacts to PyPI
58+
uses: pypa/gh-action-pypi-publish@release/v1
4959
- name: Draft a release
5060
uses: softprops/action-gh-release@v1
5161
with:
5262
draft: true
5363
generate_release_notes: true
5464
files: |
5565
opensearch-protobufs-java.tar.gz
66+
opensearch_protobufs-*-py3-none-any.whl
5667
opensearch-protobufs-*.zip

BUILD.bazel

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -72,53 +72,49 @@ genrule(
7272
name = "fix_schemas_imports",
7373
srcs = [":opensearch_protos_schemas"],
7474
outs = [
75-
"opensearch/protos/schemas/common_pb2.py",
76-
"opensearch/protos/schemas/document_pb2.py",
77-
"opensearch/protos/schemas/search_pb2.py",
78-
"opensearch/protos/schemas/__init__.py",
75+
"opensearch/protobufs/schemas/common_pb2.py",
76+
"opensearch/protobufs/schemas/document_pb2.py",
77+
"opensearch/protobufs/schemas/search_pb2.py",
78+
"opensearch/protobufs/schemas/__init__.py",
7979
],
8080
cmd = """
81-
mkdir -p $(RULEDIR)/opensearch/protos/schemas
81+
mkdir -p $(RULEDIR)/opensearch/protobufs/schemas
8282
83-
# Copy and modify the schema files
8483
for pb in common document search; do
85-
cp $(BINDIR)/protos/schemas/$${pb}_python_proto_pb/protos/schemas/$${pb}_pb2.py $(RULEDIR)/opensearch/protos/schemas/
84+
cp $(BINDIR)/protos/schemas/$${pb}_python_proto_pb/protos/schemas/$${pb}_pb2.py $(RULEDIR)/opensearch/protobufs/schemas/
8685
sed -i \
87-
-e 's/from protos\\.schemas import \\([^_ ]\\+\\)_pb2 as protos_dot_schemas_dot_\\1__pb2/from opensearch.protos.schemas import \\1_pb2/g' \
88-
$(RULEDIR)/opensearch/protos/schemas/$${pb}_pb2.py
86+
-e 's/from protos\\.schemas import \\([^_ ]\\+\\)_pb2 as protos_dot_schemas_dot_\\1__pb2/from opensearch.protobufs.schemas import \\1_pb2/g' \
87+
$(RULEDIR)/opensearch/protobufs/schemas/$${pb}_pb2.py
8988
done
9089
91-
# Create schemas __init__.py
92-
touch $(RULEDIR)/opensearch/protos/schemas/__init__.py
90+
touch $(RULEDIR)/opensearch/protobufs/schemas/__init__.py
9391
""",
9492
)
9593

9694
genrule(
9795
name = "fix_services_imports",
9896
srcs = [":opensearch_protos_services"],
9997
outs = [
100-
"opensearch/protos/services/document_service_pb2.py",
101-
"opensearch/protos/services/document_service_pb2_grpc.py",
102-
"opensearch/protos/services/search_service_pb2.py",
103-
"opensearch/protos/services/search_service_pb2_grpc.py",
104-
"opensearch/protos/services/__init__.py",
98+
"opensearch/protobufs/services/document_service_pb2.py",
99+
"opensearch/protobufs/services/document_service_pb2_grpc.py",
100+
"opensearch/protobufs/services/search_service_pb2.py",
101+
"opensearch/protobufs/services/search_service_pb2_grpc.py",
102+
"opensearch/protobufs/services/__init__.py",
105103
],
106104
cmd = """
107-
mkdir -p $(RULEDIR)/opensearch/protos/services
105+
mkdir -p $(RULEDIR)/opensearch/protobufs/services
108106
109-
# Copy and modify the service files
110107
for pb in document_service search_service; do
111-
cp $(BINDIR)/protos/services/$${pb}_python_proto_pb/protos/services/$${pb}_pb2.py $(RULEDIR)/opensearch/protos/services/
112-
cp $(BINDIR)/protos/services/$${pb}_python_proto_pb/protos/services/$${pb}_pb2_grpc.py $(RULEDIR)/opensearch/protos/services/
108+
cp $(BINDIR)/protos/services/$${pb}_python_proto_pb/protos/services/$${pb}_pb2.py $(RULEDIR)/opensearch/protobufs/services/
109+
cp $(BINDIR)/protos/services/$${pb}_python_proto_pb/protos/services/$${pb}_pb2_grpc.py $(RULEDIR)/opensearch/protobufs/services/
113110
114111
# Fix imports in both pb2 and pb2_grpc files
115112
sed -i \
116-
-e 's/from protos\\.schemas import/from opensearch.protos.schemas import/g' \
117-
$(RULEDIR)/opensearch/protos/services/$${pb}_pb2*.py
113+
-e 's/from protos\\.schemas import/from opensearch.protobufs.schemas import/g' \
114+
$(RULEDIR)/opensearch/protobufs/services/$${pb}_pb2*.py
118115
done
119116
120-
# Create services __init__.py
121-
touch $(RULEDIR)/opensearch/protos/services/__init__.py
117+
touch $(RULEDIR)/opensearch/protobufs/services/__init__.py
122118
""",
123119
)
124120

@@ -139,13 +135,28 @@ py_library(
139135

140136
py_wheel(
141137
name = "opensearch_protos_wheel",
142-
distribution = "opensearch-protos",
138+
distribution = "opensearch-protobufs",
143139
python_tag = "py3",
144140
version = "0.10.0",
145141
requires = [
146142
"protobuf>=3.20.3",
147143
"grpcio>=1.68.1",
148144
],
145+
author = "OpenSearch Team",
146+
license = "Apache-2.0",
147+
classifiers = [
148+
"Intended Audience :: Developers",
149+
"License :: Apache-2.0 Software License",
150+
"Programming Language :: Python :: 3",
151+
],
152+
homepage = "https://opensearch.org/",
153+
project_urls = {
154+
"Bug Tracker": "https://github.com/opensearch-project/opensearch-protobufs/issues",
155+
"Documentation": "https://github.com/opensearch-project/opensearch-protobufs/blob/main/README.md",
156+
"Source Code": "https://github.com/opensearch-project/opensearch-protobufs",
157+
},
158+
platform = "any",
159+
python_requires = ">=3.10",
149160
deps = [
150161
":fixed_schemas",
151162
":fixed_services",

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
44

55
## [Unreleased]
66
### Added
7+
- Publish opensearch-protos python package to PyPi. ([#183](https://github.com/opensearch-project/opensearch-protobufs/pull/183))
78

89
### Changed
910
- update `score` type. ([#176](https://github.com/opensearch-project/opensearch-protobufs/pull/176))

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ RUN bazel build //:opensearch_protos_wheel
9898

9999
FROM package-bazel-python AS test-bazel-python
100100

101-
RUN pip3 install /build/bazel-bin/opensearch_protos-*-py3-none-any.whl
101+
RUN pip3 install /build/bazel-bin/opensearch_protobufs-*-py3-none-any.whl
102102
RUN python3 /build/tools/python/print_modules.py
103103

104104
#################################################

tools/python/print_modules.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
import sys
22

3-
print('Testing opensearch-protos wheel installation...')
3+
print('Testing opensearch-protobufs wheel installation...')
44
print('Python version:', sys.version)
55

6-
from opensearch.protos.schemas import common_pb2
6+
from opensearch.protobufs.schemas import common_pb2
77
print('✓ Successfully imported common_pb2')
88

9-
from opensearch.protos.schemas import document_pb2
9+
from opensearch.protobufs.schemas import document_pb2
1010
print('✓ Successfully imported document_pb2')
1111

12-
from opensearch.protos.schemas import search_pb2
12+
from opensearch.protobufs.schemas import search_pb2
1313
print('✓ Successfully imported search_pb2')
1414

1515
print('Common module attributes:', [attr for attr in dir(common_pb2) if not attr.startswith('_')][:5])
1616
print('Document module attributes:', [attr for attr in dir(document_pb2) if not attr.startswith('_')][:5])
1717
print('Search module attributes:', [attr for attr in dir(search_pb2) if not attr.startswith('_')][:5])
1818

19-
from opensearch.protos.services import document_service_pb2
19+
from opensearch.protobufs.services import document_service_pb2
2020
print('✓ Successfully imported document_service_pb2')
2121

22-
from opensearch.protos.services import search_service_pb2
22+
from opensearch.protobufs.services import search_service_pb2
2323
print('✓ Successfully imported search_service_pb2')
2424

2525
print('Document service attributes:', [attr for attr in dir(document_service_pb2) if not attr.startswith('_')][:5])

0 commit comments

Comments
 (0)