Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRAFT: Using the buf.build toolchain for generating language bindings #44

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

johnsabath
Copy link
Contributor

@johnsabath johnsabath commented Nov 22, 2022

Improves UX of building and consuming api-interfaces

  • Leverages buf's remote builds to avoid having to install most system dependencies on the host machine
  • Generates python, go, and typescript web bindings that are valid installable dependencies into a gen directory
  • Generates correct python import paths, avoiding the need for import path hacks

There are no breaking changes to the gRPC interface as a result of this change, although some imports may need to be updated.

Changes

Generation Command

yarn generate

Python SDK

Before:

# setup.py
    install_requires=[
        'grpcio==1.48.1',
        'grpcio-tools==1.48.1',
        'protobuf==3.19.5'
    ],
# some python file that wants to use grpc
thisPath = pathlib.Path(__file__).parent.parent.resolve()
genPath = thisPath / "src/stability_sdk/interfaces/gooseai/generation"
tensPath = thisPath / "src/stability_sdk/interfaces/src/tensorizer/tensors"
assert genPath.exists()
assert tensPath.exists()

sys.path.extend([str(genPath), str(tensPath)])

import stability_sdk.interfaces.gooseai.generation.generation_pb2 as generation
import stability_sdk.interfaces.gooseai.generation.generation_pb2_grpc as generation_grpc

After:

# setup.py
    install_requires=[
        'grpcio==1.51.1',
        'grpcio-tools==1.51.1',
        'protobuf==4.21.6',
        'stability-api-interfaces @ git+https://github.com/stability-ai/api-interfaces.git@js/buf-spike#subdirectory=gen/proto/python',
    ],
# some python file that wants to use grpc
import stability_api_interfaces.gooseai.generation_pb2 as generation
import stability_api_interfaces.gooseai.generation_pb2_grpc as generation_grpc

Full Diff

Go

Before:

import (
  "github.com/stability-ai/api-interfaces/gooseai/engines"
  "github.com/stability-ai/api-interfaces/gooseai/generation"
  "github.com/stability-ai/api-interfaces/gooseai/dashboard"
)

After:

import (
  "github.com/stability-ai/api-interfaces/gen/proto/go/gooseai"
)

Testing status:

@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 6, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1261 Code Smells

No Coverage information No Coverage information
2.4% 2.4% Duplication

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant