diff --git a/cyber/python/README.md b/cyber/python/README.md index 63018ad3e24c79bb228ea95ba2cc9407005a5805..12a8de985d1dd212a50811cb3021f2bdec7e6e86 100644 --- a/cyber/python/README.md +++ b/cyber/python/README.md @@ -1,10 +1,16 @@ -# 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.