Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Code formatter #18

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ application_import_names = apps, authentication, common
exclude = **/__init__.py, **/migrations, .venv

inline-quotes = double
#import-order-style = google
max-line-length = 120

# B901 blind except: statement (duplicate of E722)
# E501 line too long
Expand Down
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ jobs:
- stage: Test
name: Run linter (flake8)
install: pip install -r requirements/testing.txt
script: flake8
script:
- flake8 --version
- flake8
# SonarCloud does not fail the build if the SonarCloud quality gate fails,
# but SonarCloud has a GitHub PR status check which can be made required.
- stage: test
Expand Down
14 changes: 14 additions & 0 deletions manage/format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

# Runs code formatter and import sorter.

SRC_DIRS="src"
CMD="manage/cmd.sh"

set -eu # Exit on error and undefined var is error

# Sort imports
#$CMD isort -rc $SRC_DIRS

# Format code
$CMD black $SRC_DIRS
2 changes: 1 addition & 1 deletion manage/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ $DC up --no-start
echo
echo "Collecting static ..."
# Ignore admin app, use theme instead
$MANAGE collectstatic -i admin --noinput --clear
$MANAGE collectstatic -i admin --noinput --clear | egrep -v "^Deleting" || true

echo
manage/update.sh
5 changes: 5 additions & 0 deletions manage/shell.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

# Runs BASH shell inside the container.

manage/cmd.sh bash -i
8 changes: 7 additions & 1 deletion manage/venv/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ export CONFIG_FILE
set -e # No -u because of source below

# Activate venv and deactivate on exit
source "$(dirname "$BASH_SOURCE[0]")/activate.sh"
source manage/venv/activate.sh
trap deactivate EXIT

set -eu

# Check if config file exists
if [[ ! -e $CONFIG_FILE ]]; then
echo "App config not found: $SETTINGS_FILE" 1>&2
exit -1
fi

$MANAGE runserver localhost:8000
4 changes: 2 additions & 2 deletions manage/venv/setup-basic.sh → manage/venv/setup-editor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
set -e # No -u because of source below

# Activate venv and deactivate on exit
source "$(dirname "$BASH_SOURCE[0]")/activate.sh"
source manage/venv/activate.sh
trap deactivate EXIT

set -eu

echo
echo "Installing requirements ..."
pip install --quiet -r requirements/development.txt
pip install -r requirements/development.txt
7 changes: 3 additions & 4 deletions manage/venv/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export CONFIG_FILE
set -e # No -u because of source below

# Activate venv and deactivate on exit
source "$(dirname "$BASH_SOURCE[0]")/activate.sh"
source manage/venv/activate.sh
trap deactivate EXIT

set -eu
Expand Down Expand Up @@ -40,8 +40,7 @@ pip install -r requirements/development.txt
echo
echo "Collecting static files ..."
# Ignore admin app, use theme instead
$MANAGE collectstatic -i admin --noinput --clear
$MANAGE collectstatic -i admin --noinput --clear | egrep -v "^Deleting" || true

echo
echo "Running migration ..."
$MANAGE migrate --fake-initial
manage/venv/update.sh
29 changes: 29 additions & 0 deletions manage/venv/update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

LOCAL_DIR=".local/venv"
CONFIG_FILE="$LOCAL_DIR/config.env"
LOG_DIR="$LOCAL_DIR/log"
MANAGE="python src/manage.py"

export CONFIG_FILE

set -e # No -u because of source below

# Activate venv and deactivate on exit
source manage/venv/activate.sh
trap deactivate EXIT

set -eu

# Check if config file exists
if [[ ! -e $CONFIG_FILE ]]; then
echo "App config not found: $SETTINGS_FILE" 1>&2
exit -1
fi

# Add other dirs and files
[[ ! -e $LOG_DIR ]] && mkdir -p $LOG_DIR

echo
echo "Running migration ..."
$MANAGE migrate --fake-initial
36 changes: 18 additions & 18 deletions requirements/testing.in
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
-r base.in

# flake8 and extensions
# flake8 and friends
flake8
flake8-bandit
flake8-blind-except
flake8-builtins
cohesion
flake8-commas
flake8-comprehensions
flake8-debugger
flake8-import-order
flake8-logging-format
flake8-mutable
flake8-pep3101
pep8-naming
flake8-print
flake8-quotes
flake8-string-format
flake8-tidy-imports
flake8-todo
flake8-black # Black check
flake8-bandit # Security checks
flake8-blind-except # Prevent blind "excepts"
flake8-builtins # Prevent builtins as variables
cohesion # Class cohesion checks
flake8-comprehensions # List/set/dict comprehension checks
flake8-debugger # Prevent debug imports/traces/etc.
flake8-import-order # Import order checks
flake8-tidy-imports # Import checks
flake8-print # Prevent print statements
flake8-logging-format # Logging format checks
flake8-mutable # Prevent mutable default arguments
flake8-pep3101 # Prevent old string formatting
flake8-string-format # New string formatting checks
pep8-naming # PEP-8 naming convention checks
flake8-quotes # String quoting checks
flake8-todo # Prevent TODO notes