Package: xdev
Xdev - Excellent DeveloperRead the docshttps://xdev.readthedocs.ioGithubhttps://github.com/Erotemic/xdevPypihttps://pypi.org/project/xdevXdev is an excellent developer tool for excellent developers.
It contains miscellaneous and/or interactive debugging tools.This started as a project for myself to contain development related tools that
I wouldn’t want to ship with a package itself (where asubeltcontains the tools used in programs
themselves). I’ve polished it up over the years, and it’s become a reasonably
useful package with tools I could see others making use of.This is the CLI:usage: xdev [-h] [--version] {info,codeblock,sed,find,tree,pint,pyfile,pyversion,editfile,format_quotes,freshpyenv,docstubs,available_package_versions,dirstats} ...

The XDEV CLI

A collection of excellent developer tools for excellent developers.

options:
  -h, --help            show this help message and exit
  --version             show version number and exit (default: False)

commands:
  {info,codeblock,sed,find,tree,pint,pyfile,pyversion,editfile,format_quotes,freshpyenv,docstubs,available_package_versions,dirstats}
                        specify a command to run
    info                Info about xdev
    codeblock           Remove indentation from text.
    sed                 Search and replace text in files
    find                Find matching files or paths in a directory.
    tree                List a directory like a tree
    pint (convert_unit)
                        Converts one type of unit to another via the pint library.
    pyfile (modpath)    Prints the path corresponding to a Python module.
    pyversion (modversion)
                        Detect and print the version of a Python module or package.
    editfile (edit)     Opens a file in your visual editor determined by the ``VISUAL``
    format_quotes       Use single quotes for code and double quotes for docs.
    freshpyenv          Create a fresh environment in a docker container to test a Python package.
    docstubs (doctypes)
                        Generate Typed Stubs from Docstrings (experimental)
    available_package_versions (availpkg)
                        Print a table of available versions of a python package on Pypi
    dirstats            Analysis for code in a repositoryThis is the top level API:fromxdevimportalgofromxdevimportautojitfromxdevimportclass_reloaderfromxdevimportclifromxdevimportdesktop_interactionfromxdevimportembedingfromxdevimportformat_quotesfromxdevimportinteractive_iterfromxdevimportintrospectfromxdevimportmiscfromxdevimportpatternsfromxdevimportprofilerfromxdevimportregex_builderfromxdevimportsearch_replacefromxdevimporttracebacksfromxdevimportutilfromxdevimportutil_networkxfromxdevimportutil_pathfromxdev.algoimport(edit_distance,knapsack,knapsack_greedy,knapsack_ilp,knapsack_iterative,knapsack_iterative_int,knapsack_iterative_numpy,number_of_decimals,)fromxdev.autojitimport(import_module_from_pyx,)fromxdev.class_reloaderimport(reload_class,)fromxdev.desktop_interactionimport(editfile,startfile,view_directory,)fromxdev.embedingimport(EmbedOnException,embed,embed_if_requested,embed_on_exception,embed_on_exception_context,fix_embed_globals,)fromxdev.format_quotesimport(DOUBLE_QUOTE,SINGLE_QUOTE,TRIPLE_DOUBLE_QUOTE,TRIPLE_SINGLE_QUOTE,format_quotes,format_quotes_in_file,format_quotes_in_text,)fromxdev.interactive_iterimport(InteractiveIter,)fromxdev.introspectimport(distext,get_func_kwargs,get_stack_frame,iter_object_tree,test_object_pickleability,)fromxdev.miscimport(byte_str,difftext,nested_type,quantum_random,set_overlaps,textfind,tree_repr,)fromxdev.patternsimport(MultiPattern,Pattern,PatternBase,RE_Pattern,our_extended_regex_compile,)fromxdev.profilerimport(IS_PROFILING,profile,profile_globals,profile_now,)fromxdev.regex_builderimport(PythonRegexBuilder,RegexBuilder,VimRegexBuilder,)fromxdev.search_replaceimport(GrepResult,find,grep,grepfile,greptext,sed,sedfile,)fromxdev.tracebacksimport(make_warnings_print_tracebacks,)fromxdev.utilimport(bubbletext,conj_phrase,take_column,)fromxdev.util_networkximport(AsciiDirectedGlyphs,AsciiUndirectedGlyphs,UtfDirectedGlyphs,UtfUndirectedGlyphs,generate_network_text,graph_str,write_network_text,)fromxdev.util_pathimport(ChDir,sidecar_glob,tree,)RemarksPerhaps I should just useipdbbut I often just like to directly embed with
IPython whenever I want:importxdevxdev.embed()Or wherever I want whenever there is an exception.importxdevwithxdev.embed_on_exception:some_code()I don’t feel like I needipdb’s other features.I also like todeffunc(a=1,b=2,c=3):"""
    Example:
        >>> from this.module import *  # import contextual namespace
        >>> import xinspect
        >>> globals().update(xinspect.get_func_kwargs(func))  # populates globals with default kwarg value
        >>> print(a + b + c)
        6
    """But I know these things are a little dirty.But these aren’t production practices. These are development tricks and life
hacks to make working faster.Also seexinspectfor things likeautogen_imports>>>importubeltasub>>>source=ub.codeblock(>>>'''
>>>     p = os.path.dirname(join('a', 'b'))
>>>     glob.glob(p)
>>>     ''')>>># Generate a list of lines to fix the name errors>>>lines=autogen_imports(source=source)>>>print(lines)['import glob','from os.path import join','import os']The CLIThe xdev CLI is getting kinda nice, although it is a bit of a hodgepodge of
functionality (much like this library).pip install xdev
xdev --helpIt contains functionality that I generally use when developing on my setup, but
I often find lacking in the setup of others.For instance thetreeUNIX
command is amazing, but not everyone has it installed, and getting it viaaptrequires sudo privileges. Meanwhile xdev can be installed in user space
via pip, so this provides me with an easy way to gettreeon someone’s
system while helping them debug.Other examples aresed,find,pyfile, andpyversion. Look at
the--helpfor more info on them.Thedirstatsfunction is like a buffed uptree. In addition to printing
the directory tree structure it inspects the contents of the tree and
summarizes things like: number of lines per type of file. For Python files it
breaks up the analysis into code-lines and docstring lines to give a better
sense of project complexity.For repo maintence I use this package in conjunction withxcookie. I use xcookie to generate the package
structure and then xdev helps fill in the details. Specifically theavailpkganddocstubscommands.Theavailpkgcommand has been indispensable for me when writing
requirements.txt files. If you need to find good versions of a package —
especially a binary one, e.g. numpy — for different versions of Python and
would like the appropirate requirements.txt syntax to be generated for you,
take a look atavailpkg. It also provides an overview of what versions of a
package are available for what operating systems / CPU architectures.Thedocstubscommand is designed to turn google-style docstrings into
proper type annotation stubs.  It “works on my machine” and currently requires
a custom monkey patched mypy. See the code for details, it is possible to use,
but it is still very raw. I do think it can evolve into a tool.