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
Built Distribution
File details
Details for the file srcml-caller-0.1.3.tar.gz
.
File metadata
- Download URL: srcml-caller-0.1.3.tar.gz
- Upload date:
- Size: 827.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42ec4188e4a848d540c0159f2a459865f734db575636cddff8af963aafaba981 |
|
MD5 | 5ad8922755eeb31562b7758274d45f26 |
|
BLAKE2b-256 | d6437c4be4ff6bddb75efa14060360657aa3715494a59cbe0c32666a1e45049a |
File details
Details for the file srcml_caller-0.1.3-cp311-cp311-macosx_13_0_arm64.whl
.
File metadata
- Download URL: srcml_caller-0.1.3-cp311-cp311-macosx_13_0_arm64.whl
- Upload date:
- Size: 2.0 MB
- Tags: CPython 3.11, macOS 13.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 781dd6d969b30675549764b472515205b2cfe3575a3a032d802f9c7b19f77ad7 |
|
MD5 | e94a4d35a4d9a0b9f7d3da05e0eed1cd |
|
BLAKE2b-256 | 5ff2f7bc09d4d98c834269b45455b27fbf6f6ba8866786e1f82ead58fc63c990 |