joh*_*ohn 5 python documentation summary conda
conda包(可以)在其元数据中具有摘要和描述。我想以某种方式阅读那些使用conda, 来帮助决定要安装哪些软件包。然而,我能找到的最多信息来自conda search -i,例如
$ conda search -i optionsfactory
Loading channels: done
optionsfactory 1.0.3 py_0
-------------------------
file name : optionsfactory-1.0.3-py_0.tar.bz2
name : optionsfactory
version : 1.0.3
build : py_0
build number: 0
size : 22 KB
license : BSD-3-Clause
subdir : noarch
url : https://conda.anaconda.org/conda-forge/noarch/optionsfactory-1.0.3-py_0.tar.bz2
md5 : f8db4dd5600ad38b5f6ecae5f6f7d2ad
timestamp : 2020-05-13 08:04:25 UTC
dependencies:
- python >=3.6
Run Code Online (Sandbox Code Playgroud)
这对于了解该包的实际用途没有帮助。
这似乎是 中的一个错误conda。包含有关包功能的信息的字段info-*.tar.zst/about.json。summary
似乎conda search 只conda info <package_name>输出保存在缺少此信息的.json文件中所创建的信息。conda index
您可以手动加载包并自己提取这部分元数据,如下所示:
#!/usr/bin/env python3
# extract_summary.py Extract the summary of a conda file
# Note does not support the old .tar.bz2 conda files, change the zipfile below if need this
import json
import tarfile
import zipfile
import sys
from collections.abc import Iterable
from pathlib import Path
import zstandard # need to run pip install zstandard first
def get_conda_pkg_info_files(
conda_pkg_file: Path,
) -> Iterable[tuple[str, dict[str, bytes]]]:
"""Extract conda package info files from conda pkg file"""
with zipfile.ZipFile(conda_pkg_file, "r") as conda_file:
for level1_file in conda_file.namelist():
if level1_file.startswith("info") and level1_file.endswith(".tar.zst"):
with conda_file.open(level1_file) as f_level1:
unzstd = zstandard.ZstdDecompressor()
with unzstd.stream_reader(f_level1) as stream:
with tarfile.open(mode="r|", fileobj=stream) as tf:
yield level1_file, {
member.name: tf.extractfile(member).read()
for member in tf
if not member.isdir()
}
def extract_summary(conda_pkg_file: Path) -> None:
"""Print summary found in conda_pkg"""
for file, tar_file in get_conda_pkg_info_files(conda_pkg_file):
json_file = tar_file["info/about.json"]
summary = json.loads(json_file)["summary"]
print(f"{conda_pkg_file}: {file} {summary}")
if __name__ == "__main__":
extract_summary(Path(sys.argv[1]))
Run Code Online (Sandbox Code Playgroud)
要获取摘要,您需要首先下载结果中*.conda给出的内容,然后执行脚本:URLconda search -i
$ wget https://conda.anaconda.org/conda-forge/noarch/optionsfactory-1.0.11-pyhd8ed1ab_0.conda
$ ./extract_summary.py optionsfactory-1.0.11-pyhd8ed1ab_0.conda
optionsfactory-1.0.11-pyhd8ed1ab_0.conda: info-optionsfactory-1.0.11-pyhd8ed1ab_0.tar.zst Python package for handling user-provided options with flexible defaults, documentation and checking
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
882 次 |
| 最近记录: |