在当前目录或最近的父目录中查找与给定模式匹配的第一个文件。
项目描述
# python-findup
## 简介
在当前工作目录(或指定目录)或最近的父目录中查找与给定模式匹配的第一个路径。该项目大致是 [node-findup-sync](https://github.com/cowboy/node-findup-sync) 的 Python 版本。
为什么?例如,git 这样的应用程序通常会在当前目录或父目录中找到项目配置文件。`findup` 模块允许应用程序作者轻松地找到这些文件或目录。
## 安装
安装的最佳方式可能是使用 pip
pip install findup
或者您可以从 GitHub 克隆并安装 findup
git clone https://github.com/todddeluca/python-findup.git cd python-findup python setup.py install
## 使用
pattern 与当前工作目录或父目录结合,并传递给 glob.glob 以查看模式是否匹配。如果匹配,则返回第一个匹配项。模式可以包含一些shell通配符,如 ? 和 *。有关更多详细信息,请参阅 Python glob 模块。
findup.glob(pattern)
当当前工作目录位于 git 仓库内时,查找 git 仓库的根目录
os.path.dirname(findup.glob(‘.git’))
或更稳健地,处理 cwd 不在 git 仓库中的情况
路径 = findup.glob(‘.git’) git_root = None if 路径 is None or os.path.dirname(路径)
项目详细信息
关闭
findup-0.3.0.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 852a4b8d5697eeabeb16dfb886178cf88b6f093d1b4f934d450a8226487fc018 |
|
MD5 | 4e988ab3882e03803542e8d93f37b43c |
|
BLAKE2b-256 | 9a02dcb111bd9cf9a316a24119b18f9e462cbf7484988c35a45fca2b8e50d781 |