From 05e1822c3de24f8843bcf63e32bec394e53190db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Tue, 4 Jul 2023 18:52:59 +0200 Subject: [PATCH] refactor files into proper submodules (not functional yet) --- hanabi/__init__.py | 0 constants.py => hanabi/constants.py | 0 {database => hanabi/database}/__init__.py | 0 {database => hanabi/database}/database.py | 0 .../database}/games_seeds_schema.sql | 0 {database => hanabi/database}/init_database.py | 0 .../database}/variant_suits_schema.sql | 0 hanabi.py => hanabi/game.py | 2 +- hanabi_suite.py => hanabi/hanabi_cli.py | 7 +++---- hanabi/live/__init__.py | 0 check_game.py => hanabi/live/check_game.py | 6 +++--- compress.py => hanabi/live/compress.py | 0 download_data.py => hanabi/live/download_data.py | 10 +++++----- hanab_live.py => hanabi/live/hanab_live.py | 6 +++--- .../live/instance_finder.py | 10 +++++----- site_api.py => hanabi/live/site_api.py | 0 variants.py => hanabi/live/variants.py | 2 +- {log_setup => hanabi}/logger_setup.py | 0 hanabi/solvers/__init__.py | 0 .../solvers/deck_analyzer.py | 6 ++---- .../solvers/greedy_solver.py | 11 +++++------ sat.py => hanabi/solvers/sat.py | 15 ++++++--------- log_setup/__init__.py | 4 ---- 23 files changed, 34 insertions(+), 45 deletions(-) create mode 100644 hanabi/__init__.py rename constants.py => hanabi/constants.py (100%) rename {database => hanabi/database}/__init__.py (100%) rename {database => hanabi/database}/database.py (100%) rename {database => hanabi/database}/games_seeds_schema.sql (100%) rename {database => hanabi/database}/init_database.py (100%) rename {database => hanabi/database}/variant_suits_schema.sql (100%) rename hanabi.py => hanabi/game.py (99%) rename hanabi_suite.py => hanabi/hanabi_cli.py (94%) create mode 100644 hanabi/live/__init__.py rename check_game.py => hanabi/live/check_game.py (94%) rename compress.py => hanabi/live/compress.py (100%) rename download_data.py => hanabi/live/download_data.py (96%) rename hanab_live.py => hanabi/live/hanab_live.py (97%) rename instance_finder.py => hanabi/live/instance_finder.py (96%) rename site_api.py => hanabi/live/site_api.py (100%) rename variants.py => hanabi/live/variants.py (99%) rename {log_setup => hanabi}/logger_setup.py (100%) create mode 100644 hanabi/solvers/__init__.py rename deck_analyzer.py => hanabi/solvers/deck_analyzer.py (98%) rename greedy_solver.py => hanabi/solvers/greedy_solver.py (97%) rename sat.py => hanabi/solvers/sat.py (97%) delete mode 100644 log_setup/__init__.py diff --git a/hanabi/__init__.py b/hanabi/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/constants.py b/hanabi/constants.py similarity index 100% rename from constants.py rename to hanabi/constants.py diff --git a/database/__init__.py b/hanabi/database/__init__.py similarity index 100% rename from database/__init__.py rename to hanabi/database/__init__.py diff --git a/database/database.py b/hanabi/database/database.py similarity index 100% rename from database/database.py rename to hanabi/database/database.py diff --git a/database/games_seeds_schema.sql b/hanabi/database/games_seeds_schema.sql similarity index 100% rename from database/games_seeds_schema.sql rename to hanabi/database/games_seeds_schema.sql diff --git a/database/init_database.py b/hanabi/database/init_database.py similarity index 100% rename from database/init_database.py rename to hanabi/database/init_database.py diff --git a/database/variant_suits_schema.sql b/hanabi/database/variant_suits_schema.sql similarity index 100% rename from database/variant_suits_schema.sql rename to hanabi/database/variant_suits_schema.sql diff --git a/hanabi.py b/hanabi/game.py similarity index 99% rename from hanabi.py rename to hanabi/game.py index 9dc2eed..8778fce 100644 --- a/hanabi.py +++ b/hanabi/game.py @@ -2,7 +2,7 @@ from typing import Optional, List from enum import Enum from termcolor import colored -import constants +from hanabi import constants class DeckCard: diff --git a/hanabi_suite.py b/hanabi/hanabi_cli.py similarity index 94% rename from hanabi_suite.py rename to hanabi/hanabi_cli.py index 8ad92c1..201da14 100755 --- a/hanabi_suite.py +++ b/hanabi/hanabi_cli.py @@ -1,14 +1,13 @@ #! /usr/bin/python3 import argparse -import logging import verboselogs from check_game import check_game -from download_data import detailed_export_game -from compress import link -from log_setup import logger, logger_manager +from hanabi.live.download_data import detailed_export_game +from hanabi.live.compress import link +from hanabi.log_setup import logger, logger_manager """ init db + populate tables diff --git a/hanabi/live/__init__.py b/hanabi/live/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/check_game.py b/hanabi/live/check_game.py similarity index 94% rename from check_game.py rename to hanabi/live/check_game.py index 8e82436..2235eee 100644 --- a/check_game.py +++ b/hanabi/live/check_game.py @@ -2,11 +2,11 @@ import copy from typing import Tuple from database import conn -from compress import decompress_deck, decompress_actions, link +from hanabi.live.compress import decompress_deck, decompress_actions, link from hanabi import GameState -from hanab_live import HanabLiveInstance, HanabLiveGameState +from hanabi.live.hanab_live import HanabLiveInstance, HanabLiveGameState from sat import solve_sat -from log_setup import logger +from hanabi.log_setup import logger # returns minimal number T of turns (from game) after which instance was infeasible diff --git a/compress.py b/hanabi/live/compress.py similarity index 100% rename from compress.py rename to hanabi/live/compress.py diff --git a/download_data.py b/hanabi/live/download_data.py similarity index 96% rename from download_data.py rename to hanabi/live/download_data.py index e57c9c8..9b9a91d 100644 --- a/download_data.py +++ b/hanabi/live/download_data.py @@ -3,13 +3,13 @@ from typing import Dict, Optional import psycopg2.errors -from site_api import get, api, replay -from database.database import Game, store, load, commit, conn, cur -from compress import compress_deck, compress_actions, DeckCard, Action, InvalidFormatError -from variants import variant_id, variant_name +from hanabi.live.site_api import get, api +from hanabi.database.database import conn, cur +from hanabi.live.compress import compress_deck, compress_actions, DeckCard, Action, InvalidFormatError +from hanabi.live.variants import variant_id, variant_name from hanab_live import HanabLiveInstance, HanabLiveGameState -from log_setup import logger +from hanabi.log_setup import logger # diff --git a/hanab_live.py b/hanabi/live/hanab_live.py similarity index 97% rename from hanab_live.py rename to hanabi/live/hanab_live.py index 0b4821b..832dc04 100644 --- a/hanab_live.py +++ b/hanabi/live/hanab_live.py @@ -1,8 +1,8 @@ -from typing import List, Optional +from typing import List import hanabi -import constants -from variants import Variant +from hanabi import constants +from hanabi.live.variants import Variant class HanabLiveInstance(hanabi.HanabiInstance): diff --git a/instance_finder.py b/hanabi/live/instance_finder.py similarity index 96% rename from instance_finder.py rename to hanabi/live/instance_finder.py index bd6b635..7624999 100644 --- a/instance_finder.py +++ b/hanabi/live/instance_finder.py @@ -5,17 +5,17 @@ import concurrent.futures import traceback from sat import solve_sat -from database.database import conn, cur -from download_data import detailed_export_game +from hanabi.database.database import conn, cur +from hanabi.live.download_data import detailed_export_game from alive_progress import alive_bar -from compress import decompress_deck, link +from hanabi.live.compress import decompress_deck, link from hanabi import HanabiInstance from threading import Lock from time import perf_counter from greedy_solver import GameState, GreedyStrategy -from log_setup import logger +from hanabi.log_setup import logger from deck_analyzer import analyze, InfeasibilityReason -from variants import Variant +from hanabi.live.variants import Variant MAX_PROCESSES = 6 diff --git a/site_api.py b/hanabi/live/site_api.py similarity index 100% rename from site_api.py rename to hanabi/live/site_api.py diff --git a/variants.py b/hanabi/live/variants.py similarity index 99% rename from variants.py rename to hanabi/live/variants.py index 3dd95e6..b89a352 100644 --- a/variants.py +++ b/hanabi/live/variants.py @@ -2,7 +2,7 @@ import enum from typing import List, Optional from hanabi import DeckCard, ActionType -from database.database import cur +from hanabi.database.database import cur def variant_id(name) -> Optional[int]: diff --git a/log_setup/logger_setup.py b/hanabi/logger_setup.py similarity index 100% rename from log_setup/logger_setup.py rename to hanabi/logger_setup.py diff --git a/hanabi/solvers/__init__.py b/hanabi/solvers/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/deck_analyzer.py b/hanabi/solvers/deck_analyzer.py similarity index 98% rename from deck_analyzer.py rename to hanabi/solvers/deck_analyzer.py index a476f8c..2adbc03 100644 --- a/deck_analyzer.py +++ b/hanabi/solvers/deck_analyzer.py @@ -1,11 +1,9 @@ -from compress import DeckCard -from typing import List +from hanabi.live.compress import DeckCard from enum import Enum from database import conn from hanabi import HanabiInstance, pp_deck -from compress import decompress_deck -import constants +from hanabi.live.compress import decompress_deck class InfeasibilityType(Enum): diff --git a/greedy_solver.py b/hanabi/solvers/greedy_solver.py similarity index 97% rename from greedy_solver.py rename to hanabi/solvers/greedy_solver.py index a864817..d352e5d 100755 --- a/greedy_solver.py +++ b/hanabi/solvers/greedy_solver.py @@ -2,13 +2,12 @@ import collections import sys from enum import Enum -from log_setup import logger -from typing import Tuple, List, Optional -from time import sleep +from hanabi.log_setup import logger +from typing import Optional -from hanabi import DeckCard, Action, ActionType, GameState, HanabiInstance -from compress import link, decompress_deck -from database.database import conn +from hanabi import DeckCard, GameState, HanabiInstance +from hanabi.live.compress import link, decompress_deck +from hanabi.database.database import conn class CardType(Enum): diff --git a/sat.py b/hanabi/solvers/sat.py similarity index 97% rename from sat.py rename to hanabi/solvers/sat.py index 4a22a30..6f0438a 100644 --- a/sat.py +++ b/hanabi/solvers/sat.py @@ -1,16 +1,13 @@ import copy -from pysmt.shortcuts import Symbol, Bool, Not, Implies, Iff, And, Or, AtMostOne, ExactlyOne, get_model, get_atoms, get_formula_size, get_unsat_core, Equals, GE, NotEquals, Int +from pysmt.shortcuts import Symbol, Bool, Not, Implies, Iff, And, Or, AtMostOne, get_model, Equals, GE, NotEquals, Int from pysmt.typing import INT -from pysmt.rewritings import conjunctive_partition -import json -from typing import List, Optional, Tuple -from concurrent.futures import ProcessPoolExecutor +from typing import Optional, Tuple -from hanabi import DeckCard, Action, ActionType, GameState, HanabiInstance -from compress import link, decompress_deck +from hanabi import DeckCard, GameState, HanabiInstance +from hanabi.live.compress import link, decompress_deck from greedy_solver import GreedyStrategy -from constants import COLOR_INITIALS -from log_setup import logger +from hanabi.constants import COLOR_INITIALS +from hanabi.log_setup import logger # literals to model game as sat instance to check for feasibility diff --git a/log_setup/__init__.py b/log_setup/__init__.py deleted file mode 100644 index 34da869..0000000 --- a/log_setup/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -from .logger_setup import LoggerManager - -logger_manager = LoggerManager() -logger = logger_manager.get_logger()