Skip to content

Commit 7df90a6

Browse files
maxxgxCopilot
authored andcommitted
chore(inspect): fix pre commit and GHA (open-edge-platform#3084)
* add pre-commit config to application Signed-off-by: Ma, Xiangxiang <[email protected]> * comment Signed-off-by: Ma, Xiangxiang <[email protected]> * use prek Signed-off-by: Ma, Xiangxiang <[email protected]> * fix style Signed-off-by: Ma, Xiangxiang <[email protected]> * geti-inspect as optional dependency for anomalib Signed-off-by: Ma, Xiangxiang <[email protected]> * ci: migrate to prek for workspace mode support - Replace custom pre-commit action with j178/prek-action@v1 - Update tox.ini to use prek instead of pre-commit - Remove obsolete custom pre-commit action - Add lock file exclusion to size check - Enables workspace mode for monorepo with multiple pre-commit configs Signed-off-by: Ma, Xiangxiang <[email protected]> * update uv lock Signed-off-by: Ma, Xiangxiang <[email protected]> * comment Signed-off-by: Ma, Xiangxiang <[email protected]> * fix style Signed-off-by: Ma, Xiangxiang <[email protected]> * fix style Signed-off-by: Ma, Xiangxiang <[email protected]> * fix style Signed-off-by: Ma, Xiangxiang <[email protected]> * add backend unit tests GHA Signed-off-by: Ma, Xiangxiang <[email protected]> * Update application/backend/src/entities/video_stream.py Co-authored-by: Copilot <[email protected]> Signed-off-by: Max Xiang <[email protected]> --------- Signed-off-by: Ma, Xiangxiang <[email protected]> Signed-off-by: Max Xiang <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 7c59626 commit 7df90a6

Some content is hidden

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

45 files changed

+1792
-829
lines changed

.github/actions/code-quality/pre-commit/action.yaml

Lines changed: 0 additions & 116 deletions
This file was deleted.

.github/workflows/_reusable-code-quality.yaml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
# Code Quality Workflow
22
#
3-
# This reusable workflow executes code quality checks using pre-commit hooks
4-
# and other quality assurance tools across multiple languages.
3+
# This reusable workflow executes code quality checks using prek (pre-commit workspace tool)
4+
# with support for monorepo configurations and multiple pre-commit configs.
55
#
66
# Key Features:
7-
# - Pre-commit hook execution
8-
# - Multi-language support
7+
# - Workspace mode support (multiple .pre-commit-config.yaml files)
8+
# - Multi-language support (Python, Node.js, etc.)
9+
# - Automatic environment management
910
# - Dependency caching
10-
# - Configurable environments
1111
# - Parallel check execution
1212
#
1313
# Process Stages:
14-
# 1. Environment Preparation:
15-
# - Python setup
16-
# - Cache configuration
14+
# 1. Checkout:
15+
# - Full repository history
16+
# - LFS file support
1717
#
18-
# 2. Quality Checks:
18+
# 2. Quality Checks (via prek):
1919
# - Code linting
2020
# - Style verification
2121
# - Type checking
2222
# - Best practices validation
23+
# - Runs appropriate hooks based on file location
2324
#
2425
# 3. Results Processing:
2526
# - Error reporting
@@ -42,7 +43,8 @@
4243
# with:
4344
# python-version: "3.11"
4445
#
45-
# Note: Requires configured pre-commit hooks in repository
46+
# Note: Uses prek-action (https://github.com/j178/prek-action) which supports
47+
# multiple pre-commit configs in workspace mode for monorepo setups
4648

4749
name: Reusable Code Quality
4850

@@ -58,15 +60,13 @@ permissions:
5860
contents: read
5961

6062
jobs:
61-
pre-commit:
63+
prek:
6264
runs-on: ubuntu-latest
63-
timeout-minutes: 5
65+
timeout-minutes: 10
6466
steps:
6567
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5
6668
with:
6769
fetch-depth: 0
6870
lfs: true
6971
persist-credentials: false
70-
- uses: ./.github/actions/code-quality/pre-commit
71-
with:
72-
python-version: ${{ inputs.python-version }}
72+
- uses: j178/prek-action@ef075ff6f80a73aeb8facb7dd22f66f344b1d17a # v1

.github/workflows/geti-inspect.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,12 @@ jobs:
9797
- name: Check source code with mypy
9898
working-directory: application/backend
9999
run: |
100-
uv run mypy . --config-file=pyproject.toml
100+
uv run --group lint mypy . --config-file=pyproject.toml
101+
102+
- name: Run unit tests
103+
working-directory: application/backend
104+
run: |
105+
uv run pytest tests/unit
101106
102107
ui-build:
103108
name: Build UI

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ repos:
1414
exclude: "docs/source/examples"
1515
- id: check-yaml
1616
- id: check-added-large-files
17+
exclude: '(^|/).*\.lock$' # Exclude lock files (uv.lock, package-lock.json, etc.)
1718
- id: debug-statements
1819
- id: detect-private-key
1920

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Pre-commit configuration for geti-inspect application (application-backend + UI)
2+
# This config uses Python 3.13+ and Node.js 24.2.0+ with tool versions matching application dependencies
3+
# Install from application/ directory with: pre-commit install --config .pre-commit-config.yaml
4+
5+
default_language_version:
6+
python: python3.13
7+
8+
repos:
9+
- repo: https://github.com/charliermarsh/ruff-pre-commit
10+
rev: "v0.14.3"
11+
hooks:
12+
# Run the linter.
13+
- id: ruff
14+
alias: ruff-application-backend
15+
name: ruff (application-backend)
16+
args: ["--fix"]
17+
# Run the formatter
18+
- id: ruff-format
19+
20+
# application-backend: python static type checking
21+
- repo: https://github.com/pre-commit/mirrors-mypy
22+
rev: "v1.18.2"
23+
hooks:
24+
- id: mypy
25+
alias: mypy-application-backend
26+
name: mypy (application-backend)
27+
additional_dependencies: [types-PyYAML, types-setuptools, types-requests]
28+
29+
# Markdown linting
30+
- repo: https://github.com/igorshubovych/markdownlint-cli
31+
rev: v0.45.0
32+
hooks:
33+
- id: markdownlint
34+
alias: markdownlint-application-backend
35+
name: markdownlint (application-backend)
36+
args: [--config=.markdownlint.yaml]

application/backend/pyproject.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ mqtt = [
5151
anomalib = { path = "../../", editable = true }
5252

5353
[tool.ruff]
54-
target-version = "py310"
54+
extend = "../../pyproject.toml"
55+
target-version = "py313"
5556
line-length = 120
5657

5758
exclude = [".venv*"]
@@ -61,7 +62,7 @@ src = ["src"]
6162
lint.select = ["ARG", "E", "F", "I", "N", "UP", "YTT", "ASYNC", "S", "COM", "C4", "FA", "PIE", "PYI", "Q", "RSE", "RET", "SIM",
6263
"TID", "TC", "PL", "RUF", "C90", "D103", "ANN001", "ANN201", "ANN205", "FAST"]
6364
lint.ignore = ["N801", "N805","N806","N807", "N818", "COM812", "RET503", "SIM108", "SIM105", "PLR2004",
64-
"RUF010", "TC001", "RUF012"]
65+
"RUF010", "TC001", "RUF012", "PLR6301", "RUF029"]
6566
lint.dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
6667

6768
[tool.pytest.ini_options]
@@ -91,6 +92,6 @@ split-on-trailing-comma = false
9192
max-args=7
9293

9394
[tool.mypy]
94-
python_version = "3.12"
95+
python_version = "3.13"
9596
ignore_missing_imports = true
9697
show_error_codes = true

application/backend/src/api/dependencies.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ async def get_job_id(job_id: str) -> UUID:
143143
"""Initializes and validates a job ID"""
144144
return get_uuid(job_id, "job")
145145

146+
146147
async def get_webrtc_manager(request: Request) -> WebRTCManager:
147148
"""Provides the global WebRTCManager instance from FastAPI application's state."""
148149
return request.app.state.webrtc_manager

application/backend/src/api/endpoints/sink_endpoints.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ async def create_sink(
9090
"""Create and configure a new sink"""
9191
# Inject project_id from URL path into the config
9292
sink_config["project_id"] = str(project_id)
93-
93+
9494
# Validate the complete config
9595
validated_sink = SinkAdapter.validate_python(sink_config)
96-
96+
9797
if validated_sink.sink_type == SinkType.DISCONNECTED:
9898
raise HTTPException(
9999
status_code=status.HTTP_400_BAD_REQUEST,
@@ -222,7 +222,7 @@ async def import_sink(
222222
try:
223223
yaml_content = await yaml_file.read()
224224
sink_data = yaml.safe_load(yaml_content)
225-
225+
226226
# Inject project_id from URL path
227227
sink_data["project_id"] = str(project_id)
228228

application/backend/src/api/endpoints/source_endpoints.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ async def create_source(
105105
"""Create and configure a new source"""
106106
# Inject project_id from URL path into the config
107107
source_config["project_id"] = str(project_id)
108-
108+
109109
# Validate the complete config
110110
validated_source = SourceAdapter.validate_python(source_config)
111-
111+
112112
if validated_source.source_type == SourceType.DISCONNECTED:
113113
raise HTTPException(
114114
status_code=status.HTTP_400_BAD_REQUEST, detail="The source with source_type=DISCONNECTED cannot be created"
@@ -233,7 +233,7 @@ async def import_source(
233233
try:
234234
yaml_content = await yaml_file.read()
235235
source_data = yaml.safe_load(yaml_content)
236-
236+
237237
# Inject project_id from URL path
238238
source_data["project_id"] = str(project_id)
239239

application/backend/src/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def clean_db() -> None:
109109
def gen_api(target_path: str) -> None:
110110
"""Generate OpenAPI specification JSON file."""
111111
# Importing create_openapi imports threading which is slow. Importing here to not slow down other cli commands.
112-
from create_openapi import create_openapi
112+
from create_openapi import create_openapi # noqa: PLC0415
113113

114114
try:
115115
create_openapi(target_path=target_path)

0 commit comments

Comments
 (0)