Skip to content

Commit

Permalink
Add CI (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rayman authored Aug 7, 2024
1 parent 436a6b8 commit e762388
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 34 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright 2023 Nobleo Technology B.V.
#
# SPDX-License-Identifier: Apache-2.0

# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python application

on: [push]

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
fail-fast: false

steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
cache: pip
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
pip install -r requirements.txt
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
export FILES="*.py */*.py */*/*.py"
flake8 $FILES --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 $FILES --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest --ignore=snakes/bots/
- name: Test imports
run: |
./tournament.py -h
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "racer/bots/example"]
path = racer/bots/example
url = git@github.com:nobleans-playground/coding-challenge-racer-bot-template.git
[submodule "racer/bots/rayman"]
path = racer/bots/rayman
url = git@github.com:Rayman/coding-challenge-racer-bot.git
5 changes: 2 additions & 3 deletions racer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ def __init__(self, game_state: GameState):

def draw(self, clock):
# scale map to full screen
zoom = self.window.get_width() / self.map.get_width()
zoom = self.window.get_height() / self.map.get_height() if self.window.get_height() / self.map.get_height() < zoom else zoom
zoom = min(self.window.get_width() / self.map.get_width(), self.window.get_height() / self.map.get_height())
map_scaled = pygame.transform.scale(self.map, Vector2(self.map.get_size()) * zoom)

lines = [l * zoom for l in self.game_state.track.lines]
lines = [line * zoom for line in self.game_state.track.lines]
pygame.draw.aalines(map_scaled, (255, 0, 0), True, lines, 10)

# Draw the cars
Expand Down
2 changes: 0 additions & 2 deletions racer/bots/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from .example import SimpleBot
from .keyboard_bot import KeyboardBot
from .rayman import Dustrider

all_bots = [
KeyboardBot,
SimpleBot,
Dustrider,
]
2 changes: 1 addition & 1 deletion racer/bots/example
Submodule example updated 2 files
+2 −0 __init__.py
+1 −1 test_bot.py
1 change: 0 additions & 1 deletion racer/bots/rayman
Submodule rayman deleted from d820c7
10 changes: 6 additions & 4 deletions racer/test_bot.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import pytest
import racer.track1 as track1

from .bot import Bot
from .track import Track


def test_complete_bot():
Expand All @@ -16,7 +18,7 @@ def contributor(self):
def compute_commands(self):
return 0.5, 0.5

bot = SimpleBot()
SimpleBot(track=Track(track1))


def test_missing_compute_commands():
Expand All @@ -30,7 +32,7 @@ def contributor(self):
return "Nobleo"

with pytest.raises(TypeError):
Incomplete()
Incomplete(track=Track(track1))


def test_missing_name():
Expand All @@ -43,7 +45,7 @@ def compute_commands(self):
return 0.5, 0.5

with pytest.raises(TypeError):
Incomplete()
Incomplete(track=Track(track1))


def test_missing_contributor():
Expand All @@ -56,4 +58,4 @@ def compute_commands(self):
return 0.5, 0.5

with pytest.raises(TypeError):
Incomplete()
Incomplete(track=Track(track1))
20 changes: 2 additions & 18 deletions racer/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def __init__(self, module):
self.name: str = module.name
self.background: Surface = module.background
self.track_width: float = module.track_width
self.lines = [Vector2(l) for l in module.lines]
self.lines = [Vector2(line) for line in module.lines]

def __deepcopy__(self, memo):
return Track(Namespace(name=deepcopy(self.name),
Expand All @@ -19,20 +19,4 @@ def __deepcopy__(self, memo):
lines=deepcopy(self.lines)))

def __repr__(self):
return f"Track({self.name!r}, {self.background!r})"

# class Track:
# def __init__(self, module):
# self.name = module.name
# self.background = module.background
# self.resolution = module.resolution
# self.width = module.width
# self.lines = [Vector2(l) for l in module.lines]
#
# @property
# def size(self):
# """Track size (x, y) in meters"""
# return Vector2(self.background.get_size()) * self.resolution
#
# def __repr__(self):
# return f"Track({self.name!r}, {self.resolution!r}, {self.background!r})"
return f"Track({self.name!r}, {self.background!r}, {self.track_width!r})"
Binary file modified requirements.txt
Binary file not shown.
4 changes: 2 additions & 2 deletions tournament.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def main():
game_state = single_game()

for bot, car_info in game_state.bots.items():
print(
f'{bot.name} reached round {car_info.round} waypoint {car_info.next_waypoint} with {car_info.cpu:.2f} seconds of CPU time')
print(f'{bot.name} reached round {car_info.round} waypoint {car_info.next_waypoint} with {car_info.cpu:.2f} '
f'seconds of CPU time')


def single_game():
Expand Down

0 comments on commit e762388

Please sign in to comment.