diff --git a/scripts/post_install.py b/scripts/post_install.py index 2f317a4..cb63533 100644 --- a/scripts/post_install.py +++ b/scripts/post_install.py @@ -5,25 +5,27 @@ from spells.cache import spells_print + def modify_activation_script(): spells_print("install", "configuring environment for spells") venv_path = os.environ.get("VIRTUAL_ENV") if not venv_path: print("No virtual environment found") return - + if sys.platform == "win32": activate_script = Path(venv_path) / "Scripts" / "activate.bat" else: activate_script = Path(venv_path) / "bin" / "activate" - + if not activate_script.exists(): print(f"Activation script not found at {activate_script}") return - + with open(activate_script, "a") as f: f.write("\n# Custom environment setup\n") f.write("export LOG=$HOME/.local/share/spells/.logs/spells.log\n") + if __name__ == "__main__": modify_activation_script() diff --git a/spells/__init__.py b/spells/__init__.py index a0f6133..33b81e7 100644 --- a/spells/__init__.py +++ b/spells/__init__.py @@ -7,4 +7,12 @@ setup_logging() -__all__ = ["summon", "view_select", "get_names", "ColSpec", "ColType", "ColName", "logging"] +__all__ = [ + "summon", + "view_select", + "get_names", + "ColSpec", + "ColType", + "ColName", + "logging", +] diff --git a/spells/cards.py b/spells/cards.py index 54e58f9..47d3696 100644 --- a/spells/cards.py +++ b/spells/cards.py @@ -78,7 +78,13 @@ def card_df(draft_set_code: str, names: list[str]) -> pl.DataFrame: draft_set_json = _fetch_mtg_json(draft_set_code) booster_info = draft_set_json["data"]["booster"] - booster_type = "play" if "play" in booster_info else "draft" if "draft" in booster_info else list(booster_info.keys())[0] + booster_type = ( + "play" + if "play" in booster_info + else "draft" + if "draft" in booster_info + else list(booster_info.keys())[0] + ) set_codes = booster_info[booster_type]["sourceSetCodes"] set_codes.reverse() diff --git a/spells/draft_data.py b/spells/draft_data.py index 9055c5d..893017d 100644 --- a/spells/draft_data.py +++ b/spells/draft_data.py @@ -148,6 +148,10 @@ def seed_params(expr): ) ) except KeyError: + logging.warning( + f"KeyError raised in calculation of {col}, probably caused by " + + "missing context. Column will have value `None`" + ) expr = tuple(pl.lit(None).alias(f"{col}_{name}") for name in names) else: expr = tuple(map(lambda name: pl.col(f"{col}_{name}"), names)) @@ -233,7 +237,11 @@ def _infer_dependencies( ): dependencies.add(split[0]) found = True - # fail silently here, so that columns can be passed in harmlessly + if not found: + logging.warning( + f"No column definition found matching dependency {item}! " + + "`summon` will fail if called with this column" + ) return dependencies diff --git a/spells/external.py b/spells/external.py index 1b7cf4e..ec577f5 100644 --- a/spells/external.py +++ b/spells/external.py @@ -100,7 +100,7 @@ def cli() -> int: def _add(set_code: str, force_download=False): - if set_code == 'all': + if set_code == "all": for code in all_sets: _add(code, force_download=force_download) diff --git a/spells/log.py b/spells/log.py index 6c447db..6462285 100644 --- a/spells/log.py +++ b/spells/log.py @@ -63,12 +63,13 @@ def console_logging(log_level): logger.removeHandler(console_handler) -def make_verbose(level: int=logging.ERROR) -> Callable: +def make_verbose(level: int = logging.ERROR) -> Callable: def decorator(func: Callable) -> Callable: @wraps(func) - def wrapped(*args, log_to_console: int=level, **kwargs): + def wrapped(*args, log_to_console: int = level, **kwargs): with console_logging(log_to_console): return func(*args, **kwargs) + return wrapped - return decorator + return decorator