Skip to content

Commit

Permalink
Merge pull request #6 from smessie/add-linter
Browse files Browse the repository at this point in the history
Add a linter and GitHub checks
  • Loading branch information
smessie authored Nov 11, 2020
2 parents 031b212 + 361cbbf commit b6ef5c7
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 18 deletions.
14 changes: 14 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[flake8]
ignore = D203
exclude = .
# No need to traverse our git directory
.git,
# There's no value in checking cache directories
__pycache__,
# This contains our virtual environments that we don't want to check
project,
venv,
# This also contains libraries that we don't want to check
venvanaconda,
max-complexity = 10
max-line-length = 120
31 changes: 31 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see:
# https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python application

on: [push, pull_request]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82,E501 --show-source --statistics
# exit-zero treats all errors as warnings. Max line length of 120 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=120 --statistics
- name: python-isort
uses: isort/[email protected]
4 changes: 4 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[settings]
profile=hug
skip=venvanaconda,project,venv
line_length=120
6 changes: 3 additions & 3 deletions agents/basic_agent.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from __future__ import annotations

from typing import List, Optional, TYPE_CHECKING
from typing import TYPE_CHECKING, List, Optional

from game.agent import Agent
from util.cards import get_played_value
from game.table import Table
from game.player import Player
from game.table import Table
from util.cards import get_played_value

if TYPE_CHECKING:
from game.card import Card
Expand Down
4 changes: 2 additions & 2 deletions agents/random_agent.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from __future__ import annotations

import random
from typing import List, TYPE_CHECKING
from typing import TYPE_CHECKING, List

from game.agent import Agent
from game.table import Table
from game.player import Player
from game.table import Table

if TYPE_CHECKING:
from game.card import Card
Expand Down
2 changes: 1 addition & 1 deletion agents/simple_agent.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from game.agent import Agent
from game.table import Table
from game.player import Player
from game.table import Table


class SimpleAgent(Agent):
Expand Down
2 changes: 1 addition & 1 deletion game/agent.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import List, TYPE_CHECKING
from typing import TYPE_CHECKING, List

from game.player import Player

Expand Down
8 changes: 4 additions & 4 deletions game/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ def __ne__(self, other):
return not self == other

def __lt__(self, other):
return self.value < other.value or (
self.value == other.value and self.suit.get_color() < other.suit.get_color())
return self.value < other.value or \
(self.value == other.value and self.suit.get_color() < other.suit.get_color())

def __le__(self, other):
return self < other or self == other

def __gt__(self, other):
return self.value > other.value or (
self.value == other.value and self.suit.get_color() > other.suit.get_color())
return self.value > other.value or \
(self.value == other.value and self.suit.get_color() > other.suit.get_color())

def __ge__(self, other):
return self > other or self == other
Expand Down
2 changes: 1 addition & 1 deletion game/player.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from itertools import combinations
from typing import List, TYPE_CHECKING
from typing import TYPE_CHECKING, List

if TYPE_CHECKING:
from game.card import Card
Expand Down
2 changes: 1 addition & 1 deletion game/president.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import List, Iterator, Tuple, Optional, Dict, TYPE_CHECKING
from typing import TYPE_CHECKING, Dict, Iterator, List, Optional, Tuple

from tqdm import tqdm

Expand Down
2 changes: 1 addition & 1 deletion game/table.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from random import shuffle
from typing import List, Tuple, Optional, TYPE_CHECKING
from typing import TYPE_CHECKING, List, Optional, Tuple

from game.deck import Deck

Expand Down
3 changes: 1 addition & 2 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/usr/bin/env python3

from game.president import President
from agents.basic_agent import BasicAgent
from agents.simple_agent import SimpleAgent
from agents.random_agent import RandomAgent
from game.president import President

if __name__ == "__main__":
game = President([
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
tqdm==4.51.0
flake8==3.8.4
isort==5.6.4
2 changes: 1 addition & 1 deletion util/cards.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Optional, List
from typing import TYPE_CHECKING, List, Optional

if TYPE_CHECKING:
from game.card import Card
Expand Down
2 changes: 1 addition & 1 deletion util/iterator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import List, Any
from typing import Any, List


class CustomIterator:
Expand Down

0 comments on commit b6ef5c7

Please sign in to comment.