Skip to content

Commit 4f8fe31

Browse files
committed
chore: Adds local linter to Makefile
1 parent 8fa4425 commit 4f8fe31

File tree

4 files changed

+73
-9
lines changed

4 files changed

+73
-9
lines changed

Makefile

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,17 @@ publish_test: ## Publish the Python package to TestPyPI
5050
@echo "Publishing package to TestPyPI..."
5151
twine upload --repository testpypi dist/*
5252

53-
linter: ## Run ruff linter with docker
54-
docker run --rm -v $(PWD):/src -w /src ghcr.io/astral-sh/ruff:0.14.2 check $$(git diff --name-only --diff-filter=ACMR | grep '\.py$$' | xargs)
53+
linter-docker: ## Run ruff linter with docker
54+
@./tools/linter.sh --docker
5555

56-
fix-linter: ## Run ruff linter with docker
57-
docker run --rm -v $(PWD):/src -w /src ghcr.io/astral-sh/ruff:0.14.2 check $$(git diff --name-only --diff-filter=ACMR | grep '\.py$$' | xargs) --fix
56+
linter-docker-fix: ## Run ruff linter with docker and auto-fix
57+
@./tools/linter.sh --docker --fix
5858

59+
linter: ## Run ruff linter locally
60+
@./tools/linter.sh
61+
62+
linter-fix: ## Run ruff linter locally with auto-fix
63+
@./tools/linter.sh --fix
5964

6065
publish: ## Publish Python package to PyPI
6166
@echo "Publishing package to PyPI..."

src/scanoss/gitlabqualityreport.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def _write_output(self, data: list[CodeQuality], output_file: str = None) -> boo
141141
file.close()
142142
self.print_debug(f"Wrote output to file: {output_file}")
143143
else:
144-
self.print_debug(f"Wrote output to 'stdout'")
144+
self.print_debug("Wrote output to 'stdout'")
145145
return True
146146
except Exception as e:
147147
self.print_stderr(f'Error writing output: {str(e)}')
@@ -184,7 +184,7 @@ def _produce_from_str(self, json_str: str, output_file: str = None) -> bool:
184184
self.print_debug(f"Parsing JSON string of length: {len(json_str)}")
185185
try:
186186
data = json.loads(json_str)
187-
self.print_debug(f"Successfully parsed JSON data")
187+
self.print_debug("Successfully parsed JSON data")
188188
self.print_trace(f"Parsed data structure: {type(data)}")
189189
except Exception as e:
190190
self.print_stderr(f'ERROR: Problem parsing input JSON: {e}')

src/scanoss/inspection/summary/match_summary.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,10 @@ def _get_matches_summary(self) -> ComponentMatchSummary:
216216
gitlab_matches_summary.files.append(summary_item)
217217
self.print_trace(f"Added file match for {file_name}")
218218

219-
self.print_debug(f"Match summary complete: {len(gitlab_matches_summary.files)} file matches, {len(gitlab_matches_summary.snippet)} snippet matches")
219+
self.print_debug(
220+
f"Match summary complete: {len(gitlab_matches_summary.files)} file matches, "
221+
f"{len(gitlab_matches_summary.snippet)} snippet matches"
222+
)
220223

221224
return gitlab_matches_summary
222225

@@ -237,7 +240,10 @@ def _markdown(self, gitlab_matches_summary: ComponentMatchSummary) -> str:
237240
self.print_debug("No matches to format - returning empty string")
238241
return ""
239242

240-
self.print_trace(f"Formatting {len(gitlab_matches_summary.files)} file matches and {len(gitlab_matches_summary.snippet)} snippet matches")
243+
self.print_trace(
244+
f"Formatting {len(gitlab_matches_summary.files)} file matches and "
245+
f"{len(gitlab_matches_summary.snippet)} snippet matches"
246+
)
241247

242248
# Define table headers
243249
file_match_headers = ['File', 'License', 'Similarity', 'PURL', 'Version']
@@ -304,7 +310,10 @@ def run(self):
304310
4. Outputs to file or stdout
305311
"""
306312
self.print_debug("Starting match summary generation process")
307-
self.print_trace(f"Configuration - Results path: {self.scanoss_results_path}, Output: {self.output}, Line range prefix: {self.line_range_prefix}")
313+
self.print_trace(
314+
f"Configuration - Results path: {self.scanoss_results_path}, Output: {self.output}, "
315+
f"Line range prefix: {self.line_range_prefix}"
316+
)
308317

309318
# Load and process scan results into categorized matches
310319
self.print_trace("Loading and processing scan results")

tools/linter.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env bash
2+
# SPDX-License-Identifier: MIT
3+
#
4+
# Lint Python files changed since merge base with origin/main
5+
# Usage: lint_changed_files.sh [--fix] [--docker]
6+
7+
set -e
8+
9+
# Parse arguments
10+
FIX_FLAG=""
11+
USE_DOCKER=false
12+
13+
while [[ $# -gt 0 ]]; do
14+
case $1 in
15+
--fix)
16+
FIX_FLAG="--fix"
17+
shift
18+
;;
19+
--docker)
20+
USE_DOCKER=true
21+
shift
22+
;;
23+
*)
24+
echo "Unknown option: $1"
25+
echo "Usage: $0 [--fix] [--docker]"
26+
exit 1
27+
;;
28+
esac
29+
done
30+
31+
# Find merge base with origin/main
32+
merge_base=$(git merge-base origin/main HEAD)
33+
34+
# Get all changed Python files since merge base
35+
files=$(git diff --name-only "$merge_base" HEAD | grep '\.py$' || true)
36+
37+
# Check if there are any Python files changed
38+
if [ -z "$files" ]; then
39+
echo "No Python files changed"
40+
exit 0
41+
fi
42+
43+
# Run linter
44+
if [ "$USE_DOCKER" = true ]; then
45+
# Run with Docker
46+
docker run --rm -v "$(pwd)":/src -w /src ghcr.io/astral-sh/ruff:0.14.2 check $files $FIX_FLAG
47+
else
48+
# Run locally
49+
python3 -m ruff check $files $FIX_FLAG
50+
fi

0 commit comments

Comments
 (0)