npdoc_cli#

Created on Sat Feb 1 11:54:32 2025

@author: coleg

Attributes#

cli

Instance of NumpyDocCLI for generating CLI's.

Exceptions#

CLIArgError

Error caused by invalid doc strings.

Classes#

FunctionInput

Class for organizing function inputs.

NumpyDocCommand

Class for parsing function signatures/doc strings in argparse objects.

NumpyDocCLI

Class for generating a CLI from numpy doc strings and type signatures.

Package Contents#

exception npdoc_cli.CLIArgError#

Bases: Exception

Error caused by invalid doc strings.

class npdoc_cli.FunctionInput#

Class for organizing function inputs.

pa = []#

List of positional arguments for a function input.

kwa#

Dictionairy of keyword arguments for a function input.

disp()#
class npdoc_cli.NumpyDocCommand(obj: callable)#

Class for parsing function signatures/doc strings in argparse objects.

obj#

Object called to and called during cli dispatch.

fname#

Name of obj.

property defaults: dict#

Dictionairy of keyword arguments and their default value

property types: dict#

Dictionairy of arguments and types.

disp()#

Print scraped settings for debugging.

scrape(replace_underscores: bool = True) FunctionInput#

Scrape doc strings and functions signature.

Turns doc strings and function signatures into settings that can be passed into argparse to generate a command line interface.

Parameters:
replace_underscoresbool, optional

Replace underscores in argument/function names with dashes, stylistic choice. The default is True.

Returns:
parser_insFunctionInput

Inputs to be passed into argparse.ArgumentParser

arg_ins_lsFunctionInput

Inputs to be passed into argparse.ArgumentParser.add_argument

Raises:
CLIArgError

If problem is found with an argument’s signature or documentation.

class npdoc_cli.NumpyDocCLI#

Class for generating a CLI from numpy doc strings and type signatures.

entry = None#

NumpyDocCommand of program entry point.

commands = []#

List of NumpyDocCommand for program commands.

subcommands#

Dictionairy of NumpyDocCommand for each subcommands.

program_parser = None#

ArgumentParser for program entry point.

command_parsers = []#

ArgumentParser for each command.

subcommand_parsers#

ArgumentParser for each subcommand

reset()#

Reset CLI to empty.

Returns:
None.
program(function: callable) callable#

Wrapper function to define the entry point.

Parameters:
functioncallable

That is called.

Returns:
functioncallable

The passed function, unmodified.

command(obj: object) object#

Wrapper function to defined commands for entry point.

Parameters:
objobject

Class definition if using subcommands, function it not.

Returns:
object

Same object passed as input, unmodified.

subcommand(function: callable) callable#

Wrapper function to define subcommands for a command.

Parameters:
functionobject

Function to be called as subcommand. Should belong as submethod to its parent commmand’s class definition.

Returns:
functioncallable

Same function passed, unmodified.

tree()#

Print program/command/subcommand heirarchy.

Returns:
None.
build(*command_instances: object, replace_underscores: bool = True, sort: str = 'None')#

Build a CLI.

Parameters:
*instancesobject

Instances of classes wrapped in command to use when calling subcommands. If an instance of a command wrapped class is not passed, the class itself will be used to call the subcommand.

replace_underscoresbool, optional

Repace underscores in argument/command names with dashes. The default is True.

sortstr, {None, alphabetical}

Sort commands and subcommands by key.

Returns:
None.
parse_args(args: list[str] = None) argparse.Namespace#

Parse command line arguments.

See argparse.ArgumentParser.parse_args for more info.

Parameters:
argslist[str], optional

List of arguments to parse. If None, parses from command line.

Returns:
argparse.Namespace

Parsed arguments.

print_help()#

Print help string for CLI

Returns:
None.
dispatch(args: argparse.Namespace)#

Dispatch command line arguments to a the right function.

Parameters:
args_ap.Namespace

Output of NumpyDocCLI.parse_args().

Returns:
any

Output of dispatched function.

npdoc_cli.cli#

Instance of NumpyDocCLI for generating CLI’s.