cscopy
cscopy 是一个 Cscope 的 Python 封装,旨在提供简单易用的接口来搜索 C 代码中的符号。它允许用户在一个临时的工作空间中对 C 代码进行索引和搜索,适合需要在不同项目或代码库中快速查找符号定义和引用的场景。
特性
- 临时工作空间:支持自动创建临时文件夹,将需要追踪的文件复制进这个文件夹,并在其中运行 Cscope。
- 简单的 API:提供了简单直观的 API 来搜索符号的定义、引用等。
安装
确保你的系统中已安装 Python 3 和 cscope。然后,使用 pip 或你喜欢的包管理器安装 cscopy:
pip install cscopy
# or
pdm add cscopy
快速开始
以下是一个简单的示例,展示了如何使用 cscopy 来搜索 C 代码中符号的定义:
from cscopy.cli import CscopeCLI
from cscopy.model import SearchType
from cscopy.workspace import CscopeWorkspace
# 初始化 CscopeCLI
cli = CscopeCLI(path="/usr/bin/cscope")
# 创建一个 CscopeWorkspace 实例
with CscopeWorkspace(files=["c_code/exit.c"], cli=cli) as workspace:
print(workspace.tempdir_path)
# 搜索符号 "exit" 的定义
res = workspace.search(mode=SearchType.C_SYMBOL, symbol="exit")
# equals to
# res = workspace.search_c_symbol("exit")
# 打印搜索结果
for r in res:
print(r.line, r.parent)
License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for cscopy 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| cscopy-0.0.3.tar.gz | 4.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cscopy-0.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.5 kB
Release files / cscopy-0.0.3.tar.gz
| Download URL | cscopy-0.0.3.tar.gz |
|---|---|
| Size | 4.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a9394c776d4f1c04ef6a17ca87faec8ed3f538e13c88128f05e7bba600ad4e50
|
|
BLAKE2b-256 checksum How to use checksums |
d36b5e2d1cf59b7e08fef59ffdc0a150a746ad21f028f9dbefecfef0c809adf3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.19.1 CPython/3.10.12 Linux/6.4.0-060400rc1-generic
|
Release files / cscopy-0.0.3-py3-none-any.whl
| Download URL | cscopy-0.0.3-py3-none-any.whl |
|---|---|
| Size | 5.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
abed5ffcf8b4d8cd26dc85f680e8918950b395ddbb1ee855a4fae8a8e16a6711
|
|
BLAKE2b-256 checksum How to use checksums |
640db0db830553da1f6b7c99c9cd116bb8028aa71ea62a2f2af8c8c5a7e39a82
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.19.1 CPython/3.10.12 Linux/6.4.0-060400rc1-generic
|