This is a fork of common intended to facilitate package building and automatic documentation generation.
Common code shared across WARG repositories, packaged as warg_common with modular builds and auto-generated Sphinx documentation.
- Modular Package Building: Select only the modules you need
- Automatic Documentation: Sphinx-generated HTML docs from Numpy-style docstrings
- Type-Annotated: Full type hints using Python's typing module
- Well-Documented: Comprehensive Numpy-style docstrings for all modules
git clone <repository-url>
cd commonpython -m venv venv
source venv/bin/activate # On Linux/Macsource venv/bin/activate
pip install -r requirements.txtBuild a wheel with selected modules:
python build_package.py camera network loggerThis will:
- Copy the specified modules to
warg_common/ - Build a wheel at
dist/warg_common-0.1.0-py3-none-any.whl
camera- Camera device abstractions (OpenCV, PiCamera2, ArducamIR)network- TCP/UDP socket wrapperslogger- Logging utilitiesdata_encoding- Position/metadata encoding/decodingimage_encoding- JPEG image encoding/decodingqr- QR code scannerkml- KML file generationhitl- Hardware-in-the-loop testingmavlink- MAVLink flight controller interfaceread_yaml- YAML configuration reader
Note: Position, location, and orientation data types are always included as they're used across modules.
python build_package.py camera network logger --docsThis generates:
- Package wheel:
dist/warg_common-0.1.0-py3-none-any.whl - HTML documentation:
dist/docs/index.html
Open dist/docs/index.html in a browser to view the documentation.
# Build without cleaning previous builds
python build_package.py camera --no-clean
# Build all modules with documentation
python build_package.py camera network logger data_encoding image_encoding qr kml hitl mavlink read_yaml --docsThe build file creates a wheel file in the dist folder. This file can simply be pip installed in any other projects.
# create a venv
python -m venv venv/
# install wheel
pip install path/to/wheel/file.whlfrom warg_common.camera import CameraOpenCV, ConfigOpenCV, CameraOption
# Create OpenCV camera
config = ConfigOpenCV(device_index=0)
success, camera = CameraOpenCV.create(width=1920, height=1080, config=config)
if success:
# Capture image
result, image = camera.run()
if result:
print(f"Captured image shape: {image.shape}")from warg_common.network.tcp import TcpClientSocket
# Connect to TCP server
success, client = TcpClientSocket.create(host="localhost", port=5000)
if success:
# Send data
client.send(b"Hello, server!")
# Receive data
success, data = client.recv(1024)
if success:
print(f"Received: {data}")
client.close()from warg_common.logger import Logger
# Create logger
success, logger = Logger.create(name="my_app", enable_log_to_file=False)
if success:
logger.info("Application started")
logger.warning("This is a warning")
logger.error("An error occurred")docs/conf.py- Sphinx configuration with Numpy docstring supportdocs/index.rst- Main documentation pagedocs/modules.rst- Auto-generated API reference (created during build)
All modules use Numpy-style docstrings:
def example_function(param1: int, param2: str) -> Tuple[bool, Optional[str]]:
"""
Short description of function.
Parameters
----------
param1 : int
Description of param1.
param2 : str
Description of param2.
Returns
-------
Tuple[bool, Optional[str]]
Success status and result string if successful, None otherwise.
"""
pass