Skip to content

Commit 1eec96f

Browse files
authored
Merge pull request #497 from DeepWaterExploration/feature/ci-cd-linting
Feature/ci cd linting
2 parents ab55d37 + f247a5c commit 1eec96f

103 files changed

Lines changed: 4602 additions & 4333 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,3 @@ contact_links:
33
- name: 📚 Documentation
44
url: https://docs.dwe.ai/
55
about: View our Setup Documentation
6-
- name: 💬 Community Forums
7-
url: https://discuss.dwe.ai/
8-
about: Join our Forums to ask questions and get help!

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,21 @@
1-
# Description
1+
## Summary
22

3-
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.
3+
[Explain the *what* and *why* of this PR.]
44

5-
Fixes #[insert issue number(s) here]
5+
Fixes #[issue number(s) here]
66

77
## Type of change
88

9-
Please select all that apply.
9+
- [ ] Bug fix
10+
- [ ] Feature / Refactor
11+
- [ ] Breaking change
12+
- [ ] Misc.
1013

11-
- [ ] Bug fix (non-breaking change which fixes an issue)
12-
- [ ] New feature (non-breaking change which adds functionality)
13-
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
14-
- [ ] This change requires a documentation update
15-
- [ ] Other: [describe here]
14+
## Quick Checklist
1615

17-
# How Has This Been Tested?
18-
19-
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
20-
21-
- [ ] Make sure code runs/builds on Linux **[REQUIRED]**
22-
- [ ] Code produces no console errors upon launching the software
23-
- [ ] Other (add any other tests run)
24-
25-
# Checklist:
26-
27-
- [ ] My code follows the style guidelines of this project
28-
- [ ] I have performed a self-review of my own code
29-
- [ ] I have added 1 or more reviewers to my pull request
30-
- [ ] Reviewer has run the above tests to verify
31-
- [ ] I have commented my code, particularly in hard-to-understand areas
32-
- [ ] I have made corresponding changes to the documentation
33-
- [ ] My changes generate no new warnings
34-
- [ ] Myself or a reviewer has tested my code to prove my fix is effective or that my feature works
35-
- [ ] New and existing unit tests pass locally with my changes (if applicable)
36-
- [ ] Any dependent changes have been merged and published in downstream modules
16+
- [ ] I have reviewed my own code.
17+
- [ ] I have tested these changes locally.
18+
- [ ] I have tested these changes on the following platforms (optional):
19+
- [ ] SVC
20+
- [ ] microSVC (optional)
21+
- [ ] SVC Pro

.github/workflows/backend.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Backend CI
2+
3+
on:
4+
# Commented to avoid double runs
5+
push:
6+
branches:
7+
- main
8+
# - "feature/**"
9+
# - "fix/**"
10+
# - "bugfix/**"
11+
# - "refactor/**"
12+
# paths:
13+
# - backend_py/**
14+
# - ".github/workflows/backend.yml"
15+
pull_request:
16+
branches: ["main"]
17+
18+
jobs:
19+
build:
20+
runs-on: ubuntu-22.04
21+
22+
defaults:
23+
run:
24+
working-directory: ./backend_py
25+
26+
steps:
27+
- uses: actions/checkout@v4
28+
29+
- name: Install Python
30+
uses: actions/setup-python@v5
31+
with:
32+
python-version: "3.11"
33+
34+
- name: Install dependencies
35+
run: | # TODO: switch to using proper dev dependencies
36+
sudo apt-get install build-essential libdbus-glib-1-dev libdbus-1-dev libpython3-dev -y # For dbus-python
37+
python -m pip install --upgrade pip
38+
pip install -r requirements.txt
39+
pip install ruff bandit ty # dev dependencies
40+
41+
- name: Ruff linting
42+
run: ruff check --output-format=github .
43+
44+
- name: Ruff formatting
45+
run: ruff format --check .
46+
47+
- name: Bandit security check (high severity)
48+
run: bandit -r . -lll
49+
50+
- name: Type checking (ty)
51+
run: ty check

.github/workflows/frontend.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Frontend CI
2+
3+
on:
4+
# Commented to avoid double runs
5+
push:
6+
branches:
7+
- main
8+
# - "feature/**"
9+
# - "fix/**"
10+
# - "bugfix/**"
11+
# - "refactor/**"
12+
# paths:
13+
# - frontend/**
14+
# - ".github/workflows/frontend.yml"
15+
pull_request:
16+
branches: ["main"]
17+
18+
jobs:
19+
Frontend:
20+
runs-on: ubuntu-22.04
21+
22+
defaults:
23+
run:
24+
working-directory: ./frontend
25+
26+
steps:
27+
- name: "Checkout code"
28+
uses: actions/checkout@v6
29+
30+
- name: "Set up Node.js"
31+
uses: actions/setup-node@v6
32+
with:
33+
node-version: "22"
34+
cache: "npm"
35+
cache-dependency-path: "./frontend/package-lock.json"
36+
37+
- name: "Install frontend dependencies"
38+
run: npm ci
39+
40+
- name: "Run frontend linting"
41+
run: npm run lint
42+
43+
- name: "Security audit"
44+
run: npm audit --audit-level=high
45+
46+
- name: "Build frontend"
47+
run: npm run build

