Skip to main content

srcml_caller, simple python bindings for srcML

Project description

srcml_caller

Simple python bindings for srcML.

Provides:

from typing import Optional
import enum


class CodeLanguage(enum.Enum):
    c = enum.auto()            # (= 0)
    c_sharp = enum.auto()      # (= 1)
    c_plus_plus = enum.auto()  # (= 2)
    java = enum.auto()         # (= 3)
    objective_c = enum.auto()  # (= 4)


def to_code(
        xml_str: str,
        encoding_src: str = "utf-8",
        encoding_xml: str = "utf-8"
) -> Optional[str]:
    pass


def to_srcml(
        code: str,
        language: CodeLanguage,
        include_positions: bool = True,
        encoding_src: str = "utf-8",
        encoding_xml: str = "utf-8"
) -> Optional[str]:
    pass


def cpp_to_srcml(
        code: str,
        include_positions: bool = True,
        encoding_src: str = "utf-8",
        encoding_xml: str = "utf-8"
) -> Optional[str]:
    pass

Example usage

>>> import srcml_caller
>>> srcml_caller.to_srcml("void foo(int v);", srcml_caller.CodeLanguage.c_plus_cplus)

'<unit revision="1.0.0" language="C++" pos:tabs="8"><function_decl pos:start="1:1" pos:end="1:16"><type pos:start="1:1" pos:end="1:4"><name pos:start="1:1" pos:end="1:4">void</name></type> <name pos:start="1:6" pos:end="1:8">foo</name><parameter_list pos:start="1:9" pos:end="1:15">(<parameter pos:start="1:10" pos:end="1:14"><decl pos:start="1:10" pos:end="1:14"><type pos:start="1:10" pos:end="1:12"><name pos:start="1:10" pos:end="1:12">int</name></type> <name pos:start="1:14" pos:end="1:14">v</name></decl></parameter>)</parameter_list>;</function_decl></unit>'

Install instructions (from pypi)

pip install -v srcml_caller

Install instructions (from source)'

git clone https://github.com/pthom/srcml_caller.git
cd srcml_caller
git submodule update --init # will fetch srcML submodule
pip install -v .

Note: on windows, you need to first install libxml2 and libxslt with vcpkg, see below:

# inside the srcml_caller directory:
git clone https://github.com/Microsoft/vcpkg.git
.\vcpkg\bootstrap-vcpkg.bat
.\vcpkg\vcpkg install libxml2:x64-windows-static libxslt:x64-windows-static                                
.\vcpkg\vcpkg install libxml2:x86-windows-static libxslt:x86-windows-static

Development build instructions

Install requirements

Linux

Download and install a newer binary version of cmake (cmake 3.24 is required)

For example:

# This is where cmake will be put
MY_BIN_DIR=~/bin

# (select your arch below)
CMAKE_BIN_URL=https://cmake.org/files/v3.25/cmake-3.25.0-linux-x86_64.tar.gz
# CMAKE_BIN_URL=https://cmake.org/files/v3.25/cmake-3.25.0-linux-aarch64.tar.gz
curl -L $CMAKE_BIN_URL  > cmake_new.tgz
tar xvfz cmake_new.tgz
rm cmake_new.tgz
echo "export PATH=$MY_BIN_DIR/cmake-3.25.0-linux-aarch64/bin:$PATH" >> ~/.bashrc
echo "export PATH=$MY_BIN_DIR/cmake-3.25.0-linux-aarch64/bin:$PATH" >> ~/.zshrc

Install requirements

Follow instructions on srcML repo: https://github.com/srcML/srcML/blob/master/BUILD.md

Install requirements for Ubuntu

From https://github.com/srcML/Docker/blob/ubuntu_latest/base/Dockerfile

sudo apt-get update && sudo apt-get install --no-install-recommends -y \
    curl \
    zip \
    g++ \
    make \
    ninja-build \
    libxml2-dev \
    libxml2-utils \
    libxslt1-dev \
    libarchive-dev \
    libssl-dev \
    libcurl4-openssl-dev \
    cpio \
    man \
    file \
    dpkg-dev

