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

Uploaded Source

Built Distribution

srcml_caller-0.1.0-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.0.tar.gz.

File metadata

  • Download URL: srcml-caller-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 f5eb404a1853907fe9b3310a6f9c2982c27372b123532d056b95911a0a1dfaed
MD5 dd78772d61cfa07fcb039fa01e77a233
BLAKE2b-256 6de480f9ccf991597c932c111b3881420af4061340e47c24461622710d72337d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for srcml_caller-0.1.0-cp39-cp39-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 4c24c603f163add79ad4d2134a81b87d38c8202641561f77d3d5db0cb716c4b3
MD5 4c95d595a62bc8b23a759b39f6496457
BLAKE2b-256 2aa812b1a200557fc64566b48e2d1abbc5c9fafcd021b685e74db2c00582c55a

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