Skip to content

Commit

Permalink
chore: implement python stub codegen (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzalezzfelipe authored Jul 7, 2024
1 parent 8a30144 commit b8d699f
Show file tree
Hide file tree
Showing 9 changed files with 197 additions and 3 deletions.
36 changes: 36 additions & 0 deletions .github/actions/publish-python/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: "Publish python"
description: 'Publishes python package to PyPI'
inputs:
registry-token:
description: token to authenticate to pypi
required: false
mode:
description: supported values are 'release' and 'dry-run'
required: true

runs:
using: 'composite'
steps:

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Install Poetry
run: pip install --no-input poetry

- name: Publish dry run
if: inputs.mode == 'dry-run'
working-directory: codegen/python
shell: bash
run: |
poetry publish --build --dry-run
- name: Publish to PyPI
if: inputs.mode == 'release'
working-directory: codegen/python
shell: bash
run: |
poetry config pypi-token.pypi "{% raw %}${{ inputs.registry-token }}{% endraw %}"
poetry publish --build
3 changes: 3 additions & 0 deletions .github/workflows/generate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ jobs:
- name: Generate code
run: buf generate proto

- name: Fix python imports
run: find gen/python/utxorpc_spec -type f -exec sed -i '' 's@from utxorpc@from utxorpc_spec.utxorpc@g' {} \;

- name: Create codegen artifact
uses: actions/upload-artifact@v4
with:
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/publish-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@ jobs:
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
mode: ${{ inputs.mode }}

publish-python:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- uses: actions/download-artifact@v4
with:
name: codegen
path: ./codegen

- uses: ./.github/actions/publish-python
with:
registry-token: ${{ secrets.PYPI_REGISTRY_TOKEN }}
mode: ${{ inputs.mode }}

publish-node:
runs-on: ubuntu-latest

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ gen/node/src/
gen/openapi/
gen/rust/src
!gen/rust/src/lib.rs
gen/python/utxorpc_spec
gen/python/dist
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@

all:
buf generate proto
find gen/python/utxorpc_spec -type f -exec sed -i '' 's@from utxorpc@from utxorpc_spec.utxorpc@g' {} \;
17 changes: 14 additions & 3 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ plugins:
out: gen/go
opt:
- paths=source_relative

- plugin: buf.build/connectrpc/go
out: gen/go
opt:
- paths=source_relative

# rust

- plugin: prost
Expand All @@ -45,13 +45,24 @@ plugins:
- compile_well_known_types
- extern_path=.google.protobuf=::pbjson_types

# python

- plugin: buf.build/protocolbuffers/python
out: gen/python/utxorpc_spec

- plugin: buf.build/protocolbuffers/pyi
out: gen/python/utxorpc_spec

- plugin: buf.build/grpc/python:v1.64.2
out: gen/python/utxorpc_spec

# node

- plugin: es
out: gen/node/src
opt:
- target=ts

- plugin: connect-es
out: gen/node/src
opt:
Expand Down
3 changes: 3 additions & 0 deletions gen/python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# UTxO RPC

Auto-generated structs for the UTxO RPC spec.
98 changes: 98 additions & 0 deletions gen/python/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions gen/python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[build-system] # https://python-poetry.org/docs/pyproject/#poetry-and-pep-517
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.poetry] # https://python-poetry.org/docs/pyproject/
name = "utxorpc-spec"
version = "0.5.1"
description = "Auto-generated structs for the UTxO RPC spec."
authors = ["Felipe Gonzalez <[email protected]>"]
readme = "README.md"
repository = "https://github.com/utxorpc/spec"

# Needed because Poetry ignores whatever is on .gitignore
include = ["utxorpc_spec/**/*.py", "utxorpc_spec/**/*.pyi"]

[tool.poetry.dependencies] # https://python-poetry.org/docs/dependency-specification/
python = ">=3.8,<4.0"
grpcio = "^1.64.1"
protobuf = "^5.27.1"
grpc-stubs = "^1.53.0.5"

[[tool.poetry.source]]
name = "pypi"

0 comments on commit b8d699f

Please sign in to comment.