You can also run ci_scripts/install_requirements_ubuntu.sh, which does exactly this.

Build

git submodule update --init

Unix and MacOS

python3 -m venv venv
source venv/bin/activate
pip install pybind11
mkdir build
cd build
cmake .. -DPYTHON_EXECUTABLE=../venv/bin/python

Windows

Please clone vcpkg in the same directory as this project, then install libxml2 and libxslt like this:

git clone https://github.com/Microsoft/vcpkg.git
.\vcpkg\bootstrap-vcpkg.bat
.\vcpkg\vcpkg install libxml2:x64-windows-static libxslt:x64-windows-static                                
.\vcpkg\vcpkg install libxml2:x86-windows-static libxslt:x86-windows-static
python3 -m venv venv
venv\Scripts\activate
pip install pybind11
mkdir build
cd build
cmake .. -DPYTHON_EXECUTABLE=c:\FULL\PATH\TO\venv\Scripts\python.exe

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

srcml-caller-0.3.0.tar.gz (603.7 kB view details)

Uploaded Source

Built Distributions

srcml_caller-0.3.0-cp312-cp312-win_amd64.whl (6.0 MB view details)

Uploaded CPython 3.12 Windows x86-64

srcml_caller-0.3.0-cp312-cp312-musllinux_1_1_x86_64.whl (4.8 MB view details)

Uploaded CPython 3.12 musllinux: musl 1.1+ x86-64

srcml_caller-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.3 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

srcml_caller-0.3.0-cp312-cp312-macosx_11_0_arm64.whl (4.8 MB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

srcml_caller-0.3.0-cp311-cp311-win_amd64.whl (6.0 MB view details)

Uploaded CPython 3.11 Windows x86-64

srcml_caller-0.3.0-cp311-cp311-musllinux_1_1_x86_64.whl (4.8 MB view details)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

srcml_caller-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.3 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

srcml_caller-0.3.0-cp311-cp311-macosx_11_0_arm64.whl (4.8 MB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

srcml_caller-0.3.0-cp310-cp310-win_amd64.whl (6.0 MB view details)

Uploaded CPython 3.10 Windows x86-64

srcml_caller-0.3.0-cp310-cp310-musllinux_1_1_x86_64.whl (4.8 MB view details)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

srcml_caller-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.3 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

srcml_caller-0.3.0-cp310-cp310-macosx_11_0_arm64.whl (4.8 MB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

File details

Details for the file srcml-caller-0.3.0.tar.gz.

File metadata

  • Download URL: srcml-caller-0.3.0.tar.gz
  • Upload date:
  • Size: 603.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for srcml-caller-0.3.0.tar.gz
Algorithm Hash digest
SHA256 2c3ed9bd540b50b2d41a92fc3f3b8fbcc81a1194f0e73d3f40d085aa8ac8da9f
MD5 e558c3884624fa741fd5beff8d307fd9
BLAKE2b-256 51a55b79424e1055aa84148e7b32ca7bf9dcf2aa0dfb06e1133e15f346ab49d6

See more details on using hashes here.

File details

Details for the file srcml_caller-0.3.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for srcml_caller-0.3.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 38e5e1845c9299280cd70c9afe48150b22f0af7b3a4bc597dd8b28a7eec4f322
MD5 7aae82a7a5afec9edfca41d3499e6cc3
BLAKE2b-256 5d435c85746d6136150deccedefb1fd93facb4aca49d1728f19c36cfd68d74b6

See more details on using hashes here.

File details

Details for the file srcml_caller-0.3.0-cp312-cp312-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for srcml_caller-0.3.0-cp312-cp312-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 1b35dc0c8e9a11edb348e617524628fcf0b3c28b9e5577ed3b4aa183f79d1785
MD5 7fccb51d4c1a8fe4f0282b4dc8b90c5f
BLAKE2b-256 397d8cfb758c4f7091c8aeaab1bb578c9db94bfb0626c79d4062020425b346ee

See more details on using hashes here.

File details

Details for the file srcml_caller-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for srcml_caller-0.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 579cfad04891dc4b723a8d2bf16195e6bb17a07a126ec3367104e3132b53786b
MD5 3112bf8d76533e93faa97570c4746760
BLAKE2b-256 1d89d4856e12e3d070fa1ae4a8cdc32b04ca8680a21e2c14f37aa7a6590823ce

See more details on using hashes here.

File details

Details for the file srcml_caller-0.3.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for srcml_caller-0.3.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 58c3449ef15905379db5df923d1147cfa5a105452c4d483ee4166b93fccea5b8
MD5 71142bf3775043b25ef944918b8c1b20
BLAKE2b-256 7e55de0d4d235ae7ba85a5f6f2702906819520960c648b61edd30379fbdd8163

See more details on using hashes here.

File details

Details for the file srcml_caller-0.3.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for srcml_caller-0.3.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 fdac7ac38abe5a8a846583e679a47cf976cdefaad0de9fd76b7ee3aa77fb3bad
MD5 824ae5b00061eb812bd8420ca91349cd
BLAKE2b-256 b4e9b5f9c9e5cb419dd6ea2a7e092e1db2d682803b0ccfd43e14defe87f8c271

See more details on using hashes here.

File details

Details for the file srcml_caller-0.3.0-cp311-cp311-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for srcml_caller-0.3.0-cp311-cp311-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 fe45c57dc3df032705e9218ce5a1d3ccb45f8112af99acbc2de46cf353724731
MD5 bb59fa5003dabeb75b2340cc67c4d11e
BLAKE2b-256 b438785497a412006392f87d91189dc19ab898da44dbf415334bb500f1d8d5e9

See more details on using hashes here.

File details

Details for the file srcml_caller-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for srcml_caller-0.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1b328148bb24f7a9500304b19acfcc57209d843ae29b690b8ac4e653d52a4d70
MD5 48ca2dd047db7a7a10498d1fd6dccb20
BLAKE2b-256 86dc944199b8c857ab0b945dd30a48515602d0123a33a6e2b55f2dbff4ef02b3

See more details on using hashes here.

File details

Details for the file srcml_caller-0.3.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for srcml_caller-0.3.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 920b2ada580e86a051606a7144e98f03227c52cb8772f994d46615489658bb8d
MD5 6186151ada0c07e2e3a11b64297afd7f
BLAKE2b-256 a0c5a6b0fd5e1d8bc74164663b1fb30702e5bde5b1a12692b00a4fb79a77b810

See more details on using hashes here.

File details

Details for the file srcml_caller-0.3.0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for srcml_caller-0.3.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 90fc8cab49880b5007f41e18094a570c9e882cdb934ce901b1cfbc06ad90d1c6
MD5 1dca297ca83d7dca929b5ee7689d726d
BLAKE2b-256 17c5a62a8d63fed578be5e0b7ba2b60a0e7083d4a525fb080ce9aca4d5ab1a57

See more details on using hashes here.

File details

Details for the file srcml_caller-0.3.0-cp310-cp310-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for srcml_caller-0.3.0-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 a04199dfd7bd7516eb81a4c2d8bf5f27a430d0455e15aedee593b4a99045b5a1
MD5 b841323cbe39a80607169b422f992dbb
BLAKE2b-256 14aed34fe0c5875bc5b4f10d3183def031f9ff3dc2f9c6ab5901124b7fd78680

See more details on using hashes here.

File details

Details for the file srcml_caller-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for srcml_caller-0.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d326120540205e02f43f9f67295aa3b4ae3389223e8ccb98d6faef5ff16cce82
MD5 5f50827a6471074342e5aa401c9c2c02
BLAKE2b-256 0370ad7129336dfb870bf7a7f9bb88a1da16af8ce3820fe967336bfd242ded3d

See more details on using hashes here.

File details

Details for the file srcml_caller-0.3.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for srcml_caller-0.3.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d562f9955dc1e5851aa0564bd292b3675340dcb8f9ec0995ce57189b9dd6866e
MD5 ba1a334fbcb8eeb5d3008422ef28e1e7
BLAKE2b-256 503837f205f05918c0f2c8ca8d5e710e2bbd8f76596ad137ec23b7df557aadb8

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