diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..0536994 --- /dev/null +++ b/.flake8 @@ -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 \ No newline at end of file diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml new file mode 100644 index 0000000..c7af910 --- /dev/null +++ b/.github/workflows/python-app.yml @@ -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/isort-action@v0.1.0 diff --git a/.isort.cfg b/.isort.cfg new file mode 100644 index 0000000..ba41e71 --- /dev/null +++ b/.isort.cfg @@ -0,0 +1,4 @@ +[settings] +profile=hug +skip=venvanaconda,project,venv +line_length=120 \ No newline at end of file diff --git a/agents/basic_agent.py b/agents/basic_agent.py index 18617d7..a5af158 100644 --- a/agents/basic_agent.py +++ b/agents/basic_agent.py @@ -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 diff --git a/agents/random_agent.py b/agents/random_agent.py index 4c804c1..889131a 100644 --- a/agents/random_agent.py +++ b/agents/random_agent.py @@ -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 diff --git a/agents/simple_agent.py b/agents/simple_agent.py index 68bc364..d237fb6 100644 --- a/agents/simple_agent.py +++ b/agents/simple_agent.py @@ -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): diff --git a/game/agent.py b/game/agent.py index de510c5..fa6cfc1 100644 --- a/game/agent.py +++ b/game/agent.py @@ -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 diff --git a/game/card.py b/game/card.py index 85f8ca4..e5f0b7f 100644 --- a/game/card.py +++ b/game/card.py @@ -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 diff --git a/game/player.py b/game/player.py index b1df02d..07879bb 100644 --- a/game/player.py +++ b/game/player.py @@ -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 diff --git a/game/president.py b/game/president.py index c10f74b..3092cd2 100644 --- a/game/president.py +++ b/game/president.py @@ -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 diff --git a/game/table.py b/game/table.py index 8e7cb34..8fc1ae3 100644 --- a/game/table.py +++ b/game/table.py @@ -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 diff --git a/main.py b/main.py index 95a9aa3..02775cc 100755 --- a/main.py +++ b/main.py @@ -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([ diff --git a/requirements.txt b/requirements.txt index 29a4d6a..720f0c5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,3 @@ tqdm==4.51.0 +flake8==3.8.4 +isort==5.6.4 \ No newline at end of file diff --git a/util/cards.py b/util/cards.py index d7b34b8..3f96a79 100644 --- a/util/cards.py +++ b/util/cards.py @@ -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 diff --git a/util/iterator.py b/util/iterator.py index 935da30..69204fe 100644 --- a/util/iterator.py +++ b/util/iterator.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import List, Any +from typing import Any, List class CustomIterator: