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

Use ruff to lint/format/isort #476

Open
wants to merge 21 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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 0 additions & 6 deletions .flake8

This file was deleted.

7 changes: 5 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ on:
push:
branches: [main]
pull_request_target:
branches: [main, 'rc-*']
branches: [main, "rc-*"]

jobs:
test:
if: github.repository_owner == 'viamrobotics'
runs-on: buildjet-2vcpu-ubuntu-2204
container:
image: python:${{ matrix.python-version }}
image: public.ecr.aws/docker/library/python:${{ matrix.python-version }}
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
Expand Down Expand Up @@ -44,6 +44,9 @@ jobs:
run: poetry run pip install -r requirements-test.txt
if: ${{ matrix.requirements-version == 'min' }}

- name: Type Check
run: make typecheck

- name: Lint
run: make lint

Expand Down
26 changes: 12 additions & 14 deletions .github/workflows/update_protos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ on:
jobs:
update-protos:
if: github.repository_owner == 'viamrobotics'
runs-on: [self-hosted, x64]
container:
image: ghcr.io/viamrobotics/canon:amd64
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: bufbuild/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -39,13 +37,13 @@ jobs:
run: make format

- name: Add + Commit + Open PR
uses: peter-evans/[email protected]
with:
commit-message: "[WORKFLOW] Updating protos from ${{ github.event.client_payload.repo_name }}, commit: ${{ github.event.client_payload.sha }}"
branch: "workflow/update-protos"
delete-branch: true
base: main
title: Automated Protos Update
body: This is an auto-generated PR to update proto definitions. Check the commits to see which repos and commits are responsible for the changes
assignees: njooma
reviewers: njooma
shell: bash
run: |
git checkout -b workflow/update-protos || git checkout workflow/update-protos
git add --all
git -c author.name=viambot -c [email protected] -c committer.name=GitHub -c [email protected] commit -m "[WORKFLOW] Updating protos from ${{ github.event.client_payload.repo_name }}, commit: ${{ github.event.client_payload.sha }}"
git -c pull.ff=only pull origin workflow/update-protos || true # do not fail if the branch doesn't exist
git push -f origin workflow/update-protos
gh pr view workflow/update-protos && gh pr reopen workflow/update-protos || gh pr create -B main -H workflow/update-protos -t "Automated Protos Update" -b "This is an auto-generated PR to update proto definitions. Check the commits to see which repos and commits are responsible for the changes" -a njooma -r njooma
env:
GH_TOKEN: ${{ github.token }}
69 changes: 34 additions & 35 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
{
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true,
},
"python.linting.flake8Enabled": true,
"editor.formatOnSave": true,
"python.analysis.typeCheckingMode": "basic",
"python.linting.ignorePatterns": [
"**/site-packages/**/*.py",
".vscode/*.py",
"gen/**/*",
"viam/proto/**/*"
],
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,
"editor.rulers": [
{
"column": 140,
"color": "#777777"
}
],
"python.formatting.provider": "black",
"cSpell.words": [
"frombytes",
"grpclib",
"klass",
"pointcloud",
"segmenters",
"TFLITE",
"tobytes",
"viam"
],
"isort.args": [
"-l 140 --profile black"
],
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true
},
"python.linting.flake8Enabled": true,
"editor.formatOnSave": true,
"python.analysis.typeCheckingMode": "basic",
"python.linting.ignorePatterns": [
"**/site-packages/**/*.py",
".vscode/*.py",
"gen/**/*",
"viam/proto/**/*"
],
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,
"editor.rulers": [
{
"column": 140,
"color": "#777777"
}
],
"python.formatting.provider": "black",
"cSpell.words": [
"frombytes",
"grpclib",
"klass",
"pointcloud",
"RSDK",
"segmenters",
"TFLITE",
"tobytes",
"viam"
],
"isort.args": ["-l 140 --profile black"]
}
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,24 @@ clean:
find . -type d -name '__pycache__' | xargs rm -rf

_lint:
flake8 --exclude=**/gen/**,*_grpc.py,*_pb2.py,*_pb2.pyi,.tox,**/venv/**
ruff --exclude=*_grpc.py,*_pb2.py,*_pb2.pyi,.tox .

lint:
poetry run $(MAKE) _lint

_format:
black --exclude ".*/gen/.*" ./src ./tests ./docs/examples
isort ./src ./tests ./docs/examples
ruff format ./src
ruff --select I001 --fix ./src

format:
poetry run $(MAKE) _format

_typecheck:
pyright

typecheck:
poetry run $(MAKE) _typecheck

_buf: clean
rm -rf src/viam/gen
buf generate buf.build/viamrobotics/api
Expand Down
4 changes: 1 addition & 3 deletions docs/examples/_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@
Location,
LocationAuthRequest,
LocationAuthResponse,
)
from viam.proto.app import LogEntry as LogEntryPB
from viam.proto.app import (
MarkPartAsMainRequest,
MarkPartAsMainResponse,
MarkPartForRestartRequest,
Expand Down Expand Up @@ -208,6 +205,7 @@
StreamingDataCaptureUploadRequest,
StreamingDataCaptureUploadResponse,
)
from viam.proto.common import LogEntry as LogEntryPB
from viam.utils import datetime_to_timestamp, dict_to_struct, value_to_primitive


Expand Down
2 changes: 1 addition & 1 deletion docs/examples/example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
"robot = await connect_with_channel()\n",
"camera = Camera.from_robot(robot, \"camera0\")\n",
"image = await camera.get_image(CameraMimeType.JPEG)\n",
"image.image.save(\"foo.png\")\n",
"image.save(\"foo.png\")\n",
"\n",
"# Don't forget to close the robot when you're done!\n",
"await robot.close()"
Expand Down
5 changes: 0 additions & 5 deletions examples/server/v1/services.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from datetime import datetime
from numpy.typing import NDArray
from typing import Dict, List, Optional, Tuple
from tests.mocks.services import MockMLModel, MockSLAM
Expand Down Expand Up @@ -27,7 +26,6 @@ def __init__(self, name: str):
self.point_cloud_chunks = MockSLAM.POINT_CLOUD_PCD_CHUNKS
self.cloud_slam = MockSLAM.CLOUD_SLAM
self.mapping_mode = MockSLAM.MAPPING_MODE
self.time = MockSLAM.LAST_UPDATE
super().__init__(name)

async def get_internal_state(self, **kwargs) -> List[bytes]:
Expand All @@ -39,8 +37,5 @@ async def get_point_cloud_map(self, **kwargs) -> List[bytes]:
async def get_position(self, **kwargs) -> Pose:
return self.position

async def get_latest_map_info(self, **kwargs) -> datetime:
return self.time

async def get_properties(self, **kwargs) -> Tuple[bool, MappingMode.ValueType]:
return (self.cloud_slam, self.mapping_mode)
Loading
Loading