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='', sub_clis=None, version=None)[source]¶
Bases:
ModalCLI
The XDEV CLI
A collection of excellent developer tools for excellent developers.
- class InfoCLI(*args, **kwargs)[source]¶
Bases:
DataConfig
Info about xdev
Valid options: []
- Parameters:
*args – positional arguments for this data config
**kwargs – keyword arguments for this data config
- default = {}¶
- class CodeblockCLI(*args, **kwargs)[source]¶
Bases:
DataConfig
Remove 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, **kwargs)[source]¶
Bases:
DataConfig
Search 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, **kwargs)[source]¶
Bases:
DataConfig
Find 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, **kwargs)[source]¶
Bases:
DataConfig
List a directory like a tree
See also
The
Example
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, **kwargs)[source]¶
Bases:
DataConfig
Converts one type of unit to another via the pint library.
Notes:
See also
The
,in-bash
,something
,we
,megabytes.
,Example
,-------------
,xdev
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(0)>}¶
- class PyfileCLI(*args, **kwargs)[source]¶
Bases:
DataConfig
Prints the path corresponding to a Python module.
This uses the
ubelt.modname_to_modpath
mechanism 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, **kwargs)[source]¶
Bases:
DataConfig
Detect 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
xdev pyversion xdev –backend=import xdev pyversion xdev –backend=pkg_resources
Valid options: []
- Parameters:
*args – positional arguments for this data config
**kwargs – keyword arguments for this data config
- default = {'backend': <Value('auto')>, 'modname': <Value(None)>}¶
- class EditfileCLI(*args, **kwargs)[source]¶
Bases:
DataConfig
Opens a file in your visual editor determined by the
VISUAL
environment variable.If
VISUAL
is 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, **kwargs)[source]¶
Bases:
DataConfig
Use 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, **kwargs)[source]¶
Bases:
DataConfig
Create 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, **kwargs)[source]¶
Bases:
DataConfig
Generate 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, **kwargs)[source]¶
Bases:
DataConfig
Print 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, **kwargs)¶
Bases:
DataConfig
Analysis 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(True)>, 'python': <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, **kwargs)[source]¶
Bases:
DataConfig
Query 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')>}¶