Hound源代码搜索引擎的命令行客户端。
项目描述
pyhound 是Hound源代码搜索引擎的命令行客户端。它连接到Hound服务器。以下是一个绝对不是虚构的示例
$ pyhound frobulate devguide:tools/frob.rst:433:if you really have to frobulate things, be sure to footils:tests/test_frob.py:378: eventlog_api.log_business(obj, 'frobulated', obj) frobulator:src/frobulator/handler.py:47: error="Could not frobulate event.",
要求
pyhound 需要 Python 3,支持 >= 3.5 版本。
安装
pyhound 需要 Hound 服务器。有关详细信息,请参阅 Hound 文档。以下步骤假定您有一个正在监听的 Hound 服务器(例如,在 http://localhost:6080 上)。
要安装 pyhound,请使用 pip
pip install pyhound
功能
pyhound 致力于以 grep 的方式输出搜索结果,因此实现了一些(但绝不是全部)其选项。
pyhound 的主要功能是其 --help 参数。
usage: pyhound [-h] [--version] [--endpoint URL] [--repos REPOSITORY_LIST] [--exclude-repos REPOSITORY_LIST] [--path FILE_PATH_PATTERN] [-A NUM] [-B NUM] [-C NUM] [--color [WHEN]] [-i] [-n] [--line-max-length LINE_MAX_LENGTH] PATTERN A command-line client for Hound. positional arguments: PATTERN The regular expression to search. optional arguments: -h, --help show this help message and exit --version show program's version number and exit --endpoint URL Host and port of the Hound server. You may also set a HOUND_ENDPOINT environment variable. Default: http://localhost:6080/ --repos REPOSITORY_LIST A comma-separated list of repositories to search in. Default: all. --exclude-repos REPOSITORY_LIST A comma-separated list of repositories to exclude. --path FILE_PATH_PATTERN A pattern to match against the path of candidate files. -A NUM, --after-context NUM Print NUM lines of trailing context after matching lines. Cannot be used with -C. -B NUM, --before-context NUM Print NUM lines of leading context before matching lines. Cannot be used with -C. -C NUM, --context NUM Print NUM lines of output context. Cannot be used with -A or -B. --color [WHEN], --colour [WHEN] Surround the matched (non-empty) strings, file names, line numbers and separators (for fields and groups of context lines) with escape sequences to display them in color on the terminal. WHEN may be "never", "always" or "auto". -i, --ignore-case Ignore case distinctions in both the PATTERN and the input files. -n, --line-number Prefix each line of output with the 1-based line number within its input file. --line-max-length LINE_MAX_LENGTH If given, don't show matching lines if they are longer than requested.
局限性
目前,pyhound 试图通过一次对 Hound 服务器的请求来检索所有搜索结果。如果结果过多(目前:超过 5000 个),服务器可能会返回错误,pyhound 将友好地显示此错误。Hound 网页用户界面也有同样的限制,并以类似的方式失败(尽管它至少显示了前 20 个结果)。
pyhound 的未来版本可能将处理这种情况,并多次向 Hound 服务器发送请求。另一方面,显示超过 5000 个搜索结果的有用性似乎值得怀疑。
替代方案
除了网页用户界面外,Hound 还附带了一个命令行客户端。但它不提供类似 grep 的输出。源代码中有一个注释表明它可能有一天会出现,但这个注释已经存在了 4 年(截至 2019 年 7 月),因此它可能不会很快实现。
Doug Hellmann 于 2018 年 2 月发布了 Beagle(也是用 Python 编写的)。它似乎专注于支持多种(许多!)输出格式,包括类似 grep 的格式。我没有对其进行测试。
名称
我必须道歉。这是我第一次编写以“py”开头的 Python 包。我以为我还可以再抵抗几年。我真是太天真了…
致谢、贡献和许可证
首先,感谢 Hound 的开发者。 :)
pyhound 由 Polyconseil 的工作人员维护。Polyconseil。它在 GitHub 上托管,网址为 https://github.com/polyconseil/pyhound/。欢迎提出建议和补丁。
持续测试在 Travis CI 上运行。当前状态:
pyhound 在 3-clause BSD 许可证下发布,许可证的副本包含在源代码中。
项目详情
pyhound-1.0.0.tar.gz 的散列
算法 | 散列摘要 | |
---|---|---|
SHA256 | 5018887c27d97d90842673c193fab6e49eafed0a6664240817a23e0c44ea1f5e |
|
MD5 | 3f3d807ccda9379f8db921e3583a9667 |
|
BLAKE2b-256 | 8e0686d486324b50377940f67e8a7a800a7bb1a76272bb1a1c40a94c48bce8c2 |