Python binding for cscopy
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cscopy-0.0.3.tar.gz.
File metadata
- Download URL: cscopy-0.0.3.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.19.1 CPython/3.10.12 Linux/6.4.0-060400rc1-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9394c776d4f1c04ef6a17ca87faec8ed3f538e13c88128f05e7bba600ad4e50
|
|
| MD5 |
0c5ddec5f9b0e98081b05005126d3fa8
|
|
| BLAKE2b-256 |
d36b5e2d1cf59b7e08fef59ffdc0a150a746ad21f028f9dbefecfef0c809adf3
|
File details
Details for the file cscopy-0.0.3-py3-none-any.whl.
File metadata
- Download URL: cscopy-0.0.3-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.19.1 CPython/3.10.12 Linux/6.4.0-060400rc1-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
abed5ffcf8b4d8cd26dc85f680e8918950b395ddbb1ee855a4fae8a8e16a6711
|
|
| MD5 |
257e4728c3299c5751cd941d796da234
|
|
| BLAKE2b-256 |
640db0db830553da1f6b7c99c9cd116bb8028aa71ea62a2f2af8c8c5a7e39a82
|