conda_argparse#

Conda command line interface parsers.

Classes#

ArgumentParser

Object for parsing command line strings into Python objects.

_GreedySubParsersAction

A custom subparser action to conditionally act as a greedy consumer.

_LazyParserMap

A dict that triggers lazy parser loading on key access.

_LazySubParsersAction

Extends _GreedySubParsersAction with lazy loading of subcommand parsers.

Functions#

_user_rc_path(→ str)

_sys_rc_path(→ str)

_escaped_user_rc_path(→ str)

_escaped_sys_rc_path(→ str)

_configure_builtin_subcommand(→ ArgumentParser)

generate_pre_parser(→ ArgumentParser)

generate_parser(→ ArgumentParser)

do_call(args, parser)

Serves as the primary entry point for commands referred to in this file and for

find_builtin_commands(→ tuple[str, ...])

_exec(executable_args, env_vars)

_exec_win(executable_args, env_vars)

_exec_unix(executable_args, env_vars)

configure_parser_plugins(→ None)

For each of the provided plugin-based subcommands, we'll create

Attributes#

BUILTIN_SUBCOMMANDS

Built-in subcommand module, help, and parser metadata.

BUILTIN_COMMANDS

Names (and aliases) of built-in commands; these cannot be overridden by plugin subcommands.

_PLUGIN_FREE_BUILTIN_COMMANDS

Built-in commands that intentionally skip plugin discovery.

_user_rc_path() → str#
_sys_rc_path() → str#
_escaped_user_rc_path() → str#
_escaped_sys_rc_path() → str#
BUILTIN_SUBCOMMANDS: dict[str, dict]#

Built-in subcommand module, help, and parser metadata.

BUILTIN_COMMANDS#

Names (and aliases) of built-in commands; these cannot be overridden by plugin subcommands.

_PLUGIN_FREE_BUILTIN_COMMANDS#

Built-in commands that intentionally skip plugin discovery.

_configure_builtin_subcommand(sub_parsers, name: str) → ArgumentParser#
generate_pre_parser(*, with_plugins: bool = True, **kwargs) → ArgumentParser#
generate_parser(**kwargs) → ArgumentParser#
do_call(args: argparse.Namespace, parser: ArgumentParser)#

Serves as the primary entry point for commands referred to in this file and for all registered plugin subcommands.

find_builtin_commands(parser: argparse.ArgumentParser) → tuple[str, ...]#
class ArgumentParser(*args, add_help=True, **kwargs)#

Bases: argparse.ArgumentParser

Object for parsing command line strings into Python objects.

Keyword Arguments:
  • (default (- color - Allow color output in help messages) -- os.path.basename(sys.argv[0]))

  • (default -- auto-generated from arguments)

  • does (- description -- A description of what the program)

  • descriptions (- epilog -- Text following the argument)

  • one (- parents -- Parsers whose arguments should be copied into this)

  • messages (- formatter_class -- HelpFormatter class for printing help)

  • arguments (- argument_default -- The default value for all)

  • containing (- fromfile_prefix_chars -- Characters that prefix files) -- additional arguments

  • arguments

  • conflicts (- conflict_handler -- String indicating how to handle)

  • option (- add_help -- Add a -h/-help)

  • unambiguously (- allow_abbrev -- Allow long options to be abbreviated)

  • with (- exit_on_error -- Determines whether or not ArgumentParser exits) -- error info when an error occurs

  • choices (- suggest_on_error - Enables suggestions for mistyped argument) -- and subparser names (default: False)

  • (default -- False)

_check_value(action, value)#
parse_args(*args, override_args=None, **kwargs)#
class _GreedySubParsersAction(option_strings, prog, parser_class, dest=SUPPRESS, required=False, help=None, metavar=None)#

Bases: argparse._SubParsersAction

A custom subparser action to conditionally act as a greedy consumer.

This is a workaround since argparse.REMAINDER does not work as expected, see python/cpython#61252.

__call__(parser, namespace, values, option_string=None)#
_get_subactions()#

Sort actions for subcommands to appear alphabetically in help blurb.

class _LazyParserMap(action)#

Bases: dict

A dict that triggers lazy parser loading on key access.

Used as the _name_parser_map for _LazySubParsersAction so that any consumer reading a specific subcommand parser (e.g. sphinx-argparse navigating a :path: directive) gets the fully-configured parser rather than the lightweight stub registered at generate_parser() time.

Initialize self. See help(type(self)) for accurate signature.

_action#
property _ready#

True once the owning action is initialized and not mid-build.

_resolve(key)#

Ensure key is fully loaded (builtin or plugin).

_resolve_all()#

Load every lazy subcommand and all plugins.

_known_names()#

Builtin names known without running any configure_parser or plugin discovery.

The union of already-materialized entries in the underlying dict (stubs and real parsers), pending lazy-loader names, and aliases. Plugin-provided subcommand names are not included here; callers that need them should use items() / values() / _resolve_all().

__getitem__(key)#

Return self[key].

get(key, default=None)#

Return the value for key if key is in the dictionary, else default.

__contains__(key)#

True if the dictionary has the specified key, else False.

items()#

Return a set-like object providing a view on the dict's items.

values()#

Return an object providing a view on the dict's values.

keys()#

Return a set-like object providing a view on the dict's keys.

__iter__()#

Implement iter(self).

__len__()#

Return len(self).

class _LazySubParsersAction(*args, **kwargs)#

Bases: _GreedySubParsersAction

Extends _GreedySubParsersAction with lazy loading of subcommand parsers.

Registers lightweight stub parsers for all built-in subcommands at generate_parser() time (name + help text only). The real configure_parser is called on demand when a subcommand is actually invoked.

Plugin subcommand discovery is deferred until a non-builtin command is requested or --help is displayed.

_name_parser_map#
choices#
_lazy_loaders: dict[str, tuple[str, dict]]#
_lazy_aliases: dict[str, str]#
_loading_name: str | None = None#
_plugins_loaded = False#
_building = False#
add_lazy_subcommand(name, module_path, help_text, **kwargs)#

Register a lazy-loaded subcommand with a stub parser.

add_parser(name, **kwargs)#

During lazy loading, return the existing stub instead of creating a new parser.

_ensure_loaded(name)#

Load a lazy subcommand's full parser configuration.

_ensure_plugins_loaded()#

Discover and register plugin subcommands on demand.

__call__(parser, namespace, values, option_string=None)#
_get_subactions()#

Ensure plugins are discovered before listing subcommands in help.

_exec(executable_args, env_vars)#
_exec_win(executable_args, env_vars)#
_exec_unix(executable_args, env_vars)#
configure_parser_plugins(sub_parsers) → None#

For each of the provided plugin-based subcommands, we'll create a new subparser for an improved help printout and calling the configure_parser() with the newly created subcommand specific argument parser.