Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2702b33
feat: Add minimal code quality infrastructure
d-ulker Sep 19, 2025
f6d3eb9
feat: Add comprehensive monster PR prevention system
d-ulker Sep 19, 2025
4048a0b
feat: Adjust PR size limits for ML/AI project flexibility
d-ulker Sep 19, 2025
a66762a
fix: Correct indentation in PR scope checker script
d-ulker Sep 19, 2025
6594ad6
fix: revert fastapi-to-flask migration, keep only code quality tooling
d-ulker Sep 19, 2025
5c0342d
feat: Implement Complete Automated Code Quality Enforcement System
deepsource-autofix[bot] Sep 20, 2025
dbede7b
fix console script entry points
d-ulker Sep 20, 2025
bbe861a
Merge branch 'feat/dl-minimal-code-quality' of github.com:uelkerd/SAM…
d-ulker Sep 20, 2025
1c4153f
fix: update setup.cfg and pr scope checker for ranges
d-ulker Sep 20, 2025
943567c
fix: add explicit permissions to pr-scope-check workflow
d-ulker Sep 20, 2025
c0d6f87
perf: add ruff linter alongside flake8 for better performance and cov…
d-ulker Sep 20, 2025
cedb9bb
fix: secure subprocess call and remove unused import
d-ulker Sep 20, 2025
b134ce9
fix: add missing __init__.py for training module
d-ulker Sep 20, 2025
dfe7029
fix: correct console script entry points for src layout package
d-ulker Sep 20, 2025
0351335
refactor: replace FastAPI dependencies with Flask in pyproject.toml
d-ulker Sep 20, 2025
44203b6
Revert "refactor: replace FastAPI dependencies with Flask in pyprojec…
d-ulker Sep 20, 2025
1168e53
docs: update PR description to reflect actual code quality and securi…
d-ulker Sep 20, 2025
6a01c88
feat: Implement Complete Automated Code Quality Enforcement System
deepsource-autofix[bot] Sep 20, 2025
4ce874b
fix: resolve ReDoS vulnerability in branch name regex validation
d-ulker Sep 20, 2025
32be992
fix: address Copilot code review comments
d-ulker Sep 20, 2025
6c44ff2
fix: address code review comments - code quality only
d-ulker Sep 20, 2025
01577c4
fix: address critical packaging and tooling configuration issues
d-ulker Sep 20, 2025
ca5e190
fix: replace Path.is_relative_to with Python 3.8 compatible helper
d-ulker Sep 20, 2025
86d98d5
fix: restore critical tool configs in pyproject.toml
d-ulker Sep 20, 2025
a627a96
fix: remove sys.path manipulation anti-pattern from cli.py
d-ulker Sep 20, 2025
73767b4
fix: clarify bandit test skipping in Makefile
d-ulker Sep 20, 2025
3ba09ee
fix: eliminate unreachable code in run_command function
d-ulker Sep 20, 2025
1ff282a
fix: remove redundant setup.cfg for single source of truth
d-ulker Sep 20, 2025
473e911
fix: enable duplicate code detection in pylint config
d-ulker Sep 20, 2025
3fd5519
Fix mypy syntax errors and package structure
d-ulker Sep 20, 2025
d0b9379
Fix emotion model ID configuration to use DeBERTa instead of DistilRo…
d-ulker Sep 27, 2025
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
78 changes: 78 additions & 0 deletions .github/workflows/pr-scope-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: PR Scope Check

permissions:
contents: read
pull-requests: read

on:
pull_request:
types: [opened, synchronize, reopened]

jobs:
scope-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Get full history for proper diff

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.8'

- name: Install dependencies
run: |
python -m pip install --upgrade pip

- name: Run PR Scope Check
run: |
python scripts/check_pr_scope.py --strict
continue-on-error: false

- name: Check branch naming
run: |
BRANCH_NAME="${{ github.head_ref }}"
if [[ ! $BRANCH_NAME =~ ^(feat|fix|chore|refactor|docs|test)/[a-z]+(-[a-z]+)*$ ]]; then
echo "❌ Branch name must follow pattern: type/short-description"
echo " Current: $BRANCH_NAME"
echo " Examples: feat/add-user-auth, fix/validate-input, chore/update-deps"
exit 1
fi
echo "✅ Branch name follows convention: $BRANCH_NAME"

- name: Check PR size limits
run: |
# Get the base branch for comparison
BASE_BRANCH="${{ github.base_ref }}"

# Count files changed
FILES_CHANGED=$(git diff --name-only origin/$BASE_BRANCH | wc -l)
echo "Files changed: $FILES_CHANGED"

