跳转到主要内容

优秀的开发者工具,适用于优秀的开发者

项目描述

Xdev - 优秀的开发者

GithubActions Codecov Pypi Downloads ReadTheDocs

阅读文档

https://xdev.readthedocs.io

Github

https://github.com/Erotemic/xdev

Pypi

https://pypi.ac.cn/project/xdev

Xdev 是一款优秀的开发者工具,适用于优秀的开发者。它包含了一些杂项和/或交互式调试工具。

这最初是我自己的一个项目,用于包含我不想在包本身中发布的与开发相关的工具(而 ubelt 包含程序本身使用的工具)。多年来我对它进行了打磨,它已成为一个相当有用的包,其中包含了我看到其他人可能会使用到的工具。

这是 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 repository

这是顶层 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,)

备注

也许我应该只使用 ipdb,但当我想要直接与 IPython 集成时,我经常这样做

import xdev
xdev.embed()

或者在任何有异常的地方。

import xdev
with xdev.embed_on_exception:
    some_code()

我不觉得我需要 ipdb 的其他功能。

我还喜欢

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

但我知道这些事情有点脏。

但这不是生产实践。这些都是开发技巧和生活窍门,可以让工作更快。

还可以查看 xinspect 了解有关 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']

CLI

xdev 命令行界面越来越好了,尽管它的功能有点杂乱(就像这个库一样)。

pip install xdev
xdev --help

它包含了我通常在开发环境中使用的一些功能,但我在其他人的设置中经常发现这些功能缺失。

例如,UNIX 命令 tree 非常出色,但并非每个人都安装了它,而且通过 apt 安装需要 sudo 权限。与此同时,xdev 可以通过 pip 在用户空间中安装,因此这为我提供了一个简单的方法,在别人的系统上安装 tree 并帮助他们调试。

其他示例还包括 sedfindpyfilepyversion。查看 --help 以获取更多关于它们的信息。

dirstats 函数就像是一个增强版的 tree。除了打印目录树结构外,它还会检查树的内容并总结如下信息:每种类型文件中的行数。对于 Python 文件,它将分析拆分为代码行和文档字符串行,以便更好地了解项目复杂性。

为了维护仓库,我结合使用此包和 xcookie。我使用 xcookie 生成包结构,然后 xdev 帮助填充细节。特别是 availpkgdocstubs 命令。

availpkg 命令在编写 requirements.txt 文件时对我来说是必不可少的。如果您需要找到不同版本的 Python 中特定包(尤其是二进制包,例如 numpy)的良好版本,并希望为您生成适当的 requirements.txt 语法,请查看 availpkg。它还提供了关于哪些操作系统/ CPU 架构可用哪些版本的包的概述。

docstubs 命令旨在将 google-style 文档字符串转换为正确的类型注解存根。它“在我的机器上运行良好”,并且目前需要一个定制的 monkey-patched mypy。请参阅代码以获取详细信息,它可以使用,但仍非常原始。我认为它有可能发展成为工具。

项目详情


下载文件

下载适合您平台的文件。如果您不确定该选择哪个,请了解更多关于 安装包 的信息。

源分布

xdev-1.5.3.tar.gz (122.3 kB 查看哈希值)

上传时间

构建分布

xdev-1.5.3-py3-none-any.whl (127.2 kB 查看哈希值)

上传于 Python 3

由以下支持