Skip to content

Commit

Permalink
chore: add python_test.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
vil02 committed Nov 23, 2024
1 parent ad7e503 commit 46e2b29
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 0 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/python_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
name: python_test

'on':
workflow_dispatch:
push:
branches:
- main
pull_request:

jobs:
python_test:
runs-on: ${{matrix.os}}
timeout-minutes: 90
strategy:
fail-fast: false
matrix:
os:
- ubuntu-20.04
python-version: ['3.10', 3.11]

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python ${{matrix.python-version}}
uses: actions/setup-python@v5
with:
python-version: ${{matrix.python-version}}

- name: Install dependencies
run: |
curl -sSL https://install.python-poetry.org | python3 -
poetry install --with dev
- name: Lint with ruff
run: |
poetry run ruff check
- name: Run liter
run: |
./check_all_python_scripts.sh
- name: Test with pytest
run: |
poetry run pytest -n 2
...
5 changes: 5 additions & 0 deletions check_all_python_scripts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

set -euo pipefail

find . -name "*.py" -exec ./check_python_file.sh {} +
30 changes: 30 additions & 0 deletions check_python_file.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

set -euo pipefail

declare -i exit_code=0

for cur_file in "$@"
do
printf "Checking \"%s\"\n" "${cur_file}"
printf "Checking with pylint:\n"
if ! poetry run pylint "${cur_file}" ; then
exit_code=1
fi

printf "Checking with flake8:\n"
if ! poetry run flake8 "${cur_file}" --count --max-line-length=88 --show-source --ignore=E203,W503 ; then
exit_code=1
fi

printf "Checking with mypy:\n"
if ! poetry run mypy "${cur_file}"; then
exit_code=1
fi
done

if [[ ${exit_code} -eq 0 ]] ; then
printf "\nNo errors found!\n"
fi

exit "${exit_code}"
29 changes: 29 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[tool.poetry]
name = "adv-2024"
version = "1.0.0"
description = "solutions of Advent of Code 2024"
authors = ["piotr.idzik <vil02_adv@10g.pl>"]
readme = "README.md"
packages = [{include = "solutions"}]

[tool.poetry.dependencies]
python = ">=3.10,<4.0.0"

[tool.poetry.group.dev]
optional = true

[tool.poetry.group.dev.dependencies]
pytest = "8.3.1"
pytest-xdist = "3.5.0"
pylint = "3.2.0"
flake8 = "7.1.1"
flake8-bugbear = "24.10.31"
flake8-pytest-style = "2.0.0"
ruff = "0.7.4"
coverage = "7.5.0"
black = "24.1"
mypy = "1.13.0"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Empty file added tests/__init__.py
Empty file.

0 comments on commit 46e2b29

Please sign in to comment.