Skip to content

Commit

Permalink
Remove Python bindings (pycaracal) (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmouchet committed Oct 27, 2023
1 parent fdad40f commit c4ee82f
Show file tree
Hide file tree
Showing 18 changed files with 3 additions and 691 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
!data/
!extern/
!include/
!python/
!src/
!tests/
!CMakeLists.txt
Expand Down
104 changes: 0 additions & 104 deletions .github/workflows/pypi.yml

This file was deleted.

11 changes: 0 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,6 @@ debug/
cmake-build-*/
.DS_Store

# Python
.eggs/
.tox/
*.egg-info/
*.so
__pycache__/
_skbuild/
dist/
venv/
MANIFEST

# Nix
result

Expand Down
28 changes: 1 addition & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ project(caracal VERSION 0.14.7)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/)

set(CARACAL_PRIVATE_FLAGS -Wall -Wextra -pedantic -fPIC)
set(CARACAL_PRIVATE_FLAGS -Wall -Wextra -pedantic)
set(THREADS_PREFER_PTHREAD_FLAG ON)

file(GLOB CARACAL_LIBRARY_SOURCES src/*.cpp)
file(GLOB CARACAL_TESTS_SOURCES tests/*.cpp)

option(WITH_BINARY "Enable binary target" OFF)
option(WITH_CONAN "Run conan install on configure" OFF)
option(WITH_PYTHON "Enable Python target" OFF)
option(WITH_TESTS "Enable tests target" OFF)
configure_file(apps/caracal-config.h.in caracal-config.h)

Expand All @@ -26,17 +25,10 @@ configure_file(apps/caracal-config.h.in caracal-config.h)
if(WITH_CONAN)
include(conan)
conan_cmake_autodetect(settings)
# Set `arch=...` setting if the `CONAN_ARCH` env. variable is set.
# This is useful to cross-compile on macOS, e.g. to compile for arm64:
# CMAKE_OSX_ARCHITECTURES=arm64 CONAN_ARCH=armv8
if(DEFINED ENV{CONAN_ARCH})
set(settings ${settings} arch=$ENV{CONAN_ARCH})
endif()
conan_cmake_install(
PATH_OR_REFERENCE
${CMAKE_CURRENT_SOURCE_DIR}
BUILD
b2
missing
SETTINGS
${settings}
Expand All @@ -57,18 +49,6 @@ if(WITH_BINARY)
find_package(cxxopts REQUIRED)
endif()

if(WITH_PYTHON)
# Add pip-installed pybind11 path to CMake's search path.
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" -c
"import pybind11; print(pybind11.get_cmake_dir())"
OUTPUT_VARIABLE _tmp_dir
OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ECHO STDOUT
)
list(APPEND CMAKE_PREFIX_PATH "${_tmp_dir}")
find_package(pybind11 REQUIRED)
endif()

if(WITH_TESTS)
find_package(Catch2 REQUIRED)
include(Catch)
Expand Down Expand Up @@ -109,12 +89,6 @@ if(WITH_BINARY)
install(TARGETS caracal-bin RUNTIME DESTINATION bin)
endif()

if(WITH_PYTHON)
pybind11_add_module(_pycaracal MODULE python/pycaracal.cpp)
target_link_libraries(_pycaracal PRIVATE caracal spdlog::spdlog)
install(TARGETS _pycaracal LIBRARY DESTINATION .)
endif()

if(WITH_TESTS)
add_executable(caracal-test ${CARACAL_TESTS_SOURCES})
target_compile_definitions(
Expand Down
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
[![Coverage](https://img.shields.io/codecov/c/github/dioptra-io/caracal?logo=codecov&logoColor=white)](https://codecov.io/gh/dioptra-io/caracal)
[![Documentation](https://img.shields.io/badge/documentation-online-blue.svg?logo=read-the-docs&logoColor=white)](https://dioptra-io.github.io/caracal/)
[![Docker Status](https://img.shields.io/github/actions/workflow/status/dioptra-io/caracal/docker.yml?branch=main&logo=github&label=docker)](https://github.com/dioptra-io/caracal/actions/workflows/docker.yml)
[![PyPI Status](https://img.shields.io/github/actions/workflow/status/dioptra-io/caracal/pypi.yml?branch=main&logo=github&label=pypi)](https://github.com/dioptra-io/caracal/actions/workflows/pypi.yml)
[![Tests Status](https://img.shields.io/github/actions/workflow/status/dioptra-io/caracal/tests.yml?branch=main&logo=github&label=tests)](https://github.com/dioptra-io/caracal/actions/workflows/tests.yml)
[![PyPI](https://img.shields.io/pypi/v/pycaracal?color=blue&logo=pypi&logoColor=white)](https://pypi.org/project/pycaracal/)

Caracal is a stateless ICMP/UDP IPv4/v6 Paris traceroute and ping engine written in modern C++ with Python bindings.
Caracal is a stateless ICMP/UDP IPv4/v6 Paris traceroute and ping engine written in modern C++.
It runs on BSD, Linux and macOS, on x86-64 and ARM64 systems.

Caracal reads probe specifications, sends the corresponding probe packets at the specified rate, parse the eventual replies and outputs them in CSV format.
Expand Down Expand Up @@ -52,5 +50,4 @@ Name | License
[cxxopts](https://github.com/jarro2783/cxxopts) | [MIT](https://opensource.org/licenses/MIT) | CLI arguments parsing
[liblpm](https://github.com/rmind/liblpm) | [2-clause BSD](https://opensource.org/licenses/BSD-2-Clause) | Longest-prefix matching
[libtins](https://github.com/mfontanini/libtins) | [2-clause BSD](https://opensource.org/licenses/BSD-2-Clause) | Packet parsing
[pybind11](https://github.com/pybind/pybind11) | [3-clause BSD](https://opensource.org/licenses/BSD-3-Clause) | Python interface
[spdlog](https://github.com/gabime/spdlog) | [MIT](https://opensource.org/licenses/MIT) | Logging
46 changes: 0 additions & 46 deletions docs/dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ Option | Default | Description
`CMAKE_BUILD_TYPE` | `Debug` | Set to `Release` for a production build.
`WITH_CONAN` | `OFF` | Whether to run `conan install` on configure or not.
`WITH_BINARY` | `OFF` | Whether to enable the `caracal-bin` target or not.
`WITH_PYTHON` | `OFF` | Whether to enable the `_pycaracal` target or not.
`WITH_TESTS` | `OFF` | Whether to enable the `caracal-test` target or not.

Use `-DOPTION=Value` to set an option.
Expand All @@ -57,7 +56,6 @@ Target | Output | Description
:---------------|:--------------------------|:-----------
`caracal-bin` | `caracal` | Prober
`caracal-test` | `caracal-test` | Unit and performance tests
`_pycaracal` | ` _pycaracal*.so` | Python interface

To build a specific target, use `cmake --build . --target TARGET`.

Expand All @@ -68,50 +66,6 @@ To build the Docker image, simply run:
docker build -t caracal .
```

## Python interface

Caracal provides an experimental Python interface.
It is currently only used for internal projects, and we do not recommend its general use.
The extension is built using [pybind11](https://github.com/pybind/pybind11), [scikit-build](https://github.com/scikit-build/scikit-build).

### Isolated build

To build the Python package in a dedicated virtual environment, use [`build`](https://github.com/pypa/build):
```bash
python3 -m pip install --upgrade build
python3 -m build
# The source distribution and the wheels will be in dist/
```

### Manual build

While `build` is very convenient to build wheels, we may want to build the extension manually to use a debugger or reduce compilation time.
To do so, we need a Python virtual environment with pybind11 installed in it:
```bash
python3 -m venv venv
source venv/bin/activate
pip3 install pybind11

mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Debug -DWITH_CONAN=ON -DWITH_PYTHON=ON -DPYTHON_EXECUTABLE=$(which python3) ..
cmake --build . --target _pycaracal

# This will build _pycaracal*.so, to test it:
python -c 'import _pycaracal'
```

To run the tests:
```bash
# Assuming the CMake build directory is build/
# In the repository root:
ln -s $(pwd)/build/_pycaracal*.so python/pycaracal/
# In python/ (must be run with python3 -m):
python3 -m pytest
```

The CI pipeline is managed by [cibuildwheel](https://github.com/joerick/cibuildwheel) in the [pypi.yml](https://github.com/dioptra-io/caracal/tree/main/.github/workflows/pypi.yml) workflow.
We build x86_64 Linux wheels for Python 3.8+, as well as universal (ARM64 + x86_64) macOS wheels for Python 3.9+.

## Profiling

Caracal is easily profiled using [perf](http://www.brendangregg.com/perf.html) on Linux.
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Introduction

Caracal is a stateless ICMP/UDP IPv4/v6 Paris traceroute and ping engine written in modern C++ with Python bindings.
Caracal is a stateless ICMP/UDP IPv4/v6 Paris traceroute and ping engine written in modern C++.
It runs on BSD, Linux and macOS, on x86-64 and ARM64 systems.

Caracal reads probe specifications, sends the corresponding probe packets at the specified rate, parse the eventual replies and outputs them in CSV format.
Expand Down
17 changes: 0 additions & 17 deletions docs/python.md

This file was deleted.

10 changes: 0 additions & 10 deletions include/caracal/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,3 @@
#ifndef __linux__
#define s6_addr32 __u6_addr.__u6_addr32
#endif

// Fix for the glibc version included in the Python manylinux2014 image...
#ifdef __GLIBC__
#ifndef __FAVOR_BSD
#define uh_sport source
#define uh_dport dest
#define uh_ulen len
#define uh_sum check
#endif
#endif
1 change: 0 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ markdown_extensions:
nav:
- index.md
- usage.md
- python.md
- dev.md
extra:
social:
Expand Down
13 changes: 0 additions & 13 deletions pyproject.toml

This file was deleted.

Loading

0 comments on commit c4ee82f

Please sign in to comment.