|
1 | | -# |
2 | | -# -*- coding: utf-8 -*- |
3 | | -# flake8: noqa F401 |
4 | 1 | """This simply imports certain things for backwards compatibility.""" |
5 | 2 |
|
| 3 | +import argparse |
6 | 4 | import importlib.metadata as importlib_metadata |
| 5 | +import sys |
7 | 6 |
|
8 | 7 | try: |
9 | 8 | __version__ = importlib_metadata.version(__name__) |
10 | 9 | except importlib_metadata.PackageNotFoundError: # pragma: no cover |
11 | 10 | # package is not installed |
12 | 11 | pass |
13 | 12 |
|
14 | | -from . import plugin |
15 | 13 | from .ansi import ( |
16 | 14 | Bg, |
17 | 15 | Cursor, |
|
31 | 29 | register_argparse_argument_parameter, |
32 | 30 | set_default_argument_parser_type, |
33 | 31 | ) |
| 32 | + |
| 33 | +# Check if user has defined a module that sets a custom value for argparse_custom.DEFAULT_ARGUMENT_PARSER. |
| 34 | +# Do this before loading cmd2.Cmd class so its commands use the custom parser. |
| 35 | +cmd2_parser_module = getattr(argparse, 'cmd2_parser_module', None) |
| 36 | +if cmd2_parser_module is not None: |
| 37 | + import importlib |
| 38 | + |
| 39 | + importlib.import_module(cmd2_parser_module) |
| 40 | + |
| 41 | +from . import plugin |
34 | 42 | from .cmd2 import Cmd |
35 | | -from .command_definition import ( |
36 | | - CommandSet, |
37 | | - with_default_category, |
38 | | -) |
39 | | -from .constants import ( |
40 | | - COMMAND_NAME, |
41 | | - DEFAULT_SHORTCUTS, |
42 | | -) |
43 | | -from .decorators import ( |
44 | | - as_subcommand_to, |
45 | | - with_argparser, |
46 | | - with_argument_list, |
47 | | - with_category, |
48 | | -) |
| 43 | +from .command_definition import CommandSet, with_default_category |
| 44 | +from .constants import COMMAND_NAME, DEFAULT_SHORTCUTS |
| 45 | +from .decorators import as_subcommand_to, with_argparser, with_argument_list, with_category |
49 | 46 | from .exceptions import ( |
50 | 47 | Cmd2ArgparseError, |
51 | 48 | CommandSetRegistrationError, |
|
55 | 52 | ) |
56 | 53 | from .parsing import Statement |
57 | 54 | from .py_bridge import CommandResult |
58 | | -from .utils import ( |
59 | | - CompletionMode, |
60 | | - CustomCompletionSettings, |
61 | | - Settable, |
62 | | - categorize, |
63 | | -) |
| 55 | +from .utils import CompletionMode, CustomCompletionSettings, Settable, categorize |
64 | 56 |
|
65 | 57 | __all__: list[str] = [ |
66 | 58 | 'COMMAND_NAME', |
|
0 commit comments