Skip to content

Commit

Permalink
RSDK-8303: get and send versions (#689)
Browse files Browse the repository at this point in the history
  • Loading branch information
purplenicole730 authored Jul 29, 2024
1 parent 604cbac commit 211d7ac
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/update_protos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ jobs:
- name: Install package
run: poetry install --all-extras

- name: Store API version
run: |
python3 etc/_update_version_metadata.py src/viam/version_metadata.py ${{ github.event.client_payload.tag }}
echo "Updated API version to ${{ github.event.client_payload.tag }} in src/viam/version_metadata.py"
- name: Generate buf
run: make buf
env:
Expand Down
20 changes: 20 additions & 0 deletions etc/_update_version_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import re
import sys


def update_version(file_path: str, new_version: str):
with open(file_path, "r") as file:
data = file.read()

data = re.sub(r'(API_VERSION\s*=\s*)"[0-9]+\.[0-9]+\.[0-9]+"', f'\\1"{new_version}"', data)

with open(file_path, 'w') as file:
file.write(data)


if __name__ == "__main__":
if len(sys.argv) != 3:
print("Usage: python3 etc/update_version.py <file_path> <new_version>")
sys.exit(1)

update_version(sys.argv[1], sys.argv[2])
7 changes: 7 additions & 0 deletions src/viam/rpc/dial.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from grpclib.client import Channel, Stream
from grpclib.const import Cardinality
from grpclib.events import SendRequest, listen
from grpclib.metadata import Deadline, _MetadataLike
from grpclib.protocol import H2Protocol
from grpclib.stream import _RecvType, _SendType
Expand All @@ -21,6 +22,7 @@
from viam.proto.rpc.auth import AuthenticateRequest, AuthServiceStub
from viam.proto.rpc.auth import Credentials as PBCredentials
from viam.utils import to_thread
from viam.version_metadata import API_VERSION, SDK_VERSION

LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -277,15 +279,20 @@ def free_str(self, ptr: ctypes.c_void_p):


async def dial(address: str, options: Optional[DialOptions] = None) -> ViamChannel:
async def send_request(event: SendRequest):
event.metadata["viam-client"] = f"python;{SDK_VERSION};{API_VERSION}"

opts = options if options else DialOptions()
if opts.disable_webrtc:
channel = await _dial_direct(address, options)
listen(channel, SendRequest, send_request)
return ViamChannel(channel, lambda: None)
runtime = _Runtime()
path, path_ptr = await runtime.dial(address, opts)
if path:
LOGGER.info(f"Connecting to socket: {path}")
chan = Channel(path=path, ssl=None)
listen(chan, SendRequest, send_request)

def release():
runtime.free_str(path_ptr)
Expand Down
4 changes: 4 additions & 0 deletions src/viam/version_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import viam

API_VERSION = "0.1.327"
SDK_VERSION = viam.__version__

0 comments on commit 211d7ac

Please sign in to comment.