Skip to content

Commit 23f048c

Browse files
authored
Rust and Release (#151)
1 parent 2f47b8e commit 23f048c

File tree

20 files changed

+308
-198
lines changed

20 files changed

+308
-198
lines changed

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
uses: snok/install-poetry@v1
2424

2525
- name: Install package
26-
run: poetry install
26+
run: make install
2727

2828
- name: Generate docs
2929
run: |

.github/workflows/publish.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Publish to PyPI
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
8+
jobs:
9+
release:
10+
if: github.repository_owner == 'viamrobotics' && github.ref == 'refs/heads/main' && contains(fromJson('["njooma"]'), github.actor)
11+
runs-on: [self-hosted, x64]
12+
container:
13+
image: ghcr.io/viamrobotics/canon:amd64
14+
15+
steps:
16+
- name: Download Release
17+
uses: dsaltares/fetch-gh-release-asset@master
18+
with:
19+
file: 'viam_sdk.*\\.whl'
20+
regex: true
21+
target: 'dist/'
22+
23+
- name: Publish
24+
uses: pypa/gh-action-pypi-publish@release/v1
25+
with:
26+
password: ${{ secrets.PYPI_API_TOKEN }}

.github/workflows/release.yml

Lines changed: 37 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
workflow_dispatch:
55
inputs:
66
version:
7-
description: 'The type of version bump. Select "-s" for no automatic version change. See https://python-poetry.org/docs/cli/#version'
7+
description: 'The type of version bump. Select "-s" for no version change. See https://python-poetry.org/docs/cli/#version'
88
type: choice
99
required: true
1010
default: '-s'
@@ -16,29 +16,20 @@ on:
1616
- preminor
1717
- prepatch
1818
- prerelease
19-
- prerelease
20-
- prerelease
2119
- '-s'
2220

2321
jobs:
2422
prepare:
25-
# if: github.repository_owner == 'viamrobotics' && github.ref == 'refs/heads/main'
26-
# runs-on: [self-hosted, x64]
27-
# container:
28-
# image: ghcr.io/viamrobotics/canon:amd64
29-
runs-on: ubuntu-latest
23+
if: github.repository_owner == 'viamrobotics' && github.ref == 'refs/heads/main' && contains(fromJson('["njooma"]'), github.actor)
24+
runs-on: [self-hosted, x64]
25+
container:
26+
image: ghcr.io/viamrobotics/canon:amd64
3027
outputs:
3128
sha: ${{ steps.commit.outputs.commit_long_sha }}
29+
version: ${{ steps.bump_version.outputs.version }}
3230
steps:
3331
- name: Checkout Code
3432
uses: actions/checkout@v3
35-
# with:
36-
# token: ${{ secrets.REPO_READ_TOKEN }}
37-
38-
# TODO: REMOVE
39-
- uses: actions/setup-python@v4
40-
with:
41-
python-version: '3.10'
4233

4334
- name: Install Poetry
4435
uses: snok/install-poetry@v1
@@ -54,29 +45,21 @@ jobs:
5445
run: |
5546
poetry version ${{ inputs.version }}
5647
echo "SDK_VERSION=$(poetry version -s)" >> $GITHUB_ENV
57-
58-
- name: Download Compiled Rust
59-
uses: dsaltares/fetch-gh-release-asset@master
60-
with:
61-
repo: 'viamrobotics/viam-rust-sdk'
62-
file: 'libviam-.*'
63-
regex: true
64-
target: 'bin/'
48+
echo "::set-output name=version::$(poetry version -s)"
6549
6650
- name: Commit + Push
6751
id: commit
6852
uses: EndBug/[email protected]
6953
with:
7054
default_author: github_actions
71-
message: Bumping prerelease version to v${{ env.SDK_VERSION }} [skip ci]
55+
message: Bumping version to v${{ env.SDK_VERSION }} [skip ci]
7256

7357
build:
7458
needs: prepare
75-
# if: github.repository_owner == 'viamrobotics' && github.ref == 'refs/heads/main'
76-
# runs-on: [self-hosted, x64]
77-
# container:
78-
# image: ghcr.io/viamrobotics/canon:amd64
79-
runs-on: ubuntu-latest
59+
if: github.repository_owner == 'viamrobotics' && github.ref == 'refs/heads/main'
60+
runs-on: [self-hosted, x64]
61+
container:
62+
image: ghcr.io/viamrobotics/canon:amd64
8063
strategy:
8164
matrix:
8265
include:
@@ -88,39 +71,52 @@ jobs:
8871
whl: macosx_11_0_arm64
8972
- arch: linux_aarch64
9073
ext: so
91-
whl: linux_aarch64
74+
whl: manylinux2014_aarch64
9275
- arch: linux_x86_64
9376
ext: so
94-
whl: linux_x86_64
77+
whl: manylinux2014_x86_64
9578
steps:
9679
- name: Checkout Code
9780
uses: actions/checkout@v3
9881
with:
9982
ref: ${{ needs.prepare.outputs.sha }}
100-
# token: ${{ secrets.REPO_READ_TOKEN }}
101-
102-
# TODO: REMOVE
103-
- uses: actions/setup-python@v4
104-
with:
105-
python-version: '3.10'
10683

10784
- name: Install Poetry
10885
uses: snok/install-poetry@v1
10986

11087
- name: Install package
11188
run: poetry install
11289

113-
- name: Copy
114-
run: cp bin/libviam-${{ matrix.arch }}.${{ matrix.ext }} src/viam/rpc/libviam.${{ matrix.ext }}
90+
- name: Download binary
91+
run: curl -sL -o src/viam/rpc/libviam.${{ matrix.ext }} https://github.com/viamrobotics/viam-rust-sdk/releases/latest/download/libviam-${{ matrix.arch }}.${{ matrix.ext }}
11592

11693
- name: Build
117-
run: poetry build
94+
run: poetry build -f wheel
11895

11996
- name: Rename
120-
run: mv dist/viam-$(poetry run python -c "import viam; print(viam.__version__)")-py3-none-any.whl dist/viam-$(poetry run python -c "import viam; print(viam.__version__)")-py3-none-${{ matrix.whl }}.whl
97+
run: mv dist/viam_sdk-$(poetry run python -c "import viam; print(viam.__version__)")-py3-none-any.whl dist/viam_sdk-$(poetry run python -c "import viam; print(viam.__version__)")-py3-none-${{ matrix.whl }}.whl
12198

12299
- name: Upload artifacts
123100
uses: actions/upload-artifact@v3
124101
with:
125102
name: dist
126103
path: dist
104+
105+
release:
106+
needs: [prepare, build]
107+
if: github.repository_owner == 'viamrobotics' && github.ref == 'refs/heads/main'
108+
runs-on: [self-hosted, x64]
109+
container:
110+
image: ghcr.io/viamrobotics/canon:amd64
111+
112+
steps:
113+
- uses: actions/download-artifact@v3
114+
115+
- name: Release
116+
uses: softprops/action-gh-release@v1
117+
with:
118+
tag_name: v${{ needs.prepare.outputs.version }}
119+
files: dist/*
120+
draft: true
121+
prerelease: ${{ contains(inputs.version, 'pre') }}
122+
fail_on_unmatched_files: true

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
uses: snok/install-poetry@v1
2828

2929
- name: Install package
30-
run: poetry install
30+
run: make install
3131

3232
- name: Lint
3333
run: make lint

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ dmypy.json
130130
.pyre/
131131

132132
# Tools
133+
bin/
133134
**/.DS_Store
134135

135136
# license finder

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ _test_docs:
4343
test_docs:
4444
kill -9 `ps aux | grep "[e]xamples.server.v1.server" | awk '{print $$2}'` || true
4545
poetry run python3 -m examples.server.v1.server 0.0.0.0 9091 quiet &
46+
sleep 3
4647
poetry run make _test_docs
4748
kill -9 `ps aux | grep "[e]xamples.server.v1.server" | awk '{print $$2}'`
4849

README.md

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,44 @@
88
> **Warning**
99
> This is an alpha release of the Viam Python SDK. Stability is not guaranteed. Breaking changes are likely to occur, and occur often.
1010
11-
## Installation - pre PyPI
11+
## Installation
12+
Currently, we have pre-built binaries for macOS (both Intel and Apple Silicon), along with Linux (x86 and aarch64) that you can install via pip
1213

13-
To install the Viam Python SDK from the current `main` branch, use the following command:
14+
`pip install viam-sdk`
1415

15-
```
16-
pip install git+https://github.com/viamrobotics/python-sdk.git
17-
```
18-
19-
To install the the Viam Python SDK from a specific branch or commit, use the following command:
20-
21-
```
22-
pip install git+https://github.com/viamrobotics/python-sdk.git@FULL_COMMIT_HASH
23-
```
16+
If your system is not supported, read further on how to install from source.
2417

2518
### Upgrading
2619

2720
> **Note**
28-
> Because the SDK is under active development, we suggest that you upgrade the package frequently.
29-
21+
> Because the SDK is under active development, we suggest that you upgrade the package frequently.
22+
3023
To upgrade, simply run the `pip install` command with the `-U` option:
24+
`pip install -U viam-sdk`
25+
26+
### Installing from Source
27+
The Viam Python SDK uses native libraries to support communication over WebRTC, which will allow you to connect to robots that are not on the same network. In order to facilitate that communication, there is a [Rust SDK](https://github.com/viamrobotics/viam-rust-sdk) that contains the necessary protocols. Therefore, to build from source, you will need both the Rust SDK and the Rust compiler.
28+
29+
1. Download/clone this repository
30+
1. Download/clone the [Rust SDK](https://github.com/viamrobotics/viam-rust-sdk)
31+
1. [Install Rust](https://www.rust-lang.org/tools/install) if not already available
32+
1. From the `viam-rust-sdk` directory, run `cargo build`
33+
* You can optionally provide the `--release` flag: `cargo build --release`
34+
1. Find the compiled library in `viam-rust-sdk/target/debug/libviam.*`
35+
* If you provided the `--release` flag, the enclosing directory will be `release`: `viam-rust-sdk/target/release/libviam.*`
36+
* The extension of the executable will depend on your operating system. For example, on macOS it will be `libviam.dylib`, whereas on Linux it will be `libviam.so`
37+
1. Copy the compiled library to the directory `viam-python-sdk/src/viam/rpc/`
38+
1. From the `viam-python-sdk` directory, run `poetry build` to create an installable package
39+
1. Find the newly created installable package located in `viam-python-sdk/dist/` and pip install it directly, e.g.: `pip install viam-python-sdk/dist/viam_sdk-0.1.0-py3-none-any.whl`
3140

32-
```
33-
pip install -U git+https://github.com/viamrobotics/python-sdk.git
34-
```
41+
42+
If you do **NOT** need communication over WebRTC (and thus, do not need the native library), the steps are:
43+
44+
1. Download/clone this repository
45+
1. Run `poetry build` from the `viam-python-sdk` directory
46+
1. Find the newly created installable package located in `viam-python-sdk/dist/` and pip install it directly, e.g.: `pip install viam-python-sdk/dist/viam_sdk-0.1.0-py3-none-any.whl`
47+
1. Ensure that every connection has the option `disable_webrtc` set to `True`: `viam.rpc.dial.DialOptions(disable_webrtc=True)`
48+
* For more information about connecting to a robot, see the [documentation](https://python.viam.dev) and [example usage](https://python.viam.dev/examples/example.html)
3549

3650
## Configure a client application at [app.viam.com](https://app.viam.com)
3751

@@ -47,7 +61,7 @@ To create a client application, to navigate to [app.viam.com](https://app.viam.c
4761
3. Wait until the robot shows as connected. If this doesn't happen try restarting the viam-server:
4862
```
4963
sudo systemctl restart viam-server
50-
```
64+
```
5165
5266
Next, select the `CONNECT` tab in the Viam Web UI, and copy the boilerplate code from the section labeled `Python SDK`.
5367

bin/libviam-linux_aarch64.so

-23.2 MB
Binary file not shown.

bin/libviam-linux_x86_64.so

-23.7 MB
Binary file not shown.

bin/libviam-macosx_arm64.dylib

-14.8 MB
Binary file not shown.

0 commit comments

Comments
 (0)