backend_py/pyproject.toml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[tool.ruff]
2+
line-length = 88
3+
indent-width = 4
4+
exclude = ["v4l2.py"] # exclude v4l2.py, since it's included as a lib directly
5+
6+
[tool.ruff.lint]
7+
select = [
8+
# pycodestyle
9+
"E",
10+
# Pyflakes
11+
"F",
12+
# pyupgrade
13+
"UP",
14+
# flake8-bugbear
15+
"B",
16+
# flake8-simplify
17+
"SIM",
18+
# isort
19+
"I",
20+
"ANN2",
21+
]
22+
23+
[tool.ruff.format]
24+
quote-style = "double"
25+
indent-style = "space"
26+
27+
[tool.ty.rules]

backend_py/run.py

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,37 @@
1-
# run.py runs the backend, creating a async socketio server and a FastAPI web framework, then
2-
# both are passed into a Server instance to handle logic, and a combination of the two is hosted
3-
# as a uvicorn server, which handles traffic
1+
# run.py runs the backend, creating a async socketio server and a FastAPI web
2+
# framework, then
3+
# both are passed into a Server instance to handle logic, and a combination of the
4+
# two is hosted as a uvicorn server, which handles traffic
5+
6+
import asyncio
7+
import logging
8+
from contextlib import asynccontextmanager
49

5-
from src import Server, FeatureSupport
610
import socketio
711
from fastapi import FastAPI
812
from fastapi.middleware.cors import CORSMiddleware
9-
import asyncio
10-
from contextlib import asynccontextmanager
11-
import logging
13+
14+
from src import FeatureSupport, Server
1215

1316
# TODO: narrow
1417
ORIGINS = ["*"]
1518

1619
# Use AsyncServer
1720
sio = socketio.AsyncServer(
18-
cors_allowed_origins='*', async_mode="asgi", transports=["websocket"]
21+
cors_allowed_origins="*", async_mode="asgi", transports=["websocket"]
1922
)
2023

2124

2225
# Define events
2326
@asynccontextmanager
24-
async def lifespan(app: FastAPI):
25-
server.serve()
27+
async def lifespan(app: FastAPI): # noqa: ANN201
28+
await server.serve()
2629
yield
2730
print("Shutting down server...")
31+
try:
32+
server.shutdown()
33+
except Exception as e:
34+
print(f"Error during shutdown: {e}")
2835

2936

3037
# FastAPI application
@@ -44,7 +51,12 @@ async def lifespan(app: FastAPI):
4451
# Server instance
4552
# server = Server(FeatureSupport.none(), sio, app, settings_path='.')
4653
server = Server(
47-
FeatureSupport(ttyd=True, wifi=True, serial=True), sio, app, settings_path=".", log_level=logging.DEBUG, is_dev_mode=True
54+
FeatureSupport(ttyd=True, wifi=True, serial=True),
55+
sio,
56+
app,
57+
settings_path=".",
58+
log_level=logging.DEBUG,
59+
is_dev_mode=True,
4860
)
4961

5062
# Combine FastAPI and Socket.IO ASGI apps
@@ -54,9 +66,8 @@ async def lifespan(app: FastAPI):
5466
if __name__ == "__main__":
5567
import uvicorn
5668

57-
async def main():
58-
config = uvicorn.Config(app, host="0.0.0.0",
59-
port=5000, log_level="warning")
69+
async def main() -> None:
70+
config = uvicorn.Config(app, host="0.0.0.0", port=5000, log_level="warning")
6071
server = uvicorn.Server(config)
6172
await server.serve()
6273

backend_py/src/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
from .server import *
1+
from .server import FeatureSupport, Server
2+
3+
__all__ = ["Server", "FeatureSupport"]

backend_py/src/logging/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
from .log_handler import *
2-
from .log_schemas import *
1+
from .log_handler import LogHandler
2+
from .log_schemas import LogSchema
3+
4+
__all__ = ["LogHandler", "LogSchema"]

backend_py/src/logging/log_handler.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
11
import logging
2+
23
import socketio
3-
from typing import List
4+
45
from .log_schemas import LogSchema
5-
import datetime
66

77

88
class LogHandler(logging.Handler):
99
def __init__(self, sio: socketio.AsyncServer, level: int | str = 0) -> None:
1010
super().__init__(level)
1111
self.sio = sio
12-
self.logs: List[LogSchema] = []
13-
self.to_emit: List[LogSchema] = []
14-
self.file_path = self._create_path()
15-
16-
def _create_path(self):
17-
datetime.datetime.now().strftime("%Y-%m-%d--%H-%M-%S.log")
12+
self.logs: list[LogSchema] = []
13+
self.to_emit: list[LogSchema] = []
1814

19-
def pop_logs(self):
15+
def pop_logs(self) -> list[LogSchema]:
2016
logs = self.to_emit
2117
self.to_emit = []
2218
return logs
2319

24-
def emit(self, record):
20+
def emit(self, record) -> None:
2521
log = {
2622
"timestamp": record.asctime,
2723
"level": record.levelname,

0 commit comments

Comments
 (0)