Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cscopy-0.0.3.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

cscopy-0.0.3-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

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

Hashes for cscopy-0.0.3.tar.gz
Algorithm Hash digest
SHA256 a9394c776d4f1c04ef6a17ca87faec8ed3f538e13c88128f05e7bba600ad4e50
MD5 0c5ddec5f9b0e98081b05005126d3fa8
BLAKE2b-256 d36b5e2d1cf59b7e08fef59ffdc0a150a746ad21f028f9dbefecfef0c809adf3

See more details on using hashes here.

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

Hashes for cscopy-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 abed5ffcf8b4d8cd26dc85f680e8918950b395ddbb1ee855a4fae8a8e16a6711
MD5 257e4728c3299c5751cd941d796da234
BLAKE2b-256 640db0db830553da1f6b7c99c9cd116bb8028aa71ea62a2f2af8c8c5a7e39a82

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page