xdev.cli.main module
Defines the subcommands for the xdev CLI.
Each subcommand is its own scriptconfig class, which is registered using a
decorator. Special “dunder” variables like __command__ and __alias__
are used to control subparser configurations. The normal scriptconfig
__default__ variable controls subparser arguments. Lastly each class must
have a main classmethod, which is the logic invoked when the subcommand is
called.
- class xdev.cli.main.XdevCLI(description: str = '', sub_clis: List[Dict[str, Any]] | None = None, version: str | None = None)[source]
Bases:
ModalCLIThe XDEV CLI
A collection of excellent developer tools for excellent developers.
- class InfoCLI(*args: Any, **kwargs: Any)[source]
Bases:
DataConfigInfo about xdev
Valid options: []
- Parameters:
*args – positional arguments for this data config
**kwargs – keyword arguments for this data config
- default = {}
- class CodeblockCLI(*args: Any, **kwargs: Any)[source]
Bases:
DataConfigRemove indentation from text.
Useful for writing subscripts (e.g. python -c code) in shell files without having to resort to ugly indentation.
Valid options: []
- Parameters:
*args – positional arguments for this data config
**kwargs – keyword arguments for this data config
- classmethod main(cmdline=False, **kwargs)[source]
Example
>>> from xdev.cli.main import * # NOQA >>> CodeblockCLI.main(cmdline=0, text='foobar')
- default = {'text': <Value('')>}
- class SedCLI(*args: Any, **kwargs: Any)[source]
Bases:
DataConfigSearch and replace text in files
Valid options: []
- Parameters:
*args – positional arguments for this data config
**kwargs – keyword arguments for this data config
- default = {'dirblocklist': <Value(None)>, 'dpath': <Value(None)>, 'dry': <Value('ask')>, 'exclude': <Value(None)>, 'include': <Value(None)>, 'recursive': <Value(True)>, 'regexpr': <Value('')>, 'repl': <Value('')>, 'verbose': <Value(2)>}
- class FindCLI(*args: Any, **kwargs: Any)[source]
Bases:
DataConfigFind matching files or paths in a directory.
This is similar to the GNU find program, but written in Python. Important differences are that this program is:
has pattern first argument and uses the cwd by default.
recursive by default
has explicit include / exclude options
Example
xdev find “*.py”
Valid options: []
- Parameters:
*args – positional arguments for this data config
**kwargs – keyword arguments for this data config
- default = {'dirblocklist': <Value(None)>, 'dpath': <Value(None)>, 'exclude': <Value(None)>, 'followlinks': <Value(False)>, 'include': <Value(None)>, 'pattern': <Value('')>, 'recursive': <Value(True)>, 'type': <Value('f')>}
- class TreeCLI(*args: Any, **kwargs: Any)[source]
Bases:
DataConfigList a directory like a tree
See also
The,xdevExample
xdev tree .
Valid options: []
- Parameters:
*args – positional arguments for this data config
**kwargs – keyword arguments for this data config
- default = {'colors': <Value(False)>, 'cwd': <Value('.')>, 'dirblocklist': <Value(None)>, 'ignore_dotprefix': <Value(True)>, 'max_depth': <Value(None)>, 'max_files': <Value(100)>}
- class PintCLI(*args: Any, **kwargs: Any)[source]
Bases:
DataConfigConverts one type of unit to another via the pint library.
Valid options: []
- Parameters:
*args – positional arguments for this data config
**kwargs – keyword arguments for this data config
- default = {'input_expr': <Value(None)>, 'output_unit': <Value(None)>, 'precision': <Value(2)>}
- class PyfileCLI(*args: Any, **kwargs: Any)[source]
Bases:
DataConfigPrints the path corresponding to a Python module.
This uses the
ubelt.modname_to_modpathmechanism that does not require importing of your package.Alternatives
An alternative with no dependencies is to use the one-liner:
python -c “import <modname>; print(<modname>.__file__)”
Example Usage
xdev pyfile xdev xdev pyfile numpy
# Use this feature in scripts for developement to avoid referencing # machine-specific paths. MODPATH=$(xdev pyfile ubelt) echo “MODPATH = $MODPATH”
Valid options: []
- Parameters:
*args – positional arguments for this data config
**kwargs – keyword arguments for this data config
- default = {'modname': <Value(None)>}
- class PyVersionCLI(*args: Any, **kwargs: Any)
Bases:
DataConfigDetect and print the version of a Python module or package.
Note
Different backends may produce different results, especially for packages that are in development and were installed in development mode.
An alternative with no dependencies is to use the one-liner:
python -c “import <modname>; print(<modname>.__version__)”
xdev pyversion xdev xdev pyversion numpy
# Both the module name and the package name can be used. xdev pyversion cv2 xdev pyversion opencv-python-headless
# For more verbose information add the verbose flag xdev pyversion opencv-python-headless –verbose
xdev pyversion xdev –backend=import xdev pyversion xdev –backend=importlib
Valid options: []
- Parameters:
*args – positional arguments for this data config
**kwargs – keyword arguments for this data config
- default = {'backend': <Value('auto')>, 'modname': <Value(None)>, 'verbose': <Value(False)>}
- classmethod main(cmdline=False, **kwargs)
- class EditfileCLI(*args: Any, **kwargs: Any)[source]
Bases:
DataConfigOpens a file in your visual editor determined by the
VISUALenvironment variable.If
VISUALis unspecified it attempts to default to the first known existing editor.Example Usage
xdev edit xdev xdev edit numpy
Valid options: []
- Parameters:
*args – positional arguments for this data config
**kwargs – keyword arguments for this data config
- default = {'target': <Value(None)>}
- class FormatQuotesCLI(*args: Any, **kwargs: Any)[source]
Bases:
DataConfigUse single quotes for code and double quotes for docs.
This is useful for “fixing” quotations after running a code formater like black on a module.
Valid options: []
- Parameters:
*args – positional arguments for this data config
**kwargs – keyword arguments for this data config
- default = {'diff': <Value(True)>, 'path': <Value('')>, 'recursive': <Value(True)>, 'verbose': <Value(3)>, 'write': <Value(False)>}
- class FreshPyenvCLI(*args: Any, **kwargs: Any)[source]
Bases:
DataConfigCreate a fresh environment in a docker container to test a Python package.
SeeAlso
The generic freshpyenv.sh bash script also installed with this package.
Valid options: []
- Parameters:
*args – positional arguments for this data config
**kwargs – keyword arguments for this data config
- default = {'image': <Value('__default__')>}
- class DocstrStubgenCLI(*args: Any, **kwargs: Any)[source]
Bases:
DataConfigGenerate Typed Stubs from Docstrings (experimental)
Note
This is an experimental command and currently requires a specialized patch to mypy to work correctly.
Valid options: []
- Parameters:
*args – positional arguments for this data config
**kwargs – keyword arguments for this data config
- default = {'module': <Value(None)>}
- class AvailablePackageCLI(*args: Any, **kwargs: Any)[source]
Bases:
DataConfigPrint a table of available versions of a python package on Pypi
Refactor of ~/local/tools/supported_python_versions_pip.py to report the available versions of a python package that meet some critera
Valid options: []
- Parameters:
*args – positional arguments for this data config
**kwargs – keyword arguments for this data config
- default = {'package_name': <Value(None)>, 'refresh': <Value(False)>, 'request_min': <Value(None)>}
- class DirectoryStatsCLI(*args: Any, **kwargs: Any)
Bases:
DataConfigAnalysis for code in a repository
CommandLine
python ~/code/xdev/xdev/cli/repo_stats.py .
Valid options: []
- Parameters:
*args – positional arguments for this data config
**kwargs – keyword arguments for this data config
- classmethod _register_main(func)
- default = {'dpath': <Value('.')>, 'exclude_dnames': <Value(None)>, 'exclude_fnames': <Value(None)>, 'ignore_dotprefix': <Value(True)>, 'include_dnames': <Value(None)>, 'include_fnames': <Value(None)>, 'max_display_depth': <Value(None)>, 'max_files': <Value(None)>, 'max_walk_depth': <Value(None)>, 'parse_content': <Value(False)>, 'python': <Value(False)>, 'rust': <Value(False)>, 'verbose': <Value(0)>, 'version': <Value(False)>}
- main(**kwargs)
Example
>>> # xdoctest: +SKIP >>> cmdline = 0 >>> kwargs = dict(dpath='module:watch') >>> main(cmdline=cmdline, **kwargs)
- normalize()
- class RegexCLI(*args: Any, **kwargs: Any)[source]
Bases:
DataConfigQuery the regex builder for help on the command line. By default prints useful regex constructs I have a hard time remembering.
Valid options: []
- Parameters:
*args – positional arguments for this data config
**kwargs – keyword arguments for this data config
- default = {'backend': <Value('python')>}
- class CLIFormatterCLI(*args: Any, **kwargs: Any)
Bases:
DataConfigThe idea is that we can ingest a dictionary, argv list, or a command line string and convert between any of these formats.
Valid options: []
- Parameters:
*args – positional arguments for this data config
**kwargs – keyword arguments for this data config
- default = {'input': <Value(None)>, 'input_type': <Value('auto')>, 'output_type': <Value('all')>}
- classmethod main(cmdline=1, **kwargs)
Example
>>> # xdoctest: +SKIP >>> from cli_formatter import * # NOQA >>> cmdline = 0 >>> kwargs = dict() >>> cls = CLIFormatterCLI >>> cls.main(cmdline=cmdline, **kwargs)
- expand_import_star
alias of
ExpandImportStarCLI