55import importlib .resources as imlr
66import typing
77from inspect import isfunction
8+ from pathlib import Path
89from types import MappingProxyType
910
1011import matplotlib .pyplot as plt
1112import matplotlib .style as mpls
1213from loam .cli import CLIManager , Subcmd
1314
15+ from . import __doc__ as doc_module
1416from . import (
15- ISOLATED ,
1617 _styles ,
1718 commands ,
1819 conf ,
19- config ,
2020 field ,
2121 plates ,
2222 refstate ,
2323 rprof ,
2424 time_series ,
2525)
26- from . import __doc__ as doc_module
2726from ._helpers import baredoc
28- from .config import CONFIG_DIR
2927
3028if typing .TYPE_CHECKING :
3129 from typing import Any , Callable , List , Optional
@@ -47,11 +45,6 @@ def _load_mplstyle() -> None:
4745 """Try to load conf.plot.mplstyle matplotlib style."""
4846 for style in conf .plot .mplstyle :
4947 style_fname = style + ".mplstyle"
50- if not ISOLATED :
51- stfile = config .CONFIG_DIR / style_fname
52- if stfile .is_file ():
53- mpls .use (str (stfile ))
54- continue
5548 # try packaged version
5649 if imlr .is_resource (_styles , style_fname ):
5750 with imlr .path (_styles , style_fname ) as stfile :
@@ -90,14 +83,24 @@ def parse_args(arglist: Optional[List[str]] = None) -> Callable[[], None]:
9083 Returns:
9184 the function implementing the sub command to be executed.
9285 """
93- climan = CLIManager (conf , ** SUB_CMDS )
94-
95- bash_script = CONFIG_DIR / "bash" / "stagpy.sh"
96- bash_script .parent .mkdir (parents = True , exist_ok = True )
97- climan .bash_complete (bash_script , "stagpy" )
98- zsh_script = CONFIG_DIR / "zsh" / "_stagpy.sh"
99- zsh_script .parent .mkdir (parents = True , exist_ok = True )
100- climan .zsh_complete (zsh_script , "stagpy" , sourceable = True )
86+
87+ def compl_cmd () -> None :
88+ if conf .completions .zsh :
89+ filepath = Path ("_stagpy.sh" )
90+ print (f"writing zsh completion file { filepath } " )
91+ climan .zsh_complete (filepath , "stagpy" , sourceable = True )
92+ elif conf .completions .bash :
93+ filepath = Path ("stagpy.sh" )
94+ print (f"writing bash completion file { filepath } " )
95+ climan .bash_complete (filepath , "stagpy" )
96+ else :
97+ print ("please choose a shell, `--help` for available options" )
98+
99+ climan = CLIManager (
100+ conf ,
101+ ** SUB_CMDS ,
102+ completions = Subcmd ("generate completion scripts" , func = compl_cmd ),
103+ )
101104
102105 cmd_args = climan .parse_args (arglist )
103106 sub_cmd = cmd_args .loam_sub_name
0 commit comments