# Count lines changed
LINES_CHANGED=$(git diff --stat origin/$BASE_BRANCH | tail -1 | awk '{
ins=0; del=0;
for(i=1;i<=NF;i++) {
if ($i ~ /insertion/) {ins=$(i-1)}
if ($i ~ /deletion/) {del=$(i-1)}
}
if(ins=="") ins=0;
if(del=="") del=0;
print ins+del
}')
LINES_CHANGED=${LINES_CHANGED:-0}
echo "Lines changed: $LINES_CHANGED"

# Check limits
if [ "$FILES_CHANGED" -gt 50 ]; then
echo "❌ Too many files changed: $FILES_CHANGED (max 50)"
exit 1
fi

if [ "$LINES_CHANGED" -gt 1500 ]; then
echo "❌ Too many lines changed: $LINES_CHANGED (max 1500)"
exit 1
fi

echo "✅ PR size within limits: $FILES_CHANGED files, $LINES_CHANGED lines"
25 changes: 25 additions & 0 deletions .gitmessage.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# SAMO-DL Commit Message Template
#
# Format: <type>(<scope>): <subject>
#
# Types:
# feat: A new feature
# fix: A bug fix
# chore: Changes to the build process or auxiliary tools/libraries
# refactor: A code change that neither fixes a bug nor adds a feature
# docs: Documentation only changes
# test: Adding missing tests or correcting existing tests
#
# Rules:
# - ONE purpose per commit (no "and", "also", "plus")
# - Subject line < 50 characters
# - Use imperative mood ("Add" not "Added")
# - No period at end of subject line
#
# Examples:
# feat: add user authentication system
# fix: resolve memory leak in model loading
# chore: update dependency versions
# refactor: simplify rate limiter logic
# docs: update API documentation
# test: add unit tests for validation functions
202 changes: 14 additions & 188 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,82 +1,4 @@
# Comprehensive Code Quality Prevention System for SAMO-DL
# This configuration prevents ALL recurring DeepSource issues from ever happening again
#
# TODO: Re-enable all disabled hooks once configuration issues are resolved
# Issue: https://github.com/uelkerd/SAMO--DL/issues/106
#
# Disabled hooks and their status:
# ✅ Bandit: RE-ENABLED - Split into targeted hooks: changed files + tests (B101 skipped)
# ✅ Safety: RE-ENABLED - Local hook with safety package, runs on push, scans all deps
# ✅ Docformatter: RE-ENABLED - Local hook with docformatter package for reliability
# ✅ Flynt: RE-ENABLED - Fully configured with always_run and pass_filenames for consistency
# - Local hooks: Configuration format issues (exclude field format) - FIXED: Updated to single-line format
#
# IMPROVEMENTS IMPLEMENTED:
# ✅ Global exclude pattern implemented - all hooks now inherit from top-level exclude
# ✅ Individual exclude patterns removed from active hooks (black, isort, ruff, mypy)
# ✅ Bandit split into targeted hooks: changed files (all rules) + tests (B101 skipped)
# ✅ Safety implemented as local hook with safety package, optimized for push-only execution
# ✅ Docformatter implemented as local hook with docformatter package for reliability
# ✅ Flynt configuration made consistent with Bandit (always_run, pass_filenames)
# ✅ Global exclude pattern enhanced to cover ALL test artifacts and build directories
# ✅ Configuration is now much more maintainable and follows best practices
# ✅ All code review comments addressed and resolved
#
# Next steps:
# 1. Test Safety hook with local implementation
# 2. Test Docformatter hook with system language configuration
# 3. Test and re-enable local hooks
# 4. Update this TODO section as hooks are re-enabled
#
# Global exclude pattern - applies to all hooks unless overridden
# Uses anchored regex with extended mode for readability and accuracy
# Comprehensive coverage: git, venvs, caches, builds, artifacts, docs, samples, test artifacts
exclude: |
(?x)^(
\.git|
\.venv|
\.env|
__pycache__|
\.pytest_cache|
\.mypy_cache|
\.ruff_cache|
build|
dist|
\.eggs|
\.tox|
\.coverage|
htmlcov|
\.cache|
\.logs|
results|
samples|
notebooks|
website|
docs/diagrams|
\.DS_Store|
artifacts|
\.benchmarks|
\.kilocode|
\.vscode|
deprecated|
test_reports|
test_report\.txt|
\.pytest_cache|
\.mypy_cache|
\.ruff_cache|
\.coverage|
coverage\.xml|
\.coveragerc|
\.gitignore-pages|
\.nojekyll|
\.deepsource\.toml|
\.pre-commit-exclude-patterns\.yaml|
trivy-results-.*\.json|
vulnerabilities-.*\.json
)$

