force kw-only args to avoid possible mistakes
add some of the notes from the discussion regarding tmpdir/reasoning
This commit is contained in:
parent
4780c5a6d7
commit
a11676896f
1 changed files with 16 additions and 11 deletions
|
@ -207,7 +207,7 @@ def _modules(*, all: bool=False) -> Iterable[HPIModule]:
|
||||||
warning(f'Skipped {len(skipped)} modules: {skipped}. Pass --all if you want to see them.')
|
warning(f'Skipped {len(skipped)} modules: {skipped}. Pass --all if you want to see them.')
|
||||||
|
|
||||||
|
|
||||||
def modules_check(verbose: bool, list_all: bool, quick: bool, for_modules: List[str]) -> None:
|
def modules_check(*, verbose: bool, list_all: bool, quick: bool, for_modules: List[str]) -> None:
|
||||||
if len(for_modules) > 0:
|
if len(for_modules) > 0:
|
||||||
# if you're checking specific modules, show errors
|
# if you're checking specific modules, show errors
|
||||||
# hopefully makes sense?
|
# hopefully makes sense?
|
||||||
|
@ -268,7 +268,7 @@ def modules_check(verbose: bool, list_all: bool, quick: bool, for_modules: List[
|
||||||
info(f' - stats: {res}')
|
info(f' - stats: {res}')
|
||||||
|
|
||||||
|
|
||||||
def list_modules(list_all: bool) -> None:
|
def list_modules(*, list_all: bool) -> None:
|
||||||
# todo add a --sort argument?
|
# todo add a --sort argument?
|
||||||
tabulate_warnings()
|
tabulate_warnings()
|
||||||
|
|
||||||
|
@ -309,14 +309,14 @@ def _requires(module: str) -> Sequence[str]:
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
||||||
def module_requires(module: str) -> None:
|
def module_requires(*, module: str) -> None:
|
||||||
rs = [f"'{x}'" for x in _requires(module)]
|
rs = [f"'{x}'" for x in _requires(module)]
|
||||||
eprint(f'dependencies of {module}')
|
eprint(f'dependencies of {module}')
|
||||||
for x in rs:
|
for x in rs:
|
||||||
click.echo(x)
|
click.echo(x)
|
||||||
|
|
||||||
|
|
||||||
def module_install(user: bool, module: str) -> None:
|
def module_install(*, user: bool, module: str) -> None:
|
||||||
# TODO hmm. not sure how it's gonna work -- presumably people use different means of installing...
|
# TODO hmm. not sure how it's gonna work -- presumably people use different means of installing...
|
||||||
# how do I install into the 'same' environment??
|
# how do I install into the 'same' environment??
|
||||||
import shlex
|
import shlex
|
||||||
|
@ -337,17 +337,22 @@ def main() -> None:
|
||||||
Tool for HPI
|
Tool for HPI
|
||||||
Work in progress, will be used for config management, troubleshooting & introspection
|
Work in progress, will be used for config management, troubleshooting & introspection
|
||||||
'''
|
'''
|
||||||
# note: code in groups doesnt run unless a subcommand is passed
|
# for potential future reference, if shared state needs to be added to groups
|
||||||
# https://click.palletsprojects.com/en/7.x/commands/#group-invocation-without-command
|
# https://click.palletsprojects.com/en/7.x/commands/#group-invocation-without-command
|
||||||
# https://click.palletsprojects.com/en/7.x/commands/#multi-command-chaining
|
# https://click.palletsprojects.com/en/7.x/commands/#multi-command-chaining
|
||||||
|
|
||||||
|
# acts as a contextmanager of sorts - any subcommand will then run
|
||||||
|
# in something like /tmp/hpi_temp_dir
|
||||||
|
# to avoid importing relative modules by accident during development
|
||||||
|
# maybe can be removed later if theres more test coverage/confidence that nothing
|
||||||
|
# would happen?
|
||||||
|
import tempfile
|
||||||
|
|
||||||
# use a particular directory instead of a random one, since
|
# use a particular directory instead of a random one, since
|
||||||
# click being decorator based means its more complicated
|
# click being decorator based means its more complicated
|
||||||
# to run things at the end (would need to use a callback or pass context)
|
# to run things at the end (would need to use a callback or pass context)
|
||||||
# https://click.palletsprojects.com/en/7.x/commands/#nested-handling-and-contexts
|
# https://click.palletsprojects.com/en/7.x/commands/#nested-handling-and-contexts
|
||||||
|
|
||||||
import tempfile
|
|
||||||
|
|
||||||
tdir: str = os.path.join(tempfile.gettempdir(), 'hpi_temp_dir')
|
tdir: str = os.path.join(tempfile.gettempdir(), 'hpi_temp_dir')
|
||||||
if not os.path.exists(tdir):
|
if not os.path.exists(tdir):
|
||||||
os.makedirs(tdir)
|
os.makedirs(tdir)
|
||||||
|
@ -370,7 +375,7 @@ def doctor_cmd(verbose: bool, list_all: bool, quick: bool, skip_conf: bool, modu
|
||||||
if not skip_conf:
|
if not skip_conf:
|
||||||
config_ok()
|
config_ok()
|
||||||
# TODO check that it finds private modules too?
|
# TODO check that it finds private modules too?
|
||||||
modules_check(verbose, list_all, quick, list(module))
|
modules_check(verbose=verbose, list_all=list_all, quick=quick, for_modules=list(module))
|
||||||
|
|
||||||
|
|
||||||
@main.group(name='config', short_help='work with configuration')
|
@main.group(name='config', short_help='work with configuration')
|
||||||
|
@ -396,7 +401,7 @@ def config_create_cmd() -> None:
|
||||||
@click.option('--all', 'list_all', is_flag=True, help='List all modules, including disabled')
|
@click.option('--all', 'list_all', is_flag=True, help='List all modules, including disabled')
|
||||||
def module_cmd(list_all: bool) -> None:
|
def module_cmd(list_all: bool) -> None:
|
||||||
'''List available modules'''
|
'''List available modules'''
|
||||||
list_modules(list_all)
|
list_modules(list_all=list_all)
|
||||||
|
|
||||||
|
|
||||||
@main.group(name='module', short_help='module management')
|
@main.group(name='module', short_help='module management')
|
||||||
|
@ -413,7 +418,7 @@ def module_requires_cmd(module: str) -> None:
|
||||||
|
|
||||||
MODULE is a specific module name (e.g. my.reddit)
|
MODULE is a specific module name (e.g. my.reddit)
|
||||||
'''
|
'''
|
||||||
module_requires(module)
|
module_requires(module=module)
|
||||||
|
|
||||||
|
|
||||||
@module_grp.command(name='install', short_help='install module deps')
|
@module_grp.command(name='install', short_help='install module deps')
|
||||||
|
@ -426,7 +431,7 @@ def module_install_cmd(user: bool, module: str) -> None:
|
||||||
MODULE is a specific module name (e.g. my.reddit)
|
MODULE is a specific module name (e.g. my.reddit)
|
||||||
'''
|
'''
|
||||||
# todo could add functions to check specific module etc..
|
# todo could add functions to check specific module etc..
|
||||||
module_install(user, module)
|
module_install(user=user, module=module)
|
||||||
|
|
||||||
|
|
||||||
# todo: add more tests?
|
# todo: add more tests?
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue