Skip to content

Commit faa9ee3

Browse files
committed
use ruff as our one only linter, fix bandit
1 parent 6261c37 commit faa9ee3

7 files changed

Lines changed: 153 additions & 283 deletions

File tree

.bandit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[bandit]
2-
exclude: ./src/tests/*
2+
exclude=src/tests/*,.venv,__pycache__,*.pyc,migrations/*

.flake8

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

.github/workflows/ci.yml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,11 @@ jobs:
5151
if: steps.cached-venv.outputs.cache-hit != 'true'
5252
run: poetry install --only dev --no-interaction
5353

54-
- name: Run Black formatter check
55-
run: poetry run black --check .
54+
- name: Run Ruff linter
55+
run: poetry run ruff check .
5656

57-
- name: Run isort import check
58-
run: poetry run isort --check-only .
59-
60-
- name: Run Flake8 linter
61-
run: poetry run flake8 .
57+
- name: Run Ruff formatter check
58+
run: poetry run ruff format --check .
6259

6360
test:
6461
name: Test
@@ -162,10 +159,10 @@ jobs:
162159
run: poetry install --no-interaction
163160

164161
- name: Run Bandit security linter
165-
run: poetry run bandit -r . --skip B101 -f json -o bandit-report.json || true
162+
run: poetry run bandit -r src --skip B101 -f json -o bandit-report.json || true
166163

167164
- name: Display Bandit results
168-
run: poetry run bandit -r . --skip B101 -f txt || true
165+
run: poetry run bandit -r src --skip B101 -f txt || true
169166

170167
# Final status check for branch protection
171168
ci-success:

Makefile

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
.PHONY: help install lint lint-fix format test test-unit test-integration test-cov security ci migrate createsuperuser runserver shell clean
2+
3+
# Default target
4+
help:
5+
@echo "Available commands:"
6+
@echo " make install - Install dependencies with poetry"
7+
@echo " make lint - Run ruff linter and formatter check"
8+
@echo " make lint-fix - Auto-fix linting and formatting issues"
9+
@echo " make format - Format code with ruff"
10+
@echo " make test - Run all tests"
11+
@echo " make test-unit - Run unit tests only"
12+
@echo " make test-integration - Run integration tests only"
13+
@echo " make test-cov - Run tests with coverage report"
14+
@echo " make security - Run bandit security scanner"
15+
@echo " make ci - Run all CI checks (lint, test-cov, security)"
16+
@echo " make migrate - Run Django migrations"
17+
@echo " make createsuperuser - Create Django superuser"
18+
@echo " make runserver - Run Django development server"
19+
@echo " make shell - Open Django shell"
20+
@echo " make clean - Remove Python cache files and test artifacts"
21+
22+
# Install dependencies
23+
install:
24+
poetry install
25+
26+
# Linting and formatting
27+
lint:
28+
poetry run ruff check .
29+
poetry run ruff format --check .
30+
31+
lint-fix:
32+
poetry run ruff check --fix .
33+
poetry run ruff format .
34+
35+
format:
36+
poetry run ruff format .
37+
38+
# Testing
39+
test:
40+
cd src && poetry run pytest
41+
42+
test-unit:
43+
cd src && poetry run pytest tests/unit/
44+
45+
test-integration:
46+
cd src && poetry run pytest tests/integration/
47+
48+
test-cov:
49+
cd src && DJANGO_ENV=testing ENVIRONMENT=TEST SECRET_KEY=test-secret-key poetry run pytest --cov=. --cov-report=xml --cov-report=term-missing -v
50+
51+
# Security
52+
security:
53+
poetry run bandit -r src --skip B101 -f txt
54+
55+
# CI - runs all checks that CI will run
56+
ci: lint test-cov security
57+
@echo ""
58+
@echo "✓ All CI checks passed!"
59+
60+
# Django commands
61+
migrate:
62+
poetry run python src/manage.py migrate
63+
64+
createsuperuser:
65+
poetry run python src/manage.py createsuperuser
66+
67+
runserver:
68+
poetry run python src/manage.py runserver
69+
70+
shell:
71+
poetry run python src/manage.py shell
72+
73+
# Cleanup
74+
clean:
75+
find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
76+
find . -type f -name "*.pyc" -delete
77+
find . -type f -name "*.pyo" -delete
78+
find . -type d -name ".pytest_cache" -exec rm -rf {} + 2>/dev/null || true
79+
find . -type f -name ".coverage" -delete
80+
find . -type f -name "coverage.xml" -delete
81+
rm -rf .ruff_cache htmlcov
82+
@echo "✓ Cleaned up Python cache files and test artifacts"

README.md

Lines changed: 63 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
55
[![Twitter Follow](https://img.shields.io/twitter/follow/operation_code.svg?style=social&label=Follow&style=social)](https://twitter.com/operation_code)
6-
[![Code-style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)
6+
[![Code style: ruff](https://img.shields.io/badge/code%20style-ruff-000000.svg)](https://github.com/astral-sh/ruff)
77

88

99
[![CircleCI](https://circleci.com/gh/OperationCode/back-end.svg?style=svg)](https://circleci.com/gh/OperationCode/back-end)
@@ -36,33 +36,77 @@ Recommended versions of tools used within the repo:
3636

3737
```bash
3838
# Install dependencies (ensure poetry is already installed)
39-
# if you are encountering an error with psycopg2 during poetry installation, ensure postgreqsql is installed (macOS: brew install postgresql)
40-
poetry install
39+
# If you are encountering an error with psycopg2 during poetry installation,
40+
# ensure PostgreSQL is installed (macOS: brew install postgresql)
41+
make install
4142

4243
# Create database
4344
# By default this creates a local sqlite database and adds tables for each of the defined models
44-
# see example.env for database configurations
45-
poetry run python src/manage.py migrate
45+
# See example.env for database configurations
46+
make migrate
4647

4748
# Create a superuser to add to the new database
48-
poetry run python src/manage.py createsuperuser
49+
make createsuperuser
4950

50-
# Run local development
51-
poetry run python src/manage.py runserver
51+
# Run local development server
52+
make runserver
53+
```
54+
55+
## Development Workflow
56+
57+
### Running Tests
58+
```bash
59+
# Run all tests
60+
make test
61+
62+
# Run only unit tests
63+
make test-unit
5264

53-
# Run testing suite
54-
poetry run pytest
65+
# Run only integration tests
66+
make test-integration
5567

56-
# Run formatting and linting
57-
poetry run black .
58-
# the next line shouldn't output anything to the terminal if it passes
59-
poetry run flake8
60-
poetry run isort .
68+
# Run tests with coverage report
69+
make test-cov
6170
```
6271

63-
## Running [Bandit](https://github.com/PyCQA/bandit)
64-
Bandit is a tool designed to find common security issues in Python code.
72+
### Linting and Formatting
73+
We use [Ruff](https://github.com/astral-sh/ruff) for both linting and code formatting.
6574

66-
From within the `back-end/` directory you can run the following Bandit command:
75+
```bash
76+
# Check linting and formatting (doesn't modify files)
77+
make lint
6778

68-
- `bandit -r .` runs all bandit tests recursively with only filters defined in the `.bandit` file.
79+
# Auto-fix linting issues and format code
80+
make lint-fix
81+
82+
# Format code only
83+
make format
84+
```
85+
86+
### Security Scanning
87+
[Bandit](https://github.com/PyCQA/bandit) is a tool designed to find common security issues in Python code.
88+
89+
```bash
90+
# Run security scanner
91+
make security
92+
```
93+
94+
### CI Checks
95+
Run all the same checks that CI will run:
96+
97+
```bash
98+
# Run all CI checks (linting, tests with coverage, security)
99+
make ci
100+
```
101+
102+
### Other Commands
103+
```bash
104+
# Open Django shell
105+
make shell
106+
107+
# Clean up Python cache files and test artifacts
108+
make clean
109+
110+
# See all available commands
111+
make help
112+
```

0 commit comments

Comments
 (0)