Skip to main content

srcml_caller, simple python bindings for srcML

Project description

srcml_caller

simple bindings for srcML, when used with C++ code.

Works on linux and MacOS.

Provides:

from typing import Optional
import enum


class CodeLanguage(enum.Enum):
    c = enum.auto()            # (= 0)
    c_sharp = enum.auto()      # (= 1)
    c_plus_cplus = 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

Based on scikit_build_example for litgen

Install instructions

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

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

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

Windows port advices

This project does not work on windows, mainly to srcML dependencies.

A possible strategy would be to:

  • Ask users to install and configure conan:
pip install conan
conan profile new default --detect
  • Use conan when running pip. see pyproject.toml which contains:
# Draft in order to install windows deps via conan
# "conan>=1.5",

(conan has the advantage to be callable from pip, since it is a python package)

  • Fill the dependencies in conanfile_win_deps.txt

  • Call conan install when CMake is invoked:

    execute_process(COMMAND
        conan install ${CMAKE_CURRENT_LIST_DIR}/${conanfile} --build=missing
        RESULT_VARIABLE conan_install_result
        )

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.1.1.tar.gz (2.8 MB view details)

Uploaded Source

Built Distribution

srcml_caller-0.1.1-cp39-cp39-macosx_12_0_arm64.whl (2.0 MB view details)

Uploaded CPython 3.9 macOS 12.0+ ARM64

File details

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

File metadata

  • Download URL: srcml-caller-0.1.1.tar.gz
  • Upload date:
  • Size: 2.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.12

File hashes

Hashes for srcml-caller-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c950e6fa7f4e502031d5705f78cac0f148ebe447435ff77a38ac357fb9499dc3
MD5 ac0c74068fe02c08a33d8626a49ad1fc
BLAKE2b-256 b54fb7dc8d5659ac7ab55d65c1211f36e3b617d1ab4a74cd09e48e4620eb0359

See more details on using hashes here.

File details

Details for the file srcml_caller-0.1.1-cp39-cp39-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for srcml_caller-0.1.1-cp39-cp39-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 c1096af2b93d7d0f970fbce7f18e9f2127bffa2864e37a77633651100d8e6215
MD5 feedc300b6dc26e3d137486ae48ce2f6
BLAKE2b-256 b825d86d66650bea5663d055e8386bec48c4d9698f4c419f436261f951f71c0a

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