Skip to content

Commit

Permalink
lint repository using pre-commit hook
Browse files Browse the repository at this point in the history
  • Loading branch information
jeriox committed Jul 30, 2024
1 parent 47666e6 commit 6fc0eda
Show file tree
Hide file tree
Showing 20 changed files with 577 additions and 470 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ name: build-container
on:
push:
branches:
- 'main'
- "main"
tags:
- 'v*'
- "v*"

jobs:
docker:
Expand Down
73 changes: 36 additions & 37 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ name: "CodeQL"

on:
push:
branches: [ main ]
branches: [main]
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]
branches: [main]
schedule:
- cron: '44 16 * * 0'
- cron: "44 16 * * 0"

jobs:
analyze:
Expand All @@ -21,41 +21,40 @@ jobs:
strategy:
fail-fast: false
matrix:
language: [ 'javascript', 'python' ]
language: ["javascript", "python"]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality


# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
194 changes: 99 additions & 95 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,55 @@ name: tests

on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]

jobs:
lint:
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: [ 3.11 ]
python-version: [3.11]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install poetry
run: curl -sSL https://install.python-poetry.org | python3 - --version 1.3.2
- uses: actions/cache@v1
with:
path: ~/.cache/pypoetry/virtualenvs
key: myHPI-${{ runner.os }}-poetry-py${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}
restore-keys: |
myHPI-${{ runner.os }}-poetry-py${{ matrix.python-version }}-
- name: Install dependencies
run: |
poetry install
- name: check format with black
run: |
poetry run black --version
poetry run black --check .
- name: check import order with isort
run: |
poetry run isort --version
poetry run isort -c .
- name: Lint with pylint
run: |
poetry run pylint --version
poetry run pylint --fail-under=9 myhpi
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install poetry
run: curl -sSL https://install.python-poetry.org | python3 - --version 1.3.2
- uses: actions/cache@v1
with:
path: ~/.cache/pypoetry/virtualenvs
key: myHPI-${{ runner.os }}-poetry-py${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}
restore-keys: |
myHPI-${{ runner.os }}-poetry-py${{ matrix.python-version }}-
- name: Install dependencies
run: |
poetry install
- name: check format with black
run: |
poetry run black --version
poetry run black --check .
- name: check import order with isort
run: |
poetry run isort --version
poetry run isort -c .
- name: Lint with pylint
run: |
poetry run pylint --version
poetry run pylint --fail-under=9 myhpi
- name: Lint templates with djhtml
run: |
poetry run djhtml --version
poetry run djhtml --check myhpi
test:
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: [ 3.11, 3.12 ]
database: [ sqlite, postgres ]
python-version: [3.11, 3.12]
database: [sqlite, postgres]
include:
- database: sqlite
database_url: "sqlite:///data/db.sqlite3"
Expand All @@ -56,70 +60,70 @@ jobs:
DJANGO_SETTINGS_MODULE: myhpi.tests.settings

steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
#- uses: Gr1N/setup-poetry@v4
#- uses: actions/cache@v1
# with:
# path: ~/.cache/pypoetry/virtualenvs
# key: myHPI-${{ runner.os }}-poetry-py${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}
# restore-keys: |
# myHPI-${{ runner.os }}-poetry-py${{ matrix.python-version }}-
- name: Setup python venv and poetry
run: |
#sudo apt-get install python-venv
python -m venv env
source env/bin/activate
curl -sSL https://install.python-poetry.org | python3 - --version 1.3.2
- name: Install dependencies
# always install all -E extras to use a single cache
run: |
sudo apt-get install gettext
source env/bin/activate
poetry run python -m pip install setuptools -U
poetry install -E mysql -E pgsql
python tools/install_bootstrap.py
- name: Prepare files for test run
continue-on-error: true
run: |
cp .env.example .env
source env/bin/activate
poetry run python manage.py compilemessages --settings myhpi.settings
poetry run python manage.py collectstatic --settings myhpi.settings
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
#- uses: Gr1N/setup-poetry@v4
#- uses: actions/cache@v1
# with:
# path: ~/.cache/pypoetry/virtualenvs
# key: myHPI-${{ runner.os }}-poetry-py${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }}
# restore-keys: |
# myHPI-${{ runner.os }}-poetry-py${{ matrix.python-version }}-
- name: Setup python venv and poetry
run: |
#sudo apt-get install python-venv
python -m venv env
source env/bin/activate
curl -sSL https://install.python-poetry.org | python3 - --version 1.3.2
- name: Install dependencies
# always install all -E extras to use a single cache
run: |
sudo apt-get install gettext
source env/bin/activate
poetry run python -m pip install setuptools -U
poetry install -E mysql -E pgsql
python tools/install_bootstrap.py
- name: Prepare files for test run
continue-on-error: true
run: |
cp .env.example .env
source env/bin/activate
poetry run python manage.py compilemessages --settings myhpi.settings
poetry run python manage.py collectstatic --settings myhpi.settings
- name: Setup postgres
uses: harmon758/postgresql-action@v1
with:
postgresql version: '11' # See https://hub.docker.com/_/postgres for available versions
postgresql db: myHPI
postgresql user: user
postgresql password: pass
if: matrix.database == 'postgres'
- name: Setup postgres
uses: harmon758/postgresql-action@v1
with:
postgresql version: "11" # See https://hub.docker.com/_/postgres for available versions
postgresql db: myHPI
postgresql user: user
postgresql password: pass
if: matrix.database == 'postgres'

- name: Setup postgres dependency
run: |
source env/bin/activate
poetry run python -m pip install psycopg2
if: matrix.database == 'postgres'
- name: Setup postgres dependency
run: |
source env/bin/activate
poetry run python -m pip install psycopg2
if: matrix.database == 'postgres'

#- name: Migrate db
# run: |
# source env/bin/activate
# # python manage.py migrate --run-syncdb
#- name: Migrate db
# run: |
# source env/bin/activate
# # python manage.py migrate --run-syncdb

- name: Test apps
env:
DATABASE_URL: ${{ matrix.database_url }}
run: |
source env/bin/activate
poetry run coverage run --source=myhpi manage.py test myhpi.tests
- name: Coveralls
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
source env/bin/activate
pip install coveralls
coveralls --service=github
if: matrix.python-version == '3.9' && matrix.database == 'sqlite'
- name: Test apps
env:
DATABASE_URL: ${{ matrix.database_url }}
run: |
source env/bin/activate
poetry run coverage run --source=myhpi manage.py test myhpi.tests
- name: Coveralls
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
source env/bin/activate
pip install coveralls
coveralls --service=github
if: matrix.python-version == '3.9' && matrix.database == 'sqlite'
18 changes: 9 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ repos:
hooks:
- id: black
- repo: https://github.com/rtts/djhtml
rev: '3.0.6'
rev: "3.0.6"
hooks:
- id: djhtml
- id: djcss
- id: djjs
- repo: local
hooks:
- id: prettier-eslint
name: Prettier and ESLint
entry: prettier-eslint --write --list-different
language: node
types_or: [javascript, css, markdown, yaml]
additional_dependencies: ["[email protected]"]
# - repo: local
# hooks:
# - id: prettier-eslint
# name: Prettier and ESLint
# entry: prettier-eslint --write --list-different
# language: node
# types_or: [javascript, css, markdown, yaml]
# additional_dependencies: ["[email protected]"]
1 change: 0 additions & 1 deletion myhpi/core/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from collections import defaultdict
from datetime import date

from django import forms
Expand Down
Loading

0 comments on commit 6fc0eda

Please sign in to comment.