提交 80413604 编写于 作者: S storypku 提交者: Xiangquan Xiao

Docs: add BUILD/run section for doc: CyberRT Python API: an example

上级 eecab463
# Python3 Wrapper for Cyber RT
# Cyber RT Python API : An Example
## Usage
This document is an example demonstrating how to use Cyber RT Python API
to write your own Python3 programs. Please make sure you have built Apollo
successfully.
Make sure you have built Apollo successfully. Then in Python code:
## Step 1: Write your own code.
Save it as, say, `path/to/my_demo.py`.
```python3
#!/usr/bin/env python3
import sys
from cyber.python.cyber_py3 import cyber
......@@ -13,16 +19,52 @@ from cyber.python.cyber_py3 import cyber
cyber.init()
if not cyber.ok():
print('Well, something is wrong.')
print('Well, something went wrong.')
sys.exit(1)
# Do your job here.
cyber.shutdown()
```
Learn more usage from the [examples](cyber_py3/examples/) and
[tests](cyber_py3/test/).
## Step 2: Write Python rule for Bazel to build
Edit `path/to/BUILD` file, add the followng section:
```
load("@rules_python//python:defs.bzl", "py_binary")
# blablahblah...
# Add your own section here
py_binary(
name = "my_demo",
srcs = ["my_demo.py"],
deps = [
"//cyber/python/cyber_py3:cyber",
],
)
```
**Note**: Like C++, Python code is also managed by Bazel starting from Apollo 6.0.
Please refer to [How to Build and Run Python Apps in Apollo](../../docs/howto/how_to_build_and_run_python_app.md) for more on that.
## Step 3: Build and run the demo program
Now you can run the following commands to build and run the demo program.
```
bazel build //path/to:my_demo
./bazel-bin/path/to/my_demo
```
Or simply run
```
bazel run //path/to:my_demo
```
## More Examples ...
Learn more Cyber RT Python examples under the [examples](cyber_py3/examples/) and
[tests](cyber_py3/test/) directory.
**Note:** Like C++ files, Python files are also managed by Bazel since Apollo 6.0. You can take
[how_to_build_and_run_python_app.md](../../docs/howto/how_to_build_and_run_python_app.md)
as reference.
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册