Skip to content

Commit

Permalink
warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
oelarnes committed Jan 9, 2025
1 parent fd6922f commit 076f460
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 10 deletions.
8 changes: 5 additions & 3 deletions scripts/post_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
10 changes: 9 additions & 1 deletion spells/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
8 changes: 7 additions & 1 deletion spells/cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
10 changes: 9 additions & 1 deletion spells/draft_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion spells/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
7 changes: 4 additions & 3 deletions spells/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 076f460

Please sign in to comment.