You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/operate/get-started/other-hardware/_index.md
+69-2
Original file line number
Diff line number
Diff line change
@@ -100,7 +100,7 @@ Authenticate your CLI session with Viam using one of the following options:
100
100
| Namespace/Organization ID | In the [Viam app](https://app.viam.com), navigate to your organization settings through the menu in upper right corner of the page. Find the **Public namespace** and copy that string. |
101
101
| Resource to add to the module (API) | The [component API](/appendix/apis/#component-apis) your module will implement. |
102
102
| Model name | Name your component model based on what it supports, for example, if it supports a model of ultrasonic sensor called “XYZ Sensor 1234” you could call your model `xyz_1234` or similar. Must be all-lowercase and use only alphanumeric characters (`a-z` and `0-9`), hyphens (`-`), and underscores (`_`). |
103
-
| Enable cloud build |You can select `No` if you will always build the module yourself before uploading it. If you select `Yes` and push the generated files (including the <file>.github</file> folder) and create a release of the format `vX.X.X`, the module will build and upload to the Viam registry and be available for all Viam-supported architectures without you needing to build for each architecture. |
103
+
| Enable cloud build | If you select `Yes`(recommended) and push the generated files (including the <file>.github</file> folder) and create a release of the format `vX.X.X`, the module will build and upload to the Viam registry and be available for all Viam-supported architectures without you needing to build for each architecture. `Yes` also makes it easier to [upload](#upload-your-module) using PyInstaller by creating a build entrypoint script. You can select `No` if you will always build the module yourself before uploading it. |
104
104
| Register module | Select `Yes` unless you are creating a local-only module for testing purposes and do not intend to upload it. |
105
105
106
106
{{< /expand >}}
@@ -752,7 +752,74 @@ Do not change the <code>module_id</code>.</p>
752
752
To package (for Python) and upload your module and make it available to configure on machines in your organization (or in any organization, depending on how you set `visibility` in the <file>meta.json</file> file):
The recommended approach for Python is to use [PyInstaller](https://pypi.org/project/pyinstaller/) to compile your module into a packaged executable: a standalone file containing your program, the Python interpreter, and all of its dependencies.
758
+
When packaged in this fashion, you can run the resulting executable on your desired target platform or platforms without needing to install additional software or manage dependencies manually.
759
+
760
+
{{% alert title="Note" color="note" %}}
761
+
To follow these PyInstaller packaging steps, you must have enabled cloud build when moving through the module generator prompts.
762
+
If you did not, you will need to manually create a <file>build.sh</file> entrypoint script.
763
+
{{% /alert %}}
764
+
765
+
To create a packaged executable:
766
+
767
+
1. First, activate the [Python virtual environment](/sdks/python/python-venv/) the module generator created for you to ensure your module has access to any required libraries.
768
+
Run the following command from inside your module's directory to activate the virtual environment:
Be sure you are within your Python virtual environment for the rest of these steps.
775
+
Your terminal prompt should include the name of your virtual environment in parentheses.
776
+
777
+
1. Edit the <file>requirements.txt</file> file, adding PyInstaller (`pyinstaller`), and the Google API Python client (`google-api-python-client`) to the list of dependencies:
778
+
779
+
```sh { class="command-line" data-prompt="$"}
780
+
pyinstaller
781
+
google-api-python-client
782
+
```
783
+
784
+
1. Install the dependencies listed in your `requirements.txt` file within your Python virtual environment using the following command:
785
+
786
+
```sh { class="command-line" data-prompt="$"}
787
+
python -m pip install -r requirements.txt -U
788
+
```
789
+
790
+
1. Then compile your module, adding the Google API Python client as a hidden import:
By default, the output directory for the packaged executable is <file>dist</file>, and the name of the executable is derived from the name of the input script (in this case, main).
803
+
804
+
We recommend you use PyInstaller with the [`build-action` GitHub action](https://github.com/viamrobotics/build-action) which provides a simple cross-platform build setup for multiple platforms: x86 and Arm Linux distributions, and MacOS.
805
+
See [Update an existing module using a GitHub action](/how-tos/manage-modules/#update-an-existing-module-using-a-github-action) for more information.
806
+
807
+
{{% alert title="Note" color="note" %}}
808
+
809
+
PyInstaller does not support relative imports in entrypoints (imports starting with `.`).
810
+
If you get `"ImportError: attempted relative import with no known parent package"`, set up a stub entrypoint as described on [GitHub](https://github.com/pyinstaller/pyinstaller/issues/2560).
811
+
812
+
In addition, PyInstaller does not support cross-compiling: you must compile your module on the target architecture you wish to support.
813
+
For example, you cannot run a module on a Linux `arm64` system if you compiled it using PyInstaller on a Linux `amd64` system.
814
+
Viam makes this easy to manage by providing a build system for modules.
815
+
Follow [these instructions](/cli/#using-the-build-subcommand) to automatically build for each system your module can support using Viam's [CLI](/cli/).
816
+
817
+
{{% /alert %}}
818
+
819
+
{{% /tab %}}
820
+
{{% tab name="Python: venv" %}}
821
+
822
+
You can use the following package and upload method if you opted not to enable cloud build when you ran `viam module generate`.
756
823
757
824
1. To package the module as an archive, run the following command from inside the module directory:
Copy file name to clipboardExpand all lines: docs/operate/get-started/other-hardware/manage-modules.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -101,7 +101,7 @@ For more information, see the [`viam module` command](/cli/#module).
101
101
### Update an existing module using a GitHub action
102
102
103
103
To update an existing module in the [Viam Registry](https://app.viam.com/registry) using continuous integration (CI), you can use one of two GitHub actions.
104
-
You can only use these GitHub actions if you have already created the module by running `viam module create` and `viam module update`.
104
+
You can only use these GitHub actions if you have already created the module by running `viam module create` and `viam module upload` (or `viam module generate` and opting to register the module, and then `viam module upload`).
105
105
For most use cases, we recommend the [`build-action` GitHub action](https://github.com/viamrobotics/build-action) which provides a simple cross-platform build setup for multiple platforms: x86, ARM Linux, and MacOS.
106
106
However, if you already have your own CI with access to arm runners or only intend to build on `x86` or `mac`, you may also use the [`upload-module` GitHub action](https://github.com/viamrobotics/upload-module) instead which allows you to define the exact build steps.
0 commit comments