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

better export names for protocol #90

Merged
merged 2 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions livekit-protocol/generate_proto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,28 @@ protoc \

touch -a "$API_OUT_PYTHON/__init__.py"

for f in "$API_OUT_PYTHON"/*.py "$API_OUT_PYTHON"/*.pyi; do
perl -i -pe 's|^(import (livekit_egress_pb2\|livekit_room_pb2\|livekit_webhook_pb2\|livekit_ingress_pb2\|livekit_models_pb2\|livekit_agent_pb2))|from . $1|g' "$f"
done

# Patch the proto stubs

# 1. rename the files
# 2. change the imports to relative imports
# 3. add __init__.py to the directory
# 4. remove livekit_ prefix
# 5. remove _pb2 suffix

mv "$API_OUT_PYTHON/livekit_egress_pb2.py" "$API_OUT_PYTHON/egress.py"
mv "$API_OUT_PYTHON/livekit_egress_pb2.pyi" "$API_OUT_PYTHON/egress.pyi"
mv "$API_OUT_PYTHON/livekit_room_pb2.py" "$API_OUT_PYTHON/room.py"
mv "$API_OUT_PYTHON/livekit_room_pb2.pyi" "$API_OUT_PYTHON/room.pyi"
mv "$API_OUT_PYTHON/livekit_webhook_pb2.py" "$API_OUT_PYTHON/webhook.py"
mv "$API_OUT_PYTHON/livekit_webhook_pb2.pyi" "$API_OUT_PYTHON/webhook.pyi"
mv "$API_OUT_PYTHON/livekit_ingress_pb2.py" "$API_OUT_PYTHON/ingress.py"
mv "$API_OUT_PYTHON/livekit_ingress_pb2.pyi" "$API_OUT_PYTHON/ingress.pyi"
mv "$API_OUT_PYTHON/livekit_models_pb2.py" "$API_OUT_PYTHON/models.py"
mv "$API_OUT_PYTHON/livekit_models_pb2.pyi" "$API_OUT_PYTHON/models.pyi"
mv "$API_OUT_PYTHON/livekit_agent_pb2.py" "$API_OUT_PYTHON/agent.py"
mv "$API_OUT_PYTHON/livekit_agent_pb2.pyi" "$API_OUT_PYTHON/agent.pyi"

perl -i -pe 's|^(import (livekit_egress_pb2\|livekit_room_pb2\|livekit_webhook_pb2\|livekit_ingress_pb2\|livekit_models_pb2\|livekit_agent_pb2))|from . $1|g' "$API_OUT_PYTHON"/*.py "$API_OUT_PYTHON"/*.pyi

perl -i -pe 's|livekit_(\w+)_pb2|${1}|g' "$API_OUT_PYTHON"/*.py "$API_OUT_PYTHON"/*.pyi
13 changes: 6 additions & 7 deletions livekit-protocol/livekit/protocol/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from . import livekit_agent_pb2 as agent
from . import livekit_egress_pb2 as egress
from . import livekit_ingress_pb2 as ingress
from . import livekit_models_pb2 as models
from . import livekit_room_pb2 as room
from . import livekit_webhook_pb2 as webhook

from . import agent
from . import egress
from . import ingress
from . import models
from . import room
from . import webhook
from .version import __version__

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

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import builtins
import google.protobuf.descriptor
import google.protobuf.internal.enum_type_wrapper
import google.protobuf.message
from . import livekit_models_pb2
from . import models
import sys
import typing

Expand Down Expand Up @@ -109,16 +109,16 @@ class Job(google.protobuf.message.Message):
id: builtins.str
type: global___JobType.ValueType
@property
def room(self) -> livekit_models_pb2.Room: ...
def room(self) -> models.Room: ...
@property
def participant(self) -> livekit_models_pb2.ParticipantInfo: ...
def participant(self) -> models.ParticipantInfo: ...
def __init__(
self,
*,
id: builtins.str = ...,
type: global___JobType.ValueType = ...,
room: livekit_models_pb2.Room | None = ...,
participant: livekit_models_pb2.ParticipantInfo | None = ...,
room: models.Room | None = ...,
participant: models.ParticipantInfo | None = ...,
) -> None: ...
def HasField(self, field_name: typing_extensions.Literal["_participant", b"_participant", "participant", b"participant", "room", b"room"]) -> builtins.bool: ...
def ClearField(self, field_name: typing_extensions.Literal["_participant", b"_participant", "id", b"id", "participant", b"participant", "room", b"room", "type", b"type"]) -> None: ...
Expand Down
Loading
Loading