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

[SW-164] Add ruff and black formatting to spot_wrapper #84

Merged
merged 8 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
17 changes: 0 additions & 17 deletions .github/workflows/black.yml

This file was deleted.

20 changes: 20 additions & 0 deletions .github/workflows/util_pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright (c) 2023 Boston Dynamics AI Institute, Inc. All rights reserved.

name: Util - Pre-Commit Runner

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
pre-commit:
name: util_pre-commit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: pre-commit/[email protected]
23 changes: 23 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright (c) 2023 Boston Dynamics AI Institute, Inc. All rights reserved.

repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
rev: 'v0.0.263'
hooks:
- id: ruff
args: ['--fix', '--config', 'pyproject.toml']
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
language_version: python3.10
args: ['--config', 'pyproject.toml']
verbose: true
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-yaml
- id: check-added-large-files
- id: check-toml
- id: end-of-file-fixer
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ Copyright (c) 2020 Boston Dynamics, Inc. All rights reserved.

Downloading, reproducing, distributing or otherwise using the SDK Software
is subject to the terms and conditions of the Boston Dynamics Software
Development Kit License (20191101-BDSDK-SL).
Development Kit License (20191101-BDSDK-SL).
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@ To update requirements.txt, use
```commandline
pipreqs . --force
```

# Contributing
This repository enforces `ruff` and `black` linting. To verify that your code will pass inspection, install `pre-commit` and run:
```bash
pre-commit install
pre-commit run --all-files
```
48 changes: 48 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[tool.ruff]
# Enable pycodestyle (`E`), Pyflakes (`F`), and import sorting (`I`)
select = ["E", "F", "I"]
ignore = []
fixable = ["A", "B", "C", "D", "E", "F", "G", "I", "N", "Q", "S", "T", "W", "ANN", "ARG", "BLE", "COM", "DJ", "DTZ", "EM", "ERA", "EXE", "FBT", "ICN", "INP", "ISC", "NPY", "PD", "PGH", "PIE", "PL", "PT", "PTH", "PYI", "RET", "RSE", "RUF", "SIM", "SLF", "TCH", "TID", "TRY", "UP", "YTT"]
khughes-bdai marked this conversation as resolved.
Show resolved Hide resolved
unfixable = []
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".hg",
".mypy_cache",
".nox",
".pants.d",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"venv",
"docker/ros",
]
line-length = 120
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
target-version = "py38"

[tool.ruff.per-file-ignores]
"__init__.py" = ["F401"]

[tool.ruff.mccabe]
max-complexity = 10

[tool.black]
line-length = 120
target-version = ['py38']
include = '\.pyi?$'
force-exclude = '''
/(
)/
'''
preview = true
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from setuptools import setup, find_packages
from setuptools import find_packages, setup

setup(
name="spot_wrapper",
Expand Down
11 changes: 4 additions & 7 deletions spot_wrapper/cam_webrtc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,16 @@ def send_sdp_answer_to_spot_cam(self, token, offer_id, sdp_answer):
server_url = f"https://{self.hostname}:{self.sdp_port}/{self.sdp_filename}"

payload = {"id": offer_id, "sdp": base64.b64encode(sdp_answer).decode("utf8")}
r = requests.post(
server_url, verify=self.cam_ssl_cert, json=payload, headers=headers
)
r = requests.post(server_url, verify=self.cam_ssl_cert, json=payload, headers=headers)
if r.status_code != 200:
raise ValueError(r)

async def start(self):
# first get a token
try:
token = self.get_bearer_token()
except:
except Exception as e:
print(f"Could not get bearer token, mocking instead. Exception: {e}")
token = self.get_bearer_token(mock=True)

offer_id, sdp_offer = self.get_sdp_offer_from_spot_cam(token)
Expand All @@ -101,9 +100,7 @@ async def _on_ice_connection_state_change():
print(f"ICE connection state changed to: {self.pc.iceConnectionState}")

if self.pc.iceConnectionState == "checking":
self.send_sdp_answer_to_spot_cam(
token, offer_id, self.pc.localDescription.sdp.encode()
)
self.send_sdp_answer_to_spot_cam(token, offer_id, self.pc.localDescription.sdp.encode())

@self.pc.on("track")
def _on_track(track):
Expand Down
Loading
Loading