使用redbaron轻松搜索和操作python源代码的工具包。
baroness的Python项目详细描述
使用 雷德巴伦。
用法
搜索
您可以使用 命令线。默认情况下,baroness将搜索所有python文件 从当前目录递归地向下。搜索模式是 与redbaron一起工作的常规python代码。顶层节点是 叫做根。
例如,搜索值为bar的所有name节点:
baroness search 'root("name", value="bar")'
search是默认子命令,因此您可以使用以下命令编写相同的子命令:
baroness 'root("name", value="bar")'
有关完整用法,请查看baroness search --help:
usage: baroness search [-h] [--no-cache] [--parents PARENTS] [--no-color] [--no-linenos] pattern [files [files ...]] positional arguments: pattern Python redbaron code to search where `root` is the variable holding the tree files File names and/or glob pattern. Default to recursive search of python all files. optional arguments: -h, --help show this help message and exit --no-cache Do no use the cache in `.baroness` even if it exists --parents PARENTS Number of parents to go up on matched nodes. --no-color Do not color the output. --no-linenos Do not output the linenumbers.
缓存
对于大型代码来说,将python文件解析为baron fst可能非常耗时。 基地。baroness可以将baron fst缓存为json文件以节省时间 搜索。默认情况下,缓存未启用,但将在以下情况下使用 男爵夫人找到一个.baroness目录。
保存/初始化缓存
要启用缓存(并最初创建缓存),可以使用:
baroness cache save
有关完整用法,请查看baroness cache save --help:
usage: baroness cache save [-h] [--force] [FILE [FILE ...]] Save given files (all tree) to disk positional arguments: FILE Files to save to cache. optional arguments: -h, --help show this help message and exit --force Save over already existing cache files.
清除缓存
要递归删除所有.baroness目录,请使用:
baroness cache delete