Skip to main content

An excellent developer tool for excellent developers

Project description

Xdev - Excellent Developer

GithubActions Codecov Pypi Downloads ReadTheDocs

Xdev is an excellent developer tool for excellent developers. It contains miscellaneous and/or interactive debugging tools.

I mostly maintain this for myself, but I could see polishing it up in the future.

This is the CLI:

(pyenv3.11.2) joncrall@toothbrush:~$ xdev --help
usage: xdev [-h] [--version] {info,codeblock,sed,find,tree,pint,pyfile,pyversion,editfile,format_quotes,freshpyenv,docstubs,available_package_versions} ...

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}
                        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

This is the top level API:

from xdev import algo
from xdev import autojit
from xdev import class_reloader
from xdev import cli
from xdev import desktop_interaction
from xdev import embeding
from xdev import format_quotes
from xdev import interactive_iter
from xdev import introspect
from xdev import misc
from xdev import patterns
from xdev import profiler
from xdev import regex_builder
from xdev import search_replace
from xdev import tracebacks
from xdev import util
from xdev import util_networkx
from xdev import util_path

from xdev.algo import (edit_distance, knapsack, knapsack_greedy, knapsack_ilp,
                       knapsack_iterative, knapsack_iterative_int,
                       knapsack_iterative_numpy, number_of_decimals,)
from xdev.autojit import (import_module_from_pyx,)
from xdev.class_reloader import (reload_class,)
from xdev.desktop_interaction import (editfile, startfile, view_directory,)
from xdev.embeding import (EmbedOnException, embed, embed_if_requested,
                           embed_on_exception, embed_on_exception_context,
                           fix_embed_globals,)
from xdev.format_quotes import (DOUBLE_QUOTE, SINGLE_QUOTE,
                                TRIPLE_DOUBLE_QUOTE, TRIPLE_SINGLE_QUOTE,
                                format_quotes, format_quotes_in_file,
                                format_quotes_in_text,)
from xdev.interactive_iter import (InteractiveIter,)
from xdev.introspect import (distext, get_func_kwargs, get_stack_frame,
                             iter_object_tree, test_object_pickleability,)
from xdev.misc import (byte_str, difftext, nested_type, quantum_random,
                       set_overlaps, textfind, tree_repr,)
from xdev.patterns import (MultiPattern, Pattern, PatternBase, RE_Pattern,
                           our_extended_regex_compile,)
from xdev.profiler import (IS_PROFILING, profile, profile_globals,
                           profile_now,)
from xdev.regex_builder import (PythonRegexBuilder, RegexBuilder,
                                VimRegexBuilder,)
from xdev.search_replace import (GrepResult, find, grep, grepfile, greptext,
                                 sed, sedfile,)
from xdev.tracebacks import (make_warnings_print_tracebacks,)
from xdev.util import (bubbletext, conj_phrase, take_column,)
from xdev.util_networkx import (AsciiDirectedGlyphs, AsciiUndirectedGlyphs,
                                UtfDirectedGlyphs, UtfUndirectedGlyphs,
                                generate_network_text, graph_str,
                                write_network_text,)
from xdev.util_path import (ChDir, sidecar_glob, tree,)

Remarks

Perhaps I should just use ipdb but I often just like to directly embed with IPython whenever I want:

import xdev
xdev.embed()

Or wherever I want whenever there is an exception.

import xdev
with xdev.embed_on_exception:
    some_code()

I don’t feel like I need ipdb’s other features.

I also like to

def func(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 see xinspect for things like autogen_imports

>>> import ubelt as ub
>>> 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 CLI

The xdev CLI is getting kinda nice, although it is a bit of a hodgepodge of functionality (much like this library).

pip install xdev
xdev --help

It contains functionality that I generally use when developing on my setup, but I often find lacking in the setup of others.

For instance the tree UNIX command is amazing, but not everyone has it installed, and getting it via apt requires sudo privileges. Meanwhile xdev can be installed in user space via pip, so this provides me with an easy way to get tree on someone’s system while helping them debug.

Other examples are sed, find, pyfile, and pyversion. Look at the --help for more info on them.

The availpkg command 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 at availpkg. It also provides an overview of what versions of a package are available for what operating systems / CPU architectures.

The docstubs command 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xdev-1.3.3.tar.gz (89.3 kB view details)

Uploaded Source

Built Distribution

xdev-1.3.3-py3-none-any.whl (92.4 kB view details)

Uploaded Python 3

File details

Details for the file xdev-1.3.3.tar.gz.

File metadata

  • Download URL: xdev-1.3.3.tar.gz
  • Upload date:
  • Size: 89.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for xdev-1.3.3.tar.gz
Algorithm Hash digest
SHA256 541b51932b44c735cdd11ed42f9c0109bab6659baf6e3486af4887cfba0337f4
MD5 3e019473f3ad8ff173ccfca7a811e770
BLAKE2b-256 49a5e33ea0d206c92b2acc8ff620c2f5aabf59b9645ec2f11760cd720d2921a2

See more details on using hashes here.

File details

Details for the file xdev-1.3.3-py3-none-any.whl.

File metadata

  • Download URL: xdev-1.3.3-py3-none-any.whl
  • Upload date:
  • Size: 92.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for xdev-1.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4b5745b9017d33b1a4cb4152fc5ac917b89ef7d618197c8543838c3abfcd800c
MD5 66bf47b84fb1191157e1221bf099cc90
BLAKE2b-256 d0f40b49c7c30cef146e50c47898315b60c43c51b0e31a08a45d8721f300755e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page