Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WORK IN PROGRESS: test linting #21

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/code-qa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Code-QA

on: push

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: 3.8.18
architecture: x64
- name: Checkout
uses: actions/checkout@v4
- name: Install deps
run: |
pip install mypy==1.8.0 pylint==3.2.5 ruff==0.1.14 pylint-protobuf==0.22.0 remotivelabs-broker>=0.1.8 pytest
- name: Run lint
run: |
cd python
make
cd -
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea
*.iml
*.iml
.venv
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.8
4 changes: 3 additions & 1 deletion python/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.pyc
__pycache__
.venv
__pycache__
.*
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should ignore all dot files, lets remove ".*"

38 changes: 38 additions & 0 deletions python/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
MAKEFLAGS += -j4 -O
.DEFAULT_GOAL := lint

.PHONY: lint
lint: pylint mypy ruff-format ruff

.PHONY: pylint
pylint:
pylint .
@echo ""

.PHONY: mypy
mypy:
mypy . --config-file pyproject.toml
@echo ""

.PHONY: ruff-format
ruff-format:
ruff format --check --diff
@echo ""

.PHONY: ruff
ruff:
ruff check
@echo ""

.PHONY: lint-fix
fix: ruff-fix ruff-format-fix

.PHONY: ruff-fix
ruff-fix:
ruff check --fix
@echo ""

.PHONY: ruff-format-fix
ruff-format-fix:
ruff format
@echo ""
2 changes: 1 addition & 1 deletion python/cloud-demo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Python 3 is required

```
pip3 install -r requirements.txt
python3 cloud-demo.py \
python3 cloud_demo.py \
--url <url_from_cloud> \
--api-key <api_key_from_cloud> \
--signals Speed,SteeringWheel_Position,Accelerator_PedalPosition
Expand Down
77 changes: 0 additions & 77 deletions python/cloud-demo/cloud-demo.py

This file was deleted.

78 changes: 78 additions & 0 deletions python/cloud-demo/cloud_demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import signal as signals
import sys
import threading
from argparse import Namespace
from typing import Any

from lib import arguments
from lib.broker import Broker

# Simple program designed to be used with our cloud demo.
# It is expected that you have followed the steps at
# https://demo.remotivelabs.com and started a broker + uploaded
# a recording.

# Once you complete the stages in our cloud-demo you will get all
# information required to run this program. It will look something like:

# python3 cloud_demo.py \
# --url <broker_url> \
# --api-key <api_key> \
# --signals VehicleSpeed,ChassisAcceleratorPedalposition

expected_available_signals = [
"VehicleSpeed",
"ChassisSteeringwheelAngle",
"ChassisAcceleratorPedalposition",
"VehicleCurrentlocationLongitude",
"VehicleCurrentlocationLatitude",
]


def print_signals(frame: Any) -> None:
for s in frame:
print(s)


def main(argv: Namespace) -> None:
print(f"Connecting to {argv.url}")

broker = Broker(argv.url, argv.api_key, argv.access_token)

print("Listing available signals")
available_signals = broker.list_signal_names()
for signal in available_signals:
print(f" - {signal}")

# Sanity check so we are running against the expected recording
if available_signals != expected_available_signals:
print(
"It does not look like you have started the demo recording in cloud. \n"
"Make sure you play turning-torso-drivecycle.zip on this broker from "
"https://demo.remotivelabs.com/p/demo/brokers"
)
sys.exit(0)

# Start subscribe to selected signals
subscription = broker.subscribe(signals=argv.signals, on_frame=print_signals, changed_values_only=True)

# play demo recording
broker.play(namespace="custom_can", path="turning-torso-drivecycle.zip")

# Wait 20 seconds and then shutdown.
# Remove the lines below to just have it running
sleep(seconds=20)

print("Cancelling subscription (20 secs or ctr-c, you can change this to just keep it running)")
subscription.cancel()


def sleep(seconds: float) -> None:
lock = threading.Event()
signals.signal(signals.SIGINT, lambda signum, frame: lock.set())
lock.wait(timeout=seconds)


if __name__ == "__main__":
args = arguments.parse()
main(args)
Empty file.
8 changes: 5 additions & 3 deletions python/cloud-demo/lib/arguments.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from __future__ import annotations

import argparse


def parse(argv):
def parse() -> argparse.Namespace:
parser = argparse.ArgumentParser(description="Provide address to RemotiveBroker")

parser.add_argument(
Expand All @@ -18,7 +20,7 @@ def parse(argv):
type=str,
help="API key is required when accessing brokers running in the cloud",
required=False,
default=None
default=None,
)

parser.add_argument(
Expand All @@ -36,7 +38,7 @@ def parse(argv):
required=False,
help="Comma separated list of signal names to subscribe on",
default="Speed",
type=lambda s: [item for item in s.split(',')]
type=lambda s: list(s.split(",")),
)

args = parser.parse_args()
Expand Down
Loading