6060
6161from .util import CliContext , pass_clictx
6262
63+ with importlib .resources .path ("tptools" , "ext" , "squore" , "assets" ) as assets_path :
64+ SETTINGS_JSON_PATH = assets_path / "settings.json"
65+ CONFIG_TOML_PATH = assets_path / "config.toml"
66+ # save to exit the context manager here as no temporary files are needed
67+
6368DEVMAP_TOML_PATH = pathlib .Path ("Squore.dev_court_map.toml" )
6469SQUORE_PATH_VERSION = "v1"
6570API_MOUNTPOINT = "/squore"
@@ -696,53 +701,47 @@ async def setup_for_squore(
696701 only_this_court : bool = False ,
697702 max_matches_per_court : int | None = None ,
698703 api_mount_point : str = API_MOUNTPOINT ,
699- settings_json : pathlib .Path | None = None ,
700- config_toml : pathlib .Path | None = None ,
704+ settings_json : pathlib .Path = SETTINGS_JSON_PATH ,
705+ config_toml : pathlib .Path = CONFIG_TOML_PATH ,
701706 devmap_toml : pathlib .Path = DEVMAP_TOML_PATH ,
702707) -> PluginLifespan :
703708 api_path = "/" .join ((api_mount_point , SQUORE_PATH_VERSION ))
704709
705710 logger .debug ("Starting squoresrv configuration…" )
706711
707- with importlib .resources .path ("tptools" , "ext" , "squore" , "assets" ) as assets_path :
708- if settings_json is None :
709- settings_json = assets_path / "settings.json"
710- logger .info (f"Serving app settings from { settings_json } " )
711- if config_toml is None :
712- config_toml = assets_path / "config.toml"
713- logger .info (f"Reading tournament & match config from { config_toml } " )
714-
715- if devmap_toml .exists ():
716- logger .info (f"Reading device to court map from { devmap_toml } " )
717-
718- squoreapp .state .squore = {
719- "settings" : settings_json ,
720- "config" : config_toml ,
721- "devmap" : devmap_toml ,
722- "matchfeedqueryparams" : MatchFeedQueryParams (
723- only_this_court = only_this_court ,
724- max_matches_per_court = max_matches_per_court ,
725- ),
726- }
727- squoreapp .mount (
728- "/flags" ,
729- StaticFiles (directory = assets_path / "flags" , html = True ),
730- name = "flags" ,
731- )
712+ logger .info (f"Serving app settings from { settings_json } " )
713+ logger .info (f"Reading tournament & match config from { config_toml } " )
714+ if devmap_toml .exists ():
715+ logger .info (f"Reading device to court map from { devmap_toml } " )
716+
717+ squoreapp .state .squore = {
718+ "settings" : settings_json ,
719+ "config" : config_toml ,
720+ "devmap" : devmap_toml ,
721+ "matchfeedqueryparams" : MatchFeedQueryParams (
722+ only_this_court = only_this_court ,
723+ max_matches_per_court = max_matches_per_court ,
724+ ),
725+ }
726+ squoreapp .mount (
727+ "/flags" ,
728+ StaticFiles (directory = assets_path / "flags" , html = True ),
729+ name = "flags" ,
730+ )
732731
733- clictx .api .mount (path = api_path , app = squoreapp , name = "squore" )
734- clictx .api .include_router (deprecated_routes , prefix = api_mount_point )
735- logger .info (f"Configured the app to serve to Squore from { api_path } " )
732+ clictx .api .mount (path = api_path , app = squoreapp , name = "squore" )
733+ clictx .api .include_router (deprecated_routes , prefix = api_mount_point )
734+ logger .info (f"Configured the app to serve to Squore from { api_path } " )
736735
737- async def callback (tournament : Tournament ) -> None :
738- logger .info ("Received new tournament data, making MatchesFeed" )
739- squoreapp .state .tournament = (
740- sqt := SquoreTournament .from_tournament (tournament )
741- )
742- clictx .itc .set ("sqtournament" , sqt )
736+ async def callback (tournament : Tournament ) -> None :
737+ logger .info ("Received new tournament data, making MatchesFeed" )
738+ squoreapp .state .tournament = (
739+ sqt := SquoreTournament .from_tournament (tournament )
740+ )
741+ clictx .itc .set ("sqtournament" , sqt )
743742
744- updates_gen = cast (AsyncGenerator [Tournament ], clictx .itc .updates ("tournament" ))
745- yield react_to_data_update (updates_gen , callback = callback )
743+ updates_gen = cast (AsyncGenerator [Tournament ], clictx .itc .updates ("tournament" ))
744+ yield react_to_data_update (updates_gen , callback = callback )
746745
747746
748747@plugin
@@ -770,12 +769,16 @@ async def callback(tournament: Tournament) -> None:
770769 "--settings-json" ,
771770 metavar = "PATH" ,
772771 type = click .Path (path_type = pathlib .Path ),
772+ default = SETTINGS_JSON_PATH ,
773+ show_default = True ,
773774 help = "Path of file to serve when Squore requests app settings" ,
774775)
775776@click .option (
776777 "--config-toml" ,
777778 metavar = "PATH" ,
778779 type = click .Path (path_type = pathlib .Path ),
780+ default = CONFIG_TOML_PATH ,
781+ show_default = True ,
779782 help = "Path of file to use for Squore tournament & match config" ,
780783)
781784@click .option (
@@ -792,8 +795,8 @@ async def squoresrv(
792795 only_this_court : bool ,
793796 max_matches_per_court : int | None ,
794797 api_mount_point : str ,
795- settings_json : pathlib .Path | None ,
796- config_toml : pathlib .Path | None ,
798+ settings_json : pathlib .Path ,
799+ config_toml : pathlib .Path ,
797800 devmap_toml : pathlib .Path ,
798801) -> PluginLifespan :
799802 """Mount endpoints to serve data for Squore"""
0 commit comments