Skip to content

Commit

Permalink
chore: add pull_request.yaml workflow (#8)
Browse files Browse the repository at this point in the history
* chore: add pull_request.yaml workflow

* chore: run black

* chore: fix all pylint issues
  • Loading branch information
koen1711 authored May 25, 2024
1 parent 5ceba65 commit 1b1ddeb
Show file tree
Hide file tree
Showing 18 changed files with 1,052 additions and 644 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Run tests

on:
pull_request:
branches:
- main

jobs:
run_tests:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10"]
steps:
- uses: actions/checkout@v4

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

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint==3.0.2 black==23.11.0
- name: Checking formatting with black
run: |
black --check ./play
- name: Analysing the code with pylint
run: |
pylint $(git ls-files 'play/*.py')
2 changes: 2 additions & 0 deletions play/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
"""The library to make pygame easier to use."""

from .play import *
from .objects import *
4 changes: 2 additions & 2 deletions play/all_sprites.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""This module contains the list of all sprites and walls in the game."""

all_sprites = []
_walls = []


29 changes: 18 additions & 11 deletions play/async_helpers.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
"""This module contains code to help with async functions."""

import asyncio as _asyncio
import warnings as _warnings
from .exceptions import Oops


def _raise_on_await_warning(func):
"""
If someone doesn't put 'await' before functions that require 'await'
like play.timer() or play.animate(), raise an exception.
"""

async def f(*args, **kwargs):
with _warnings.catch_warnings(record=True) as w:
async def raise_on_warning(*args, **kwargs):
with _warnings.catch_warnings(record=True) as warnings:
await func(*args, **kwargs)
for warning in w:
str_message = warning.message.args[0] # e.g. "coroutine 'timer' was never awaited"
if 'was never awaited' in str_message:
for warning in warnings:
str_message = warning.message.args[
0
] # e.g. "coroutine 'timer' was never awaited"
if "was never awaited" in str_message:
unawaited_function_name = str_message.split("'")[1]

raise Oops(
f"""Looks like you forgot to put "await" before play.{unawaited_function_name} on line {warning.lineno} of file {warning.filename}.
To fix this, just add the word 'await' before play.{unawaited_function_name} on line {warning.lineno} of file {warning.filename} in the function {func.__name__}.""")
else:
print(warning.message)
f"""Looks like you forgot to put "await" before play.{unawaited_function_name} on line {warning.lineno} of file {warning.filename}.""" + # pylint: disable=line-too-long
"""To fix this, just add the word 'await' before play.{unawaited_function_name} on line {warning.lineno} of file {warning.filename} in the function {func.__name__}.""" # pylint: disable=line-too-long
# pylint: enable=line-too-long
)
print(warning.message)

return f
return raise_on_warning


def _make_async(func):
Expand All @@ -37,4 +44,4 @@ def _make_async(func):
async def async_func(*args, **kwargs):
return func(*args, **kwargs)

return async_func
return async_func
7 changes: 6 additions & 1 deletion play/clamp.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
""" Module for clamping values.
"""


def _clamp(num, min_, max_):
if num < min_:
return min_
elif num > max_:
if num > max_:
return max_
return num
Loading

0 comments on commit 1b1ddeb

Please sign in to comment.