repos:
# Basic pre-commit hooks (run first)
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
Expand All @@ -94,125 +16,29 @@ repos:
- id: fix-byte-order-marker
- id: mixed-line-ending
- id: check-ast
- id: check-added-large-files

# Python formatting and linting (in order)
- repo: https://github.com/psf/black
rev: 24.2.0
hooks:
- id: black
language_version: python3
args: [--line-length=88, --target-version=py38]
types: [python]

# Import sorting and organization
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
args: [--profile=black, --line-length=88, --py=38]
types: [python]

# Python linting with Ruff (super fast)
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.0
rev: v0.1.8
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
types: [python]
- id: ruff-format

# Type checking with MyPy
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
rev: v1.7.1
hooks:
- id: mypy
args: [--ignore-missing-imports, --python-version=3.8]
types: [python]
additional_dependencies: [types-requests, types-PyYAML]
exclude: |
(?x)(
scripts/training/bulletproof_training_cell\.py$
| scripts/training/bulletproof_training_cell_fixed\.py$
| scripts/training/final_bulletproof_training_cell\.py$
)

# Security scanning with Bandit (optimized for performance)
# Split into targeted hooks: changed files (all rules) + tests (B101 skipped)
- repo: https://github.com/PyCQA/bandit
rev: 1.7.5
- repo: https://github.com/pycqa/bandit
rev: 1.7.6
hooks:
- id: bandit
name: bandit (changed files)
# Scan only changed Python files, enforce all rules
types: [python]
exclude: '^(tests/|.*_test\.py$)'

- id: bandit
name: bandit (tests, B101 skipped)
# Scan test files with B101 (assert_used) disabled
args: [-s, B101]
types: [python]
files: '^(tests/|.*_test\.py$)'

# Security vulnerability scanning with Safety (local hook)
# Local hook with safety package for reliability and control
# Runs on push to avoid blocking commits, scans all dependency files
- repo: local
hooks:
- id: safety-scan
name: Safety (dependency vulnerability scan)
entry: safety
language: python
additional_dependencies: [safety==3.6.0]
args: [scan, --full-report, --target, .]
pass_filenames: false
stages: [push]
# Optional: Add policy file for custom rules
# args: [scan, --full-report, --policy-file, .safety-policy.yml]
# env:
# - SAFETY_API_KEY # if using the commercial DB

# Documentation formatting with Docformatter (local hook)
# Local hook with docformatter package to avoid external repository compatibility issues
- repo: local
hooks:
- id: docformatter
name: Docformatter (docstring formatting)
entry: docformatter
language: python
additional_dependencies: [docformatter==1.7.3]
args: [--in-place, --wrap-summaries=88, --wrap-descriptions=88]
types: [python]

# String formatting with flynt
# Configuration consistent with Bandit hooks for maintainability
- repo: https://github.com/ikamensh/flynt
rev: "0.78"
hooks:
- id: flynt
args: [--line-length=88, .]
types: [python]
pass_filenames: false
always_run: true

# Custom SAMO-DL code quality enforcer
# TODO: Re-enable once configuration issues are resolved
# Issue: https://github.com/uelkerd/SAMO--DL/issues/106
# - repo: local
# hooks:
# - id: samo-code-quality-enforcer
# name: SAMO-DL Code Quality Enforcer
# entry: python scripts/maintenance/code_quality_enforcer.py
# language: python
# types: [python]
# pass_filenames: false
# always_run: true

# Auto-fix common code quality issues
# TODO: Re-enable once configuration issues are resolved
# Issue: https://github.com/uelkerd/SAMO--DL/issues/106
# - repo: local
# hooks:
# - id: samo-auto-fix-code-quality
# name: SAMO-DL Auto-Fix Code Quality
# entry: python scripts/maintenance/auto_fix_code_quality.py
# language: python
# types: [python]
# pass_filenames: false
# always_run: true

# Global configuration
default_language_version:
python: python3.8
args: [-c, pyproject.toml]
15 changes: 15 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[MASTER]
disable =
C0114, # missing-module-docstring
C0115, # missing-class-docstring
C0116, # missing-function-docstring
R0903, # too-few-public-methods
R0913, # too-many-arguments
W0613, # unused-argument (legitimate in interface implementations)
C0103, # invalid-name

[FORMAT]
max-line-length = 88

[BASIC]
good-names = i,j,k,ex,Run,_,id
Loading
Loading