From 16a419f55868e39f7a94b16462a3bad4f43a2b0f Mon Sep 17 00:00:00 2001 From: c0de Date: Fri, 11 Nov 2022 20:06:14 -0600 Subject: [PATCH] Fix circular import issue --- GhostBallBot/game/base.py | 40 +++++++++++++++++++++++++++++++++++ GhostBallBot/game/end_game.py | 2 +- GhostBallBot/game/guess.py | 2 +- GhostBallBot/game/help.py | 2 +- GhostBallBot/game/manager.py | 36 ------------------------------- GhostBallBot/game/new_game.py | 2 +- GhostBallBot/game/points.py | 2 +- 7 files changed, 45 insertions(+), 41 deletions(-) create mode 100644 GhostBallBot/game/base.py diff --git a/GhostBallBot/game/base.py b/GhostBallBot/game/base.py new file mode 100644 index 0000000..0c49028 --- /dev/null +++ b/GhostBallBot/game/base.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 +# Copyright 2022 - c0de +# Licensed under the MIT License (https://opensource.org/licenses/MIT) + +# pylint: disable=missing-module-docstring + +from database.models import database, GameModel as Game + +class BaseGameManager: + """Base Game Manager for each Game Manager class to inherit""" + + def __init__(self): + # Only one game should run at at time + self.is_running = False + + self.commands = [] + + self.game = Game + + # Discord message + self.message = None + + # Discord client instance + self.discord = None + + def __enter__(self): + """ + Allows use of `with Game() as game` for try/except statements + (https://peps.python.org/pep-0343/) + """ + + database.connect() + return self + + def __exit__(self, exception_type, exception_value, exception_traceback): + """ + Automagically close the database + when this class has ended execution + """ + database.close() \ No newline at end of file diff --git a/GhostBallBot/game/end_game.py b/GhostBallBot/game/end_game.py index 8212dfc..e47aeb3 100644 --- a/GhostBallBot/game/end_game.py +++ b/GhostBallBot/game/end_game.py @@ -7,7 +7,7 @@ import datetime from database.models import GameModel as Game, GuessModel as Guess -from game.manager import BaseGameManager +from game.base import BaseGameManager from game.process_guess import ProcessGuess diff --git a/GhostBallBot/game/guess.py b/GhostBallBot/game/guess.py index 8680f48..1446e7d 100644 --- a/GhostBallBot/game/guess.py +++ b/GhostBallBot/game/guess.py @@ -7,7 +7,7 @@ import uuid from database.models import PlayerModel as Player, GuessModel as Guess -from game.manager import BaseGameManager +from game.base import BaseGameManager class GuessManager(BaseGameManager): diff --git a/GhostBallBot/game/help.py b/GhostBallBot/game/help.py index d1fcfef..c3ad8ce 100644 --- a/GhostBallBot/game/help.py +++ b/GhostBallBot/game/help.py @@ -4,7 +4,7 @@ # pylint: disable=missing-module-docstring -from game.manager import BaseGameManager +from game.base import BaseGameManager class HelpManager(BaseGameManager): diff --git a/GhostBallBot/game/manager.py b/GhostBallBot/game/manager.py index 71a3335..751d7c4 100644 --- a/GhostBallBot/game/manager.py +++ b/GhostBallBot/game/manager.py @@ -10,8 +10,6 @@ Discord channel """ -from database.models import database, GameModel as Game - from game.new_game import NewGameManager from game.end_game import EndGameManager from game.guess import GuessManager @@ -19,40 +17,6 @@ from game.points import PointsManager from game.help import HelpManager -class BaseGameManager: - """Base Game Manager for each Game Manager class to inherit""" - - def __init__(self): - # Only one game should run at at time - self.is_running = False - - self.commands = [] - - self.game = Game - - # Discord message - self.message = None - - # Discord client instance - self.discord = None - - def __enter__(self): - """ - Allows use of `with Game() as game` for try/except statements - (https://peps.python.org/pep-0343/) - """ - - database.connect() - return self - - def __exit__(self, exception_type, exception_value, exception_traceback): - """ - Automagically close the database - when this class has ended execution - """ - database.close() - - class GameManager( NewGameManager, EndGameManager, GuessManager, PointsManager, HelpManager ): diff --git a/GhostBallBot/game/new_game.py b/GhostBallBot/game/new_game.py index e2f1f56..9b1108b 100644 --- a/GhostBallBot/game/new_game.py +++ b/GhostBallBot/game/new_game.py @@ -7,7 +7,7 @@ import uuid from database.models import GameModel as Game -from game.manager import BaseGameManager +from game.base import BaseGameManager class NewGameManager(BaseGameManager): diff --git a/GhostBallBot/game/points.py b/GhostBallBot/game/points.py index a5aff56..e80f03f 100644 --- a/GhostBallBot/game/points.py +++ b/GhostBallBot/game/points.py @@ -5,7 +5,7 @@ # pylint: disable=not-an-iterable,missing-module-docstring from database.models import PlayerModel as Player -from game.manager import BaseGameManager +from game.base import BaseGameManager class PointsManager(BaseGameManager):