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_plus)

'<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 libiconv:x64-windows-static
.\vcpkg\vcpkg install libxml2:x86-windows-static libxslt:x86-windows-static libiconv: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 libiconv:x64-windows-static
.\vcpkg\vcpkg install libxml2:x86-windows-static libxslt:x86-windows-static libiconv: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.5.0.tar.gz (727.3 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

srcml_caller-0.5.0-cp314-cp314-win_amd64.whl (6.6 MB view details)

Uploaded CPython 3.14Windows x86-64

srcml_caller-0.5.0-cp314-cp314-musllinux_1_2_x86_64.whl (5.9 MB view details)

Uploaded CPython 3.14musllinux: musl 1.2+ x86-64

srcml_caller-0.5.0-cp314-cp314-manylinux_2_28_x86_64.whl (5.5 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ x86-64

srcml_caller-0.5.0-cp314-cp314-macosx_11_0_arm64.whl (5.1 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

srcml_caller-0.5.0-cp313-cp313-win_amd64.whl (6.5 MB view details)

Uploaded CPython 3.13Windows x86-64

srcml_caller-0.5.0-cp313-cp313-musllinux_1_2_x86_64.whl (5.9 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

srcml_caller-0.5.0-cp313-cp313-manylinux_2_28_x86_64.whl (5.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

srcml_caller-0.5.0-cp313-cp313-macosx_11_0_arm64.whl (5.1 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

srcml_caller-0.5.0-cp312-cp312-win_amd64.whl (6.5 MB view details)

Uploaded CPython 3.12Windows x86-64

srcml_caller-0.5.0-cp312-cp312-musllinux_1_2_x86_64.whl (5.9 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

srcml_caller-0.5.0-cp312-cp312-manylinux_2_28_x86_64.whl (5.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

srcml_caller-0.5.0-cp312-cp312-macosx_11_0_arm64.whl (5.1 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

srcml_caller-0.5.0-cp311-cp311-win_amd64.whl (6.5 MB view details)

Uploaded CPython 3.11Windows x86-64

srcml_caller-0.5.0-cp311-cp311-musllinux_1_2_x86_64.whl (5.9 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

srcml_caller-0.5.0-cp311-cp311-manylinux_2_28_x86_64.whl (5.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

srcml_caller-0.5.0-cp311-cp311-macosx_11_0_arm64.whl (5.1 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

Details for the file srcml_caller-0.5.0.tar.gz.

File metadata

  • Download URL: srcml_caller-0.5.0.tar.gz
  • Upload date:
  • Size: 727.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for srcml_caller-0.5.0.tar.gz
Algorithm Hash digest
SHA256 f45c91384fc2595b49e27f853eea93dbd4a8c40400577e12292aaad97940d877
MD5 f5d440d9b8495f99b05fe8e212641250
BLAKE2b-256 7874611253f5f08b8d594d1b87199ef635a43a4ebebe9764b2ee2820755d685c

See more details on using hashes here.

File details

Details for the file srcml_caller-0.5.0-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for srcml_caller-0.5.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 76e12c9243f6afb51e6984581cdb6177c205c0ca85f66aa7cce1e2b9589ec2c1
MD5 27c4ab9ec1396dcf8f6b0f14dc5a84f9
BLAKE2b-256 487455e30643b289d50186a99d9e644d27185e368820e76136a53e25e74050b5

See more details on using hashes here.

File details

Details for the file srcml_caller-0.5.0-cp314-cp314-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for srcml_caller-0.5.0-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 6ca74314080524f7a22c66cc89b7f07bcde25b935a9ddbdef00611a5f946b25e
MD5 5f610658df0389ae8842bd0df9defc1c
BLAKE2b-256 92f4f391a941d0de6836f2857d75b533a977d56849cf1b12e2cc2402de94ebdc

See more details on using hashes here.

File details

Details for the file srcml_caller-0.5.0-cp314-cp314-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for srcml_caller-0.5.0-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 26077a43303840a1d63d6673f07fe364334597591a59f65e93b20dad5454fba3
MD5 e16118708e202aea8948e5e52f0a0125
BLAKE2b-256 fd66b5b8f93b3ecb3c6ba3abe5d0be89af34576407975dc03123134b8a3cb9ed

See more details on using hashes here.

File details

Details for the file srcml_caller-0.5.0-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for srcml_caller-0.5.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f392c3360f44a3a58c464894696d086ec399ccc37187ed699c568faa6c7afd07
MD5 e299520188451a5f62b4b1a02dd2958d
BLAKE2b-256 2ca5c7029656cf97786f1793c87ce0353266ab409f6cc511947390789ca66e90

See more details on using hashes here.

File details

Details for the file srcml_caller-0.5.0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for srcml_caller-0.5.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 c3754650f894c4247f51ca4437910b6131af63bc4de72a61c38467f04c1bdf89
MD5 9cedbf85b01c074133a186f41064e561
BLAKE2b-256 1eda34b73fa4437cce68ce9491cc4dba0b3bcb683c1a4521cbc9e7e523130006

See more details on using hashes here.

File details

Details for the file srcml_caller-0.5.0-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for srcml_caller-0.5.0-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d449ca2f41d77f49c36e4181c6038b4dfa01b73dc270a9b41e316fa9ba49d6c6
MD5 13881e9a376e6696ace753dbc8b45eab
BLAKE2b-256 e71cbeb1f92fd90446b7e85eef14a9ef01b274734edd2c090d0f39eecaf5cd58

See more details on using hashes here.

File details

Details for the file srcml_caller-0.5.0-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for srcml_caller-0.5.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b75894de3e083cffe858c8cb124bd647b13bd69e39c719d41b02f7818a8400aa
MD5 e0f9d4e13073c5d7f891b9dacbec1503
BLAKE2b-256 069f9b1450705b241a00b75cbdc0611b744eb255b1f36d14d6071b97210a3138

See more details on using hashes here.

File details

Details for the file srcml_caller-0.5.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for srcml_caller-0.5.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bde0d754b13c12108e1710ca890e1546e1ed1b83ae251421958705ebad9c23ea
MD5 a20284a46f9479330c12d154cd224799
BLAKE2b-256 3ff31dea50e8f9f065a3ca327243f410845eadd1ed3afeda7515deb91b932989

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for srcml_caller-0.5.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 e36f9d5c69f41fe2d0a01b767486f3692d4bdda47bff1f69d66ace19cf1ddf68
MD5 4403077e110736c5e23993b5bd8809d3
BLAKE2b-256 f9d64becd7e9fe5b0c87267fb3d2a0c20dab77294d66c3a0b3425e82883a9a9a

See more details on using hashes here.

File details

Details for the file srcml_caller-0.5.0-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for srcml_caller-0.5.0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 a59b8d606c3f5a24439013ff399c2215281b81137acefe70633b94e53db232bf
MD5 c77d11b10be6e177892ba1c5edc0f6fd
BLAKE2b-256 ff1826e48fd53e1319eeadd7f81cffc4b5352d7612435dd30aeee50257bde7a1

See more details on using hashes here.

File details

Details for the file srcml_caller-0.5.0-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for srcml_caller-0.5.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 33d22351121686f66bc00a07df82b5851e6bcff3800868bcf38ff142fbca2cdb
MD5 e847503f24c8829081182ca06189e8d2
BLAKE2b-256 7eb5e62829e0754547f28417e3dbeeb5603de8dfb89d08fb931116c0b53bf6c4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for srcml_caller-0.5.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 626f39bcb8dfd12bacca8ca7534c0681822fa445c712dacfcdc7648ea7da273f
MD5 c40387be4655c74f8ffc39a5d065da03
BLAKE2b-256 956ae30fa832223d812ef96dddd7166b4bc7b21d8b1ed02d192043f2ffede024

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for srcml_caller-0.5.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 64ea972a099b7aa4acc1fd91eea9d124aecf28409aa2b8c31ba7ad3ab9593b61
MD5 aeb816722f833f0ad509fd9da8125128
BLAKE2b-256 8437e4b731f81deda6fb7b2a97d841a0ab5111c4c186ee31089c902226a19422

See more details on using hashes here.

File details

Details for the file srcml_caller-0.5.0-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for srcml_caller-0.5.0-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c23fbb112fa8ab4468dcf17440a25677da2eaf46e8672619c10a3750d62e3e1b
MD5 69f2f044c348aa6fff08b9871f067190
BLAKE2b-256 cdb7f8a9b77d647b861d343c5959d88d57707c15107391264e7aee49fa749384

See more details on using hashes here.

File details

Details for the file srcml_caller-0.5.0-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for srcml_caller-0.5.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 55737b2335b2c5bcb9c6a32e980c7f2615777ffb03af28c8211482b96c386d6e
MD5 1d9aef6018b891404d331f54e5406247
BLAKE2b-256 5bf8af371757af799ab5fa33502566a25d34d28ff1cb83283d97aec6e2ea9680

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for srcml_caller-0.5.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2ab4ca4780d0ea7a23e19e61ea3d30b12fd2c7a8965af69789009059c5eb917b
MD5 db8c0d04043be5def2405475a3652886
BLAKE2b-256 ede3378b082ef6dd7e434af6c77c5521a5f39a17b745e68bfade59e8ad81fb89

See more details on using hashes here.

Supported by

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