From d891b3269f2379a7cbe7f3148ce5b968cc53da30 Mon Sep 17 00:00:00 2001 From: Todd Leonhardt <2812720+tleonhardt@users.noreply.github.com> Date: Sat, 5 Dec 2026 16:55:58 -0500 Subject: [PATCH 01/16] Modernize the native binding workshop and add Python-to-Rust examples --- .github/workflows/ci.yml | 61 ++ .github/workflows/docs.yml | 41 ++ .gitignore | 100 +-- .pre-commit-config.yaml | 19 + .python-version | 1 + Makefile | 33 + Pipfile | 12 - Prerequisites.md | 110 ---- README.md | 244 +------ cffi/.gitignore | 2 - cffi/Readme.md | 30 - cffi/build_c_dynamic_lib.sh | 5 - cffi/fib_python.py | 44 -- cffi/fibonacci.c | 18 - cffi/fibonacci.h | 7 - cffi/test_cffi.py | 55 -- comparison/__init__.py | 1 + comparison/benchmark.py | 51 ++ comparison/reference.py | 11 + cython/integrate/.gitignore | 3 - cython/integrate/Readme.md | 174 ----- cython/integrate/build_cython.sh | 1 - cython/integrate/cyintegrate.pyx | 29 - cython/integrate/cython_speedup.py | 46 -- cython/integrate/integrate.py | 29 - cython/integrate/setup.py | 11 - cython/optimize_python/.gitignore | 2 - cython/optimize_python/Readme.md | 28 - cython/optimize_python/build_cython.bat | 1 - cython/optimize_python/build_cython.sh | 1 - cython/optimize_python/cython_speedup.py | 42 -- cython/optimize_python/fib.pyx | 15 - cython/optimize_python/fib_cython.py | 30 - cython/optimize_python/fib_python.py | 44 -- cython/optimize_python/setup.py | 11 - cython/wrap_arrays/.gitignore | 3 - cython/wrap_arrays/Readme.md | 54 -- cython/wrap_arrays/build_cython.sh | 8 - cython/wrap_arrays/cfastlz.pxd | 10 - cython/wrap_arrays/cyfastlz.pyx | 47 -- cython/wrap_arrays/fastlz.c | 551 ---------------- cython/wrap_arrays/fastlz.h | 101 --- cython/wrap_arrays/run_test.sh | 1 - cython/wrap_arrays/setup.py | 11 - cython/wrap_arrays/test_cython_wrapper.py | 39 -- cython/wrap_c/.gitignore | 3 - cython/wrap_c/Readme.md | 25 - cython/wrap_c/build_cython.sh | 8 - cython/wrap_c/cfib.pxd | 6 - cython/wrap_c/cyfib.pyx | 7 - cython/wrap_c/cython_wrapper_speedup.py | 42 -- cython/wrap_c/fib_python.py | 44 -- cython/wrap_c/fibonacci.c | 18 - cython/wrap_c/fibonacci.h | 7 - cython/wrap_c/run_test.sh | 1 - cython/wrap_c/setup.py | 8 - cython/wrap_c/test_cython_wrapper.py | 6 - docs/benchmark.md | 13 + docs/bindings.md | 34 + docs/exercises.md | 134 ++++ docs/index.md | 48 ++ native/CMakeLists.txt | 74 +++ native/LICENSE | 21 + native/bindings/cffi_fib.py.in | 17 + native/bindings/cython_fib.pyx | 11 + native/bindings/cython_typed.pyx | 13 + native/bindings/nanobind_fib.cpp | 8 + native/bindings/pybind_fib.cpp | 8 + native/bindings/swig_fib.i | 17 + native/core/fibonacci.c | 16 + native/core/fibonacci.cpp | 18 + native/core/fibonacci.h | 4 + native/core/fibonacci.hpp | 5 + native/core/metadata.c | 7 + native/core/metadata.h | 11 + native/labs.cmake | 17 + native/labs/buffer_codec.pyx | 50 ++ native/labs/callbacks.hpp | 14 + native/labs/callbacks.i | 21 + native/labs/integration.pyx | 15 + native/labs/vector_codec.cpp | 52 ++ native/labs/vector_codec.hpp | 10 + native/labs/vector_codec.i | 23 + native/pyproject.toml | 33 + native/src/native_examples/__init__.py | 1 + pybind11/.gitignore | 3 - pybind11/Readme.md | 20 - pybind11/build_pybind11.sh | 6 - pybind11/fib_python.py | 44 -- pybind11/fibonacci.cpp | 42 -- pybind11/fibonacci.h | 7 - pybind11/test_pybind11.py | 42 -- pyproject.toml | 33 + rust/Cargo.lock | 132 ++++ rust/Cargo.toml | 13 + rust/pyproject.toml | 19 + rust/src/lib.rs | 24 + swig/fastlz/.gitignore | 5 - swig/fastlz/Compress.cpp | 86 --- swig/fastlz/Compress.h | 22 - swig/fastlz/Compress.i | 21 - swig/fastlz/Readme.md | 32 - swig/fastlz/build_fastlz_lib.sh | 5 - swig/fastlz/build_swig_python_wrapper.sh | 2 - swig/fastlz/fastlz.c | 551 ---------------- swig/fastlz/fastlz.h | 99 --- swig/fastlz/setup.py | 16 - swig/fastlz/test_swig.py | 51 -- swig/fibonacci/.gitignore | 8 - swig/fibonacci/CMakeLists.txt | 20 - swig/fibonacci/Readme.md | 32 - swig/fibonacci/build_c.sh | 1 - swig/fibonacci/build_swig_python_wrapper.bat | 1 - swig/fibonacci/build_swig_python_wrapper.sh | 1 - swig/fibonacci/build_swig_ruby_wrapper.sh | 4 - swig/fibonacci/extconf.rb | 5 - swig/fibonacci/fib_python.py | 44 -- swig/fibonacci/fibonacci.c | 61 -- swig/fibonacci/fibonacci.h | 7 - swig/fibonacci/fibonacci.i | 9 - swig/fibonacci/setup.py | 14 - swig/fibonacci/test_swig.py | 42 -- swig/fibonacci/test_swig.rb | 7 - swig/logger/.gitignore | 4 - swig/logger/Readme.md | 37 -- swig/logger/build_swig.sh | 2 - swig/logger/example.cpp | 31 - swig/logger/example.h | 37 -- swig/logger/example.i | 14 - swig/logger/runme.py | 54 -- swig/logger/setup.py | 14 - swig/structs/.gitignore | 8 - swig/structs/Readme.md | 23 - swig/structs/build_c.sh | 1 - swig/structs/build_swig_python_wrapper.sh | 2 - swig/structs/clean.sh | 12 - swig/structs/fib_python.py | 44 -- swig/structs/fibonacci.c | 79 --- swig/structs/fibonacci.h | 21 - swig/structs/fibonacci.i | 12 - swig/structs/setup.py | 14 - swig/structs/test_swig.py | 46 -- tests/test_fibonacci.py | 41 ++ tests/test_labs.py | 92 +++ uv.lock | 657 +++++++++++++++++++ zensical.toml | 12 + 146 files changed, 1968 insertions(+), 3827 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/docs.yml create mode 100644 .pre-commit-config.yaml create mode 100644 .python-version create mode 100644 Makefile delete mode 100644 Pipfile delete mode 100644 Prerequisites.md delete mode 100644 cffi/.gitignore delete mode 100644 cffi/Readme.md delete mode 100755 cffi/build_c_dynamic_lib.sh delete mode 100755 cffi/fib_python.py delete mode 100644 cffi/fibonacci.c delete mode 100644 cffi/fibonacci.h delete mode 100755 cffi/test_cffi.py create mode 100644 comparison/__init__.py create mode 100644 comparison/benchmark.py create mode 100644 comparison/reference.py delete mode 100644 cython/integrate/.gitignore delete mode 100644 cython/integrate/Readme.md delete mode 100755 cython/integrate/build_cython.sh delete mode 100644 cython/integrate/cyintegrate.pyx delete mode 100755 cython/integrate/cython_speedup.py delete mode 100644 cython/integrate/integrate.py delete mode 100644 cython/integrate/setup.py delete mode 100644 cython/optimize_python/.gitignore delete mode 100644 cython/optimize_python/Readme.md delete mode 100755 cython/optimize_python/build_cython.bat delete mode 100755 cython/optimize_python/build_cython.sh delete mode 100755 cython/optimize_python/cython_speedup.py delete mode 100644 cython/optimize_python/fib.pyx delete mode 100755 cython/optimize_python/fib_cython.py delete mode 100755 cython/optimize_python/fib_python.py delete mode 100644 cython/optimize_python/setup.py delete mode 100644 cython/wrap_arrays/.gitignore delete mode 100644 cython/wrap_arrays/Readme.md delete mode 100755 cython/wrap_arrays/build_cython.sh delete mode 100644 cython/wrap_arrays/cfastlz.pxd delete mode 100644 cython/wrap_arrays/cyfastlz.pyx delete mode 100644 cython/wrap_arrays/fastlz.c delete mode 100644 cython/wrap_arrays/fastlz.h delete mode 100755 cython/wrap_arrays/run_test.sh delete mode 100644 cython/wrap_arrays/setup.py delete mode 100644 cython/wrap_arrays/test_cython_wrapper.py delete mode 100644 cython/wrap_c/.gitignore delete mode 100644 cython/wrap_c/Readme.md delete mode 100755 cython/wrap_c/build_cython.sh delete mode 100644 cython/wrap_c/cfib.pxd delete mode 100644 cython/wrap_c/cyfib.pyx delete mode 100755 cython/wrap_c/cython_wrapper_speedup.py delete mode 100755 cython/wrap_c/fib_python.py delete mode 100644 cython/wrap_c/fibonacci.c delete mode 100644 cython/wrap_c/fibonacci.h delete mode 100755 cython/wrap_c/run_test.sh delete mode 100644 cython/wrap_c/setup.py delete mode 100644 cython/wrap_c/test_cython_wrapper.py create mode 100644 docs/benchmark.md create mode 100644 docs/bindings.md create mode 100644 docs/exercises.md create mode 100644 docs/index.md create mode 100644 native/CMakeLists.txt create mode 100644 native/LICENSE create mode 100644 native/bindings/cffi_fib.py.in create mode 100644 native/bindings/cython_fib.pyx create mode 100644 native/bindings/cython_typed.pyx create mode 100644 native/bindings/nanobind_fib.cpp create mode 100644 native/bindings/pybind_fib.cpp create mode 100644 native/bindings/swig_fib.i create mode 100644 native/core/fibonacci.c create mode 100644 native/core/fibonacci.cpp create mode 100644 native/core/fibonacci.h create mode 100644 native/core/fibonacci.hpp create mode 100644 native/core/metadata.c create mode 100644 native/core/metadata.h create mode 100644 native/labs.cmake create mode 100644 native/labs/buffer_codec.pyx create mode 100644 native/labs/callbacks.hpp create mode 100644 native/labs/callbacks.i create mode 100644 native/labs/integration.pyx create mode 100644 native/labs/vector_codec.cpp create mode 100644 native/labs/vector_codec.hpp create mode 100644 native/labs/vector_codec.i create mode 100644 native/pyproject.toml create mode 100644 native/src/native_examples/__init__.py delete mode 100644 pybind11/.gitignore delete mode 100644 pybind11/Readme.md delete mode 100755 pybind11/build_pybind11.sh delete mode 100755 pybind11/fib_python.py delete mode 100644 pybind11/fibonacci.cpp delete mode 100644 pybind11/fibonacci.h delete mode 100755 pybind11/test_pybind11.py create mode 100644 pyproject.toml create mode 100644 rust/Cargo.lock create mode 100644 rust/Cargo.toml create mode 100644 rust/pyproject.toml create mode 100644 rust/src/lib.rs delete mode 100644 swig/fastlz/.gitignore delete mode 100644 swig/fastlz/Compress.cpp delete mode 100644 swig/fastlz/Compress.h delete mode 100644 swig/fastlz/Compress.i delete mode 100644 swig/fastlz/Readme.md delete mode 100755 swig/fastlz/build_fastlz_lib.sh delete mode 100755 swig/fastlz/build_swig_python_wrapper.sh delete mode 100644 swig/fastlz/fastlz.c delete mode 100644 swig/fastlz/fastlz.h delete mode 100644 swig/fastlz/setup.py delete mode 100644 swig/fastlz/test_swig.py delete mode 100644 swig/fibonacci/.gitignore delete mode 100644 swig/fibonacci/CMakeLists.txt delete mode 100644 swig/fibonacci/Readme.md delete mode 100755 swig/fibonacci/build_c.sh delete mode 100755 swig/fibonacci/build_swig_python_wrapper.bat delete mode 100755 swig/fibonacci/build_swig_python_wrapper.sh delete mode 100755 swig/fibonacci/build_swig_ruby_wrapper.sh delete mode 100644 swig/fibonacci/extconf.rb delete mode 100755 swig/fibonacci/fib_python.py delete mode 100644 swig/fibonacci/fibonacci.c delete mode 100644 swig/fibonacci/fibonacci.h delete mode 100644 swig/fibonacci/fibonacci.i delete mode 100644 swig/fibonacci/setup.py delete mode 100755 swig/fibonacci/test_swig.py delete mode 100755 swig/fibonacci/test_swig.rb delete mode 100644 swig/logger/.gitignore delete mode 100644 swig/logger/Readme.md delete mode 100755 swig/logger/build_swig.sh delete mode 100644 swig/logger/example.cpp delete mode 100644 swig/logger/example.h delete mode 100644 swig/logger/example.i delete mode 100755 swig/logger/runme.py delete mode 100644 swig/logger/setup.py delete mode 100644 swig/structs/.gitignore delete mode 100644 swig/structs/Readme.md delete mode 100755 swig/structs/build_c.sh delete mode 100755 swig/structs/build_swig_python_wrapper.sh delete mode 100755 swig/structs/clean.sh delete mode 100755 swig/structs/fib_python.py delete mode 100644 swig/structs/fibonacci.c delete mode 100644 swig/structs/fibonacci.h delete mode 100644 swig/structs/fibonacci.i delete mode 100644 swig/structs/setup.py delete mode 100755 swig/structs/test_swig.py create mode 100644 tests/test_fibonacci.py create mode 100644 tests/test_labs.py create mode 100644 uv.lock create mode 100644 zensical.toml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..ab16e40 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,61 @@ +name: Native examples + +on: + pull_request: + push: + branches: [master] + +permissions: + contents: read + +concurrency: + group: tests-${{ github.event.pull_request.number || github.sha }} + cancel-in-progress: true + +jobs: + test: + name: ${{ matrix.os }} / Python ${{ matrix.python }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + python: ["3.11", "3.12", "3.13", "3.14", "3.15"] + include: + - os: macos-latest + python: "3.15" + - os: windows-latest + python: "3.15" + runs-on: ${{ matrix.os }} + timeout-minutes: 25 + env: + UV_PYTHON: ${{ matrix.python }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0 + with: + version: "0.13.13" + - name: Install zlib headers on Linux + if: runner.os == 'Linux' + run: sudo apt-get update && sudo apt-get install -y zlib1g-dev + - name: Install static zlib for MSVC + if: runner.os == 'Windows' + shell: pwsh + run: | + vcpkg install zlib:x64-windows-static-md --classic + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + "ZLIB_ROOT=$env:VCPKG_INSTALLATION_ROOT/installed/x64-windows-static-md" >> $env:GITHUB_ENV + - name: Build and test the installed examples + run: uv run --locked --no-default-groups --group test python -m pytest + - name: Smoke-test the benchmark + run: uv run --locked --no-default-groups --group test python -m comparison.benchmark --calls 100 --repeat 1 + + quality: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0 + with: + version: "0.13.13" + - run: uv lock --check + - run: uv sync --locked --only-group quality + - run: uv run --locked --no-sync prek run --all-files --show-diff-on-failure diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 0000000..279d1fc --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,41 @@ +name: Documentation + +on: + pull_request: + push: + branches: [master] + workflow_dispatch: + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0 + with: + version: "0.13.13" + - run: make docs-test + - uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5.0.0 + with: + path: site/ + + deploy: + needs: build + if: github.ref == 'refs/heads/master' && github.event_name != 'pull_request' + runs-on: ubuntu-latest + concurrency: + group: github-pages + cancel-in-progress: false + permissions: + pages: write + id-token: write + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + steps: + - name: Deploy the guide + id: deployment + uses: actions/deploy-pages@368f82528645a54fb793d4d04e342629a3f51346 # v5.0.1 diff --git a/.gitignore b/.gitignore index a1b3b5f..2199f38 100644 --- a/.gitignore +++ b/.gitignore @@ -1,99 +1,15 @@ -# Byte-compiled / optimized / DLL files +.venv/ __pycache__/ *.py[cod] -*$py.class - -# C extensions +*.egg-info/ *.so - -# Distribution / packaging -.Python -env/ +*.pyd build/ -develop-eggs/ dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -*.egg-info/ -.installed.cfg -*.egg - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*,cover -.hypothesis/ - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ - -# PyBuilder target/ - -# IPython Notebook -.ipynb_checkpoints - -# pyenv -.python-version - -# celery beat schedule file -celerybeat-schedule - -# dotenv -.env - -# virtualenv -venv/ -ENV/ - -# Spyder project settings -.spyderproject - -# Rope project settings -.ropeproject - -# Mac OS X +site/ +.cache/ +.pytest_cache/ +.ruff_cache/ .DS_Store - -# IntelliJ IDEs such as PyCharm -.idea - -# Pipenv -Pipfile.lock -.venv +.idea/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..628e590 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,19 @@ +repos: + - repo: local + hooks: + - id: ruff-check + name: Ruff lint + language: system + entry: uv run --locked --no-sync ruff check + types: [python] + - id: ruff-format + name: Ruff format + language: system + entry: uv run --locked --no-sync ruff format --check + types: [python] + - id: rustfmt + name: Rust format + language: system + entry: cargo fmt --manifest-path rust/Cargo.toml -- --check + types: [rust] + pass_filenames: false diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..93a848f --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.15 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a556667 --- /dev/null +++ b/Makefile @@ -0,0 +1,33 @@ +.DEFAULT_GOAL := help +.PHONY: help install hooks check test benchmark docs docs-test + +help: + @echo 'make install Install both native packages and development tools' + @echo 'make hooks Install the prek Git hook' + @echo 'make check Check the lockfile and run prek on all files' + @echo 'make test Build the bindings and run the shared test suite' + @echo 'make benchmark Compare the implementations on this machine' + @echo 'make docs Preview the Zensical guide locally' + @echo 'make docs-test Build the guide with strict validation' + +install: + uv sync --locked + +hooks: install + uv run --locked --no-sync prek install + +check: install + uv lock --check + uv run --locked --no-sync prek run --all-files + +test: + uv run --locked python -m pytest + +benchmark: + uv run --locked python -m comparison.benchmark + +docs: + uv run --isolated --locked --only-group docs zensical serve + +docs-test: + uv run --isolated --locked --only-group docs zensical build --strict diff --git a/Pipfile b/Pipfile deleted file mode 100644 index f9af38b..0000000 --- a/Pipfile +++ /dev/null @@ -1,12 +0,0 @@ -[[source]] -name = "pypi" -url = "https://pypi.org/simple" -verify_ssl = true - -[dev-packages] -ipython = "*" - -[packages] -cffi = "*" -cython = "*" -pybind11 = "*" diff --git a/Prerequisites.md b/Prerequisites.md deleted file mode 100644 index 23a1101..0000000 --- a/Prerequisites.md +++ /dev/null @@ -1,110 +0,0 @@ -# Prerequisites for Running Example Code -The examples on this site are compatible with Mac OS X, Linux, and Windows. To run these examples -you will need various C/C++ and Python software installed. The instructions here cover the -prerequisites necessary to run the Cython, SWIG, and CFFI examples. - - -## C and C++ compiler toolchains -To run most of the examples you need a C compiler toolchain and for some of them you also need -a C++ compiler toolchain. How to get this installed depends on which operating system (OS) you - are running. - -### Linux -If you are using any of Linux OSes which use **apt** for a package manager (Debian, Ubuntu, or Mint), -then you can do the following to get all of the C and C++ tools you need: - -```bash -sudo apt-get install build-essential -``` - -For other Linux package managers, the fundamental tools you want to install are ``gcc`` and ``g++``. - -### Mac OS X -Install the free **XCode** developer tools from the App Store. Make sure you run it at least once and -say "yes" if it asks you if you want to install the command-line tools. - -### Windows -There are a number of options for Windows, but by far the simplest is to use the same compiler which -Python itself was compiled with. For recent versions of Python released within the past couple years, -this is the Visual C++ compiler which comes with Visual Studio 2017. - -It is relatively easy to use both SWIG and Cython on Windows because all C/C++ compilation can -coordinated within the setup.py file and handled either by the setuptools or distutils Python module. -In this case, Python will automatically know where all of the correct libraries to link against are. - -Using CFFI can be a little bit more finicky since it is directly calls into pre-compiled dynamic -libraries and makes some assumptions regarding the C ABI. So you really need to make sure you are -using the exact compiler that Python itself was compiled with. - -See the [WindowsCompliers](https://wiki.python.org/moin/WindowsCompilers) section of the Python Wiki for more -information. - -**If you try to use the examples on Windows and run into difficulties, you may wish to setup a Linux -virtual machine (VM) for evaluation purposes since C/C++ compilers are a lot easier to setup on Linux. -We recommend using -[VMware Player](http://www.vmware.com/products/player/playerpro-evaluation.html) or -[Virtualbox](https://www.virtualbox.org) to install a Linux Virtual Machine (VM).** - - -## Python and Other Tools - -### Pipenv -[Pipenv](https://github.com/pypa/pipenv) is an easy way to install compatible versions of `cffi`, `cython`, and -`pybind11`. Once `pipenv` in installed, these other packages can be installed in a virtual environment using: -```shell script -pipenv install -``` - -Then this Python virtual environment can be entered using: -```shell script -pipenv shell -``` - -### Anaconda Python -Another easy way to get all of the tools installed and setup is by using the Anaconda Python -distribution. This is a free distribution of Python available for Windows, Mac OS X, and Linux which -comes with a couple hundred of the most common and useful Python modules pre-installed including Cython -and CFFI. It also comes with the ``conda`` package manager which can be used to install additional -tools such as SWIG. - -Download the latest version of [Anaconda](https://www.continuum.io/downloads). We recommend Python 3.6 or newer. - -Install Anaconda per the instructions and let it modify your .bashrc, .bash_profile, or path accordingly. -NOTE: Do not use ``sudo`` to install Anaconda, just install it as a normal user. - -This also installs Cython and CFFI. - -## SWIG -If Anaconda is installed, you can use the included **conda** package manager to install SWIG. Do -the following in a command-line terminal: - -```bash -conda install swig -``` - -Alternatively, on macOS you can use the Homebrew package manager to install SWIG: - -```shell script -brew install swig -``` - -## PyPy -PyPy is best installed with a package manager such as *brew* on Mac OS X or *apt-get** on many Linux distros. - -### PyPy on Mac -Use the Homebrew package manager to install - -```bash -brew install pypy -``` - -### PyPy on Linux -Use your the package manager which comes your distro to install pypy. For example, on Debian, Ubuntu, or Mint -distros: - -```bash -sudo apt-get install pypy -``` - -### PyPy on Windows -Download a Windows binary from the PyPy website: http://pypy.org/download.html diff --git a/README.md b/README.md index 3468d63..2511b08 100644 --- a/README.md +++ b/README.md @@ -1,229 +1,33 @@ -# Python_Interface_Cpp -Example code for interfacing with C and C++ from Python using Cython, SWIG, PyPy, CFFI, and pybind11: +# Python Native Interfaces -* [Cython](http://cython.org) -* [SWIG](http://www.swig.org) -* [PyPy](https://pypy.org) -* [CFFI](http://cffi.readthedocs.io) -* [pybind11](https://github.com/pybind/pybind11) +Call the same Fibonacci function from Python through CFFI, Cython, SWIG, pybind11, nanobind, and PyO3. The examples also show how to pass byte buffers, expose a C struct, and call a Python override from C++. Every worked example builds into a Python environment and runs under pytest. -## Fibonacci Example -This repository has example code for interfacing with some C code for calculating the Nth -fibonacci number from Python using the four different tools. +## Try it -This is the one universal example present for all tools and is thus intended to provide -an apples-to-apples comparison both in terms of API/usage and performance. +Install [uv](https://docs.astral.sh/uv/getting-started/installation/), a C/C++17 compiler, Rust with Cargo, and the zlib development headers. The default interpreter is CPython 3.15. Platform-specific instructions are in the [getting-started guide](docs/index.md). -### Fibonacci Performance Benchmarks -One metric for evaluating these tools is performance. Here is a table which shows speedup -factor relative to the pure Python implementation of the Fibonacci code. So a speedup of **2** -means that code ran twice as fast as the pure Python version. +```sh +uv sync --locked +uv run --locked python -c "from rust_fibonacci import compute_fibonacci; print(compute_fibonacci(20))" +uv run --locked python -m pytest +``` -| Tool | Speedup | -| ------------------ | -------:| -| pypy + CFFI | 40 | -| Cython (optimized) | 27 | -| Cython (wrapper) | 25 | -| SWIG | 14 | -| pybind11 | 10 | -| pypy | 8 | -| CFFI | 6 | -| Python | 1 | +The Rust call prints `17711`. The original workshop starts its sequence at `1, 2, 3, 5`, so its index 20 corresponds to the conventional Fibonacci number F(22). -NOTE: These numbers were originally measured on a 2013 15" Mac Book Pro using Python 3.6 via Anaconda distro -with the latest versions of all tools installed using the conda package manager. I have more recently measured -using a Python 3.7 virtual environment via [Pipenv](https://github.com/pypa/pipenv) and confirmed that they -stayed approximately the same and relative rankings in terms of performance are identical. +| To | Run | +| --- | --- | +| Build the extensions and run tests | `make test` | +| Compare timings on your machine | `make benchmark` | +| Install the prek Git hook | `make hooks` | +| Run code quality checks | `make check` | +| Serve the Zensical guide | `make docs` | +| Build the site with strict validation | `make docs-test` | -The Fibonacci example presented here is pretty trivial. Your mileage may vary depending on your -application. But overall these performance measurements are fairly representative of what you -may typically expect from each of these tools. +## Explore the code -In general whenever you see nested loops in your Python code, that is where you should expect the -most speedup can be gained by optimizing with C/C++. Speedups on the order of 1000 are not -uncommon if you are dealing with triply-nested loops for things like image processing code. +- [C and C++ bindings](native/) share one scikit-build-core/CMake build. Compare the binding declarations and the native functions they call. +- [Rust extension](rust/) uses PyO3 and maturin. It exposes the same Python function as the C and C++ examples. +- [The guide to the bindings](docs/bindings.md) explains when each approach fits. [Workshop exercises](docs/exercises.md) walk through typed loops, buffers, vectors, and callbacks. +- [Benchmark instructions](docs/benchmark.md) describe the measurements and their limits. -## Other Examples -Some of the tools have other examples provided as well, typically for more advanced features. -But no attempt is made to provide an apples-to-apples cross-tool comparison for these other -examples. - -# Meet the tools - -## Cython -Cython is the C-Extensions for Python module and it is an optimising static transpiler which -lets you use optional C static types embedded in your Python code and automatically translate -that to C or C++ code and then automatically compile it. - -But all of that happens pretty much behind the scenes, and you are left with code that looks -mostly like Python, but has the performance of C. - -It has a bit of a learning curve, but it is amazing. In particular it is awesome for -optimizing existing Python code. But it is also good for providing really high performance -wrappers of existing C/C++ code with a clean Pythonic API. It just requires you to manually -do the wrapping, so it involves significantly more work on your part to do so than using SWIG. - -The [Cython documentation](http://docs.cython.org/en/latest/) is excellent and there is a great -[book](https://www.amazon.com/Cython-Programmers-Kurt-W-Smith/dp/1491901551) from OReilly and also some great -video presentations on [YouTube](https://www.youtube.com/watch?v=gMvkiQ-gOW8&t=14s) and on [Safari](http://shop.oreilly.com/product/0636920046813.do). - -## SWIG -SWIG is the Simplified Wrapper and Interface Generator. It is capable of wrapping C and C++ -code/libraries in about 20 different target languages including Python, Java, C#, etc. - -SWIG largely automates the process of wrapping existing C/C++ code so it is faster and easier -to use for that purpose than Cython. - -The [SWIG documentation](http://www.swig.org/Doc3.0/index.html) can sometimes leave something to be desired, but it is an extremely powerful -tool which is an excellent choice in many situations. A professor from the University of Oslo has -a decent [video tutorial](https://www.youtube.com/watch?v=J-iVTLp6M9I) with [example code](https://github.com/UiO-INF3331/code-snippets/tree/master/mixed/swig) on GitHub. - -SWIG is the granddaddy of all of the tools here. It has been around for a long time. Given how -long it has been around and the wealth of target languages, it is probably the most widely used -of these tools. - -## PyPy -PyPy is a fast, compliant alternative implementation of the Python language (2.7.13 and 3.5.3) in Python. -The normal implementation of Python is in C and is referred to as CPython. PyPy uses a Just-in-Time (JIT) -compiler, so Python programs often run significantly faster on PyPy. It also employs various memory -optimizations compared to CPython. - -The major advantage of PyPy is that it can deliver some quick and easy wins. You don't need to change -your existing Python code in any way! You just install PyPy and run your Python program using **pypy** -instead of **python**. - -The major disadvantage of PyPy is that not all 3rd-party Python libraries work with PyPy. Detailed -information on which modules are compatible can be found [here](https://pypy.org/compat.html). - -## CFFI -CFFI is the C Foreign Function Interface for Python. It is basically an improved version of -Python's built-in ctypes. - -It can call functions in a C dynamic library just by writing code inline in Python. There -isn't any sort of need for an external wrapper. Hence, it is the quickest and easiest -of these libraries to use to interface with existing C dynamic libraries. However, the -performance is decidedly worse than the other options presented here unless it is used in combination -with PyPy, in which case the performance is truly excellent. - -Its real strength lies in 100% compatibility with PyPy and lower overhead present when using CFFI -with PyPy's JIT. So it is the go-to choice if you are -using the PyPy JIT. That being said, I don't think I would recommend using it if you aren't using -PyPy because either Cython or SWIG tend to be a better fit for most applications when used with -the normal CPython implementation of Python. - -CFFI has decent [documentation](https://cffi.readthedocs.io/en/latest/) and here is a [tutorial video](https://www.youtube.com/watch?v=ThDFmuXH15k). - -## pybind11 -pybind11 is essentially what arose from the ashes of Boost.Python. It is the newest of the tools -presented here, but it is already better than -Boost.Python ever was. - -It only works with bleeding-edge C++11 compilers. My experience is that I couldn't get it to work on Mac OS X at all and I tried with both Python 3.6 and Python 2.7, both from Anaconda distro and using default LLVM compiler from Xcode on Mac OS X -10.12.4. I also could not get it working on either Ubuntu 16.04 or 14.04 with either Python 2.7 or 3.6. I was able to get it working on Debian 9 with both Python 2.7 and 3.5 as installed from apt-get. Given that experience I wouldn't even consider it remotely stable yet. - -The performance is worse than either SWIG or Cython and the ease of use is not as easy to use as SWIG. -So does a niche exist for pybind11? pybind11 does make it easy to embedded Python within a C++ project and it is well -supported on Windows. Here is a [good video](https://channel9.msdn.com/Shows/Visual-Studio-Toolbox/Embedding-Python-in-a-C-Project) that demonstrates scripting a -C++ application with Python using pybind11 and Visual Studio 2017. - -[pybind11 documentation](http://pybind11.readthedocs.io/en/stable/) is decent and here is a [conference video](https://www.youtube.com/watch?v=jQedHfF1Jfw). - -pybind11 does appear to be under rapid development, so maybe it will get better in the future; but at this time I can -only recommend it for embedding Python within a C++ project (though it is probably worth noting that Cython is also -capable of doing that). - -# Conclusion / Recommendations -Ok, here are some of my thoughts. They are my opinions and are hence subjective in nature, though -they are grounded in my having actually evaluated these tools at length. - -If what you care about most is performance, then Cython is the clear winner by a wide margin. But on -the flip side, this tool has the largest learning curve, at least if you are looking at wrapping -existing C++ code. - -If what you care about most is productivity, then SWIG is the clear winner if you want to wrap existing -C/C++ code and Cython is the clear winner if you want to optimize existing Python code. - -If all of the 3rd-party Python libraries you are using are compatible with PyPy, then using PyPy can -provide a painless performance boost for free. Given that there are no code changes required to use it, -it is very much worth trying it and seeing what sort of speedup you get. - -CFFI is pretty lame unless you are using PyPy. But it is super easy to use with near zero learning curve. -So if you just want to call a function or two from an existing C library, it may be your best bet. On -the other hand, if all of the 3rd party libraries you are using work with PyPy and you only want to -interface with C code (not C++), then the combination of PyPy + CFFI can result in some truly impressive -performance improvements. - -pybind11 struggles with easy cross-platform compatibility and its performance is worse than SWIG, but it is more of a -pain to use than SWIG. So I'd recommend staying away from it for now unless you are looking to embed Python code within -a C++ project on Windows. - -## Updates for 2019 -Recent re-evaluation of all these options firmly confirms my original conclusions. `Cython` and `SWIG` are both awesome -with distinct tradeoffs. The combination of `PyPy` + `CFFI` is attractive and shows a lot of potential. While the -cross-platform compatibility issues previously seen with `pybind11` appear to have been resolved, I still can't see a -use case for which it would be superior to one of the other options; but it has a ton of stars on GitHub so perhaps I -am missing something? - -# Running Example Code Yourself -For information on getting all of the necessary prerequisites installed, see -[Prerequisites for Running Example Code](https://github.com/tleonhardt/Python_Interface_Cpp/blob/master/Prerequisites.md). - -For info on how to build and run each particular example, see the **Readme.md** in the example directory. - - -# Excercises -There are a few examples here which are intended as guided exercises to help build your knowledge of how -to use Cython and SWIG. - -The exercises exist on the **master** branch, while the solutions exist on the **solutions** branch. - -Most exercises have **TODO:** comments in the locations where they want you to write some code and have -instructions in the Readme.md for that exercise. - -## Cython Exercises - -### Intro to Cython Exercise -The [integrate](https://github.com/tleonhardt/Python_Interface_Cpp/tree/master/cython/integrate) Cython -example serves as a good basic introduction to using Cython to optimize existing Python code. It -details a relatively typical series of steps which are followed in using Cython for process of -progressively optimizing existing Python code. - -### Cython for Wrapping -The [wrap_arrays](https://github.com/tleonhardt/Python_Interface_Cpp/tree/master/cython/wrap_arrays) -Cython example serves as an introduction to using Cython to wrap existing C code. It purposely uses -an example where the C functions take pointers to arrays, so it can help you learn how to generate -wrapper code for this common type of scenario. - -There are better (more optimal) ways of doing this than presented in the solution. The solution tries -to keep it simple. - -## SWIG Exercises - -### Cross-language Polymorphism in SWIG -The [logger](https://github.com/tleonhardt/Python_Interface_Cpp/tree/master/swig/logger) SWIG example -serves as an introduction to how to achieve true cross-language polymorphism in SWIG by using directors. -This allows you to have a base class defined in C++, inherit from this class in Python, and then -instantiate a C++ class which takes a pointer to the base class and you pass it a pointer to an instance -of the derived class and your C++ class will end up calling virtual methods defined in Python. - -While this sounds complicated and abstract, it is actually pretty simple to make use of it and is of -great practical utility. - -As a side benefit, this example also covers how to wrap STL std::string strings and effectively auto-cast -them to Python str objects. - -### Using STL Containers in SWIG -The [fastlz](https://github.com/tleonhardt/Python_Interface_Cpp/tree/master/swig/fastlz) SWIG example -serves as an introduction to how to use STL containers such as vectors in your SWIG Python wrappers. Also -serves as an example of how to get your SWIG wrappers to link to dynamic libraries. - -## Solutions -Solutions to all exercises are in the same location as the exercise, but on the **solutions** branch. - - -# Presentation -The repository also has an overview [presentation](https://github.com/tleonhardt/Python_Interface_Cpp/tree/master/Interfacing_C_C++_with_Python.pdf) covering the basics of Cython, SWIG, and CFFI as well -as when you might want to use each one. - -To accompany this presentation, there is a [lab guide](https://github.com/tleonhardt/Python_Interface_Cpp/tree/master/Interfacing_C_C++_with_Python-Exercises.pdf) -which provides an overview of the Cython and SWIG hand-on exercises in this repository. +The original [slides](Interfacing_C_C++_with_Python.pdf) and [lab handout](Interfacing_C_C++_with_Python-Exercises.pdf) accompany the [2019 workshop checkout](https://github.com/tleonhardt/Python_Interface_Cpp/tree/398eab0c6e7f5e0358edb6644c71b5fdc6b2606a). Its PyPy comparisons, Ruby extension, FastLZ exercises, and platform-specific build scripts are available there. For the current exercises, use the [Zensical guide](https://tleonhardt.github.io/Python_Interface_Cpp/). diff --git a/cffi/.gitignore b/cffi/.gitignore deleted file mode 100644 index 9d22eb4..0000000 --- a/cffi/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*.o -*.so diff --git a/cffi/Readme.md b/cffi/Readme.md deleted file mode 100644 index 81c8626..0000000 --- a/cffi/Readme.md +++ /dev/null @@ -1,30 +0,0 @@ -# Interfacing with a dynamic library from Python using CFFI -Example code for interfacing with a C dynamic library from Python using CFFI. - -## Building -Build the C dynamic library using the following shell script: - - ./build_c_dynamic_lib.sh - -## Evaluating -Compare the results of a pure Python implementation to that of the CFFI wrapper using: - - ./test_cffi.py - -## Code Files -* Pure Python implementation - * fib_python.py -* C implementation - * fibonacci.h/.c -* CFFI "wrapper" (there is no wrapper code, its all inline Python) - * test_cffi.py - - -## Troubleshooting -The ABI of the C API is generally not stable and may change between versions of Python. This can -cause code which used to work to break when you upgrade either your version of Python or CFFI. - -If you get a Python traceback from an exception that contains something like "ImportError: dlopen", -then you may have a mismatch between your version of Python and your version of CFFI. Try upgrading -one or both. The **conda** package manager which ships with the Anaconda Python distro is convenient -for this. diff --git a/cffi/build_c_dynamic_lib.sh b/cffi/build_c_dynamic_lib.sh deleted file mode 100755 index 3a95794..0000000 --- a/cffi/build_c_dynamic_lib.sh +++ /dev/null @@ -1,5 +0,0 @@ -# Compile with position-independent code -cc -std=c11 -c -Wall -Werror -g0 -O3 -fpic fibonacci.c - -# Create a shared library from an object file -cc -shared -o libfibonacci.so fibonacci.o diff --git a/cffi/fib_python.py b/cffi/fib_python.py deleted file mode 100755 index 527dc7f..0000000 --- a/cffi/fib_python.py +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env python -# coding=utf-8 -""" Pure Python implementation for computing the nth fibonacci number in a -non-recursive fashion. -""" - - -def compute_fibonacci(n): - """ - Computes fibonacci sequence - """ - a = 1 - b = 1 - intermediate = 0 - for x in range(n): - intermediate = a - a = a + b - b = intermediate - return a - - -if __name__ == '__main__': - import sys - import timeit - - n = 20 - try: - n = int(sys.argv[1]) - except Exception: - pass - - fib_n = compute_fibonacci(n) - - number_of_times = 100000 - try: - number_of_times = int(sys.argv[2]) - except Exception: - pass - - total_time = timeit.timeit("compute_fibonacci({})".format(n), - setup="from __main__ import compute_fibonacci", - number=number_of_times) - avg_time = total_time / number_of_times - print("fib({0}) = {1} [average execution time: {2:.2g} s]".format(n, fib_n, avg_time)) diff --git a/cffi/fibonacci.c b/cffi/fibonacci.c deleted file mode 100644 index e5026af..0000000 --- a/cffi/fibonacci.c +++ /dev/null @@ -1,18 +0,0 @@ -/* File : fibonacci.c - * - * Implementation of the algorithm in C to be compiled to a dynamic library - */ - -int compute_fibonacci(int n) -{ - int temp; - int a = 1; - int b = 1; - for (int x=0; x None: + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument( + "-n", type=int, default=20, metavar="INDEX", help="workshop index (0 to 44)" + ) + parser.add_argument("--calls", type=int, default=100_000, help="calls per timing sample") + parser.add_argument("--repeat", type=int, default=5, help="number of timing samples") + args = parser.parse_args() + if not 0 <= args.n <= 44 or min(args.calls, args.repeat) < 1: + parser.error("use an index from 0 to 44 and positive sample sizes") + + expected = reference.compute_fibonacci(args.n) + print(f"{sys.implementation.name} {platform.python_version()} on {platform.platform()}") + print(f"fib({args.n}) = {expected}, median of {args.repeat} × {args.calls:,} calls") + print(f"{'Implementation':<18} {'ns/call':>10} {'speedup':>9}") + for name, module in ( + ("Python", reference), + ("CFFI (ABI)", cffi_fib), + ("Cython (wrapper)", cython_fib), + ("Cython (typed)", cython_typed), + ("SWIG", swig_fib), + ("pybind11", pybind_fib), + ("nanobind", nanobind_fib), + ("PyO3", rust_fibonacci), + ): + fib = module.compute_fibonacci + if fib(args.n) != expected: + raise ValueError(f"{name} disagrees with the Python reference") + timer = Timer("fib(n)", globals={"fib": fib, "n": args.n}) + seconds = median(timer.repeat(repeat=args.repeat, number=args.calls)) / args.calls + if module is reference: + baseline = seconds + print(f"{name:<18} {seconds * 1e9:>10.1f} {baseline / seconds:>8.2f}x") + + +if __name__ == "__main__": + main() diff --git a/comparison/reference.py b/comparison/reference.py new file mode 100644 index 0000000..b9c7f61 --- /dev/null +++ b/comparison/reference.py @@ -0,0 +1,11 @@ +"""The original workshop's Fibonacci convention starts at 1, 2, 3, 5.""" + + +def compute_fibonacci(n: int) -> int: + """Return the workshop's term n, which is F(n + 2) in standard notation.""" + if not 0 <= n <= 44: + raise ValueError("n must be between 0 and 44") + previous, current = 1, 1 + for _ in range(n): + previous, current = current, previous + current + return current diff --git a/cython/integrate/.gitignore b/cython/integrate/.gitignore deleted file mode 100644 index cd19358..0000000 --- a/cython/integrate/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -*.c -*.html - diff --git a/cython/integrate/Readme.md b/cython/integrate/Readme.md deleted file mode 100644 index 6e9d9eb..0000000 --- a/cython/integrate/Readme.md +++ /dev/null @@ -1,174 +0,0 @@ -# Faster code via static typing and Cython -Cython is a Python compiler. This means that it can compile normal Python code without changes (with a few -obvious exceptions of some as-yet unsupported language features). However, for performance critical code, -it is often helpful to add static type declarations, as they will allow Cython to step out of the dynamic -nature of the Python code and generate simpler and faster C code - sometimes faster by orders of magnitude. - -It must be noted, however, that type declarations can make the source code more verbose and thus less -readable. It is therefore discouraged to use them without good reason, such as where benchmarks prove that -they really make the code substantially faster in a performance critical section. Typically a few types in -the right spots go a long way. - -All C types are available for type declarations: integer and floating point types, complex numbers, structs, -unions and pointer types. Cython can automatically and correctly convert between the types on assignment. -This also includes Python’s arbitrary size integer types, where value overflows on conversion to a C type -will raise a Python OverflowError at runtime. (It does not, however, check for overflow when doing -arithmetic.) The generated C code will handle the platform dependent sizes of C types correctly and safely -in this case. - -Types are declared via the cdef keyword. - -## Exercise - -The file **integrate.py** contains pure Python code for numerically integrating a function. The file -**cyintegrate.pyx** contains an exact copy of the code in *integrate.py*. The **build_cython.sh** script -builds the Cython code present in **cyintegrate.pyx** using the configuration in **setup.py**. - -The **cython_speedup.py** file is setup to import both the pure Python and the Cython version and to -benchmark their performance using a common configuration. - -NOTE: You need to rebuild your Cython code anytime you make changes to **cyintegrate.pyx** - - -## Step 0 - rename the .py file to .pyx -The first thing you need to do when using Cython to optimize existing Python code is to rename the -module you want to optimize to have a **.pyx** extension instead of **.py**. Then you need to create -a **setup.py** file which uses the **setuptools** module to Cythonize and compile your code. These -preliminary steps have both already been done for you in this exercise. - -## Step 1 - see how things work to start with -Cython will give some performance benefit even when compiling Python code without any static type -declarations. - -Build the Cython code: - -```bash -python setup.py build_ext --inplace -``` - -Run **cython_speedup.py** to compare the two implementations at this point. - -```bash -python cython_speedup.py -``` - -On my system, even though we have done **nothing** to change the pure Python code in any way, Cython -provides about a 60% speedup. - - -## Step 2 - look at the HTML annotation file -The **setup.py** file contains this code which tells Cython to create a *.html annotations file: - -```python -import Cython.Compiler.Options -Cython.Compiler.Options.annotate = True -``` - -This is equivalent to calling cythonize with the **-a** flag at the command line. - -Open the **cyintegrate.html** file in the web browser of your choice. Yellow lines show code which requires -interaction with the Python interpreter. The darker the yellow, the more interactions with the Python -interpreter. Any interactions with the Python interpreter slow Cython's generated C/C++ code down. White lines -indicate no interaction with the Python interpreter (pure C code). - -What you want to do is get rid of as much yellow as possible and end up with as much white as possible. This -matters particularly inside loops. The main way you get rid of these interactions with the Python interpreter -is to declare optional C static types, so Cython can use them to generate fast C code. - -After each optimization step in this exercise, you should re-examine the HTML annotation file and let -the remaining yellow lines guide your next optimization step. - - -## Step 3 - Typing Variables -As we saw, simply compiling this code in Cython merely gives a 60% speedup. This is better than nothing, -but adding some static types can make a much larger difference. - -Types for function arguments can be added simply by prefacing the parameter name with a C type, such as: - -```python -def f(double x): - return cos(x) -``` - -Types for local variables can be added by declaring them wtih **cdef**: -```python -cdef int i -``` - -Try adding static types for all function arguments and all local variables. I recommend using **double** for -floating point types since the Python **float** type corresponds to a C **double**. Once you have done -this, recompile your Cython code and re-run **cython_speedup.py**. - -This results in a 2.5 times speedup over the pure Python version. - - -## Step 4 - Typing Functions -Python function calls can be expensive – in Cython doubly so because one might need to convert to and from -Python objects to do the call. In our example above, the argument is assumed to be a C double both inside -f() and in the call to it, yet a Python float object must be constructed around the argument in order to -pass it. - -Therefore Cython provides a syntax for declaring a C-style function, the cdef keyword: -```python -cdef double f(double x) except? -2: - return cos(x) -``` - -Some form of except-modifier should usually be added, otherwise Cython will not be able to propagate -exceptions raised in the function (or a function it calls). The except? -2 means that an error will be -checked for if -2 is returned (though the ? indicates that -2 may also be used as a valid return value). -Alternatively, the slower except * is always safe. An except clause can be left out if the function returns -a Python object or if it is guaranteed that an exception will not be raised within the function call. - -A side-effect of cdef is that the function is no longer available from Python-space, as Python wouldn’t -know how to call it. It is also no longer possible to change f() at runtime. - -Using the cpdef keyword instead of cdef, a Python wrapper is also created, so that the function is -available both from Cython (fast, passing typed values directly) and from Python (wrapping values in Python -objects). In fact, cpdef does not just provide a Python wrapper, it also installs logic to allow the -method to be overridden by python methods, even when called from within cython. This does add a tiny -overhead compared to cdef methods. - -Speedup: 5 times over pure Python. - - -## Step 5 - Replacing Python standard library calls with C library calls -The call to **cos(x)** still requires interaction with the Python interpreter. The C standard library -also has a pure C implementation of the cosine function. Wouldn't it be great if we could just call that -function instead? - -Well, we can! Cython supports this sort of syntax: - -```python -from libc.math cimport cos -``` - -We can replace the "from math import cos" line with the above for further performance improvements. - -Speedup: 28 times over pure Python. - - -## Step 6 - Tell Cython to disable unnecessary safety checks -Python has a bunch of built in "safety" checks which aren't present in C. It checks for things like -division by zero, accessing an array out of bounds, integer overflow, etc. Unless you tell Cython you -don't want it to do this sort of checking, it will continue to do it just like Python. - -If you know your code is safe and Cython doesn't need to do these sorts of checks, you can inform Cython -of this to get some extra performance boost. - -In our example, there is one last nagging line of yellow, which if we expand it is due to a floating point -division check. Since this isn't in the loop, disabling this check won't buy us much here, but if it -were in the loop it would make a difference. Regardless, it is good to know how to tell Cython to do this -sort of thing. - -So to disable the floating point division check for a particular function, you can do this: - -```python -import cython - -@cython.cdivision(True) -cpdef double integrate_f(double a, double b, int N): - ... -``` - -Look here for more info: [Cython compiler directives](http://cython.readthedocs.io/en/latest/src/reference/compilation.html#compiler-directives) diff --git a/cython/integrate/build_cython.sh b/cython/integrate/build_cython.sh deleted file mode 100755 index 35154d4..0000000 --- a/cython/integrate/build_cython.sh +++ /dev/null @@ -1 +0,0 @@ -python setup.py build_ext --inplace diff --git a/cython/integrate/cyintegrate.pyx b/cython/integrate/cyintegrate.pyx deleted file mode 100644 index 23da0b6..0000000 --- a/cython/integrate/cyintegrate.pyx +++ /dev/null @@ -1,29 +0,0 @@ -# coding=utf-8 -""" -Pure Python code for numerically integrating a function. -""" -from math import cos - - -def f(x): - """Example function in one variable. - - :param x: float - point we wish to evaluate the function at - :return: float - function value at point x - """ - return cos(x) - - -def integrate_f(a, b, N): - """Numerically integrate function f starting at point a and going to point b, using N rectangles. - - :param a: float - starting point - :param b: float - ending point - :param N: int - number of points to use in the rectangluar approximation to the integral - :return: float - approximation to the true integral, which improves as N increases - """ - s = 0.0 - dx = (b-a)/N - for i in range(N): - s += f(a+i*dx) - return s * dx diff --git a/cython/integrate/cython_speedup.py b/cython/integrate/cython_speedup.py deleted file mode 100755 index ec9c25d..0000000 --- a/cython/integrate/cython_speedup.py +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env python -# coding=utf-8 -""" Python wrapper to time the Cython implementation versus the pure Python implementation. - -This is for the example of numerical integration. -""" -from integrate import integrate_f as pyintegrate_f -from cyintegrate import integrate_f as cyintegrate_f -from math import pi, isclose - -if __name__ == '__main__': - import sys - import timeit - - a = 0 - b = pi/2 - N = 10000 - try: - N = int(sys.argv[1]) - except Exception: - pass - - number_of_times = 100 - try: - number_of_times = int(sys.argv[2]) - except Exception: - pass - - int_py = pyintegrate_f(a, b, N) - int_cy = cyintegrate_f(a, b, N) - if not isclose(int_py, int_cy): - raise(ValueError(int_cy)) - - py_tot = timeit.timeit("integrate_f({}, {}, {})".format(a, b, N), - setup="from integrate import integrate_f", - number=number_of_times) - cy_tot = timeit.timeit("integrate_f({}, {}, {})".format(a, b, N), - setup="from cyintegrate import integrate_f", - number=number_of_times) - py_avg = py_tot / number_of_times - cy_avg = cy_tot / number_of_times - - print("int({}, {}, {}) = {}".format(a, b, N, int_py)) - print("Python average time: {0:.2g}".format(py_avg)) - print("Cython average time: {0:.2g}".format(cy_avg)) - print("Cython speedup: {0:.2g} times".format(py_avg/cy_avg)) diff --git a/cython/integrate/integrate.py b/cython/integrate/integrate.py deleted file mode 100644 index 23da0b6..0000000 --- a/cython/integrate/integrate.py +++ /dev/null @@ -1,29 +0,0 @@ -# coding=utf-8 -""" -Pure Python code for numerically integrating a function. -""" -from math import cos - - -def f(x): - """Example function in one variable. - - :param x: float - point we wish to evaluate the function at - :return: float - function value at point x - """ - return cos(x) - - -def integrate_f(a, b, N): - """Numerically integrate function f starting at point a and going to point b, using N rectangles. - - :param a: float - starting point - :param b: float - ending point - :param N: int - number of points to use in the rectangluar approximation to the integral - :return: float - approximation to the true integral, which improves as N increases - """ - s = 0.0 - dx = (b-a)/N - for i in range(N): - s += f(a+i*dx) - return s * dx diff --git a/cython/integrate/setup.py b/cython/integrate/setup.py deleted file mode 100644 index 7546d6c..0000000 --- a/cython/integrate/setup.py +++ /dev/null @@ -1,11 +0,0 @@ -# coding=utf-8 -from setuptools import setup -from Cython.Build import cythonize -import Cython.Compiler.Options - -Cython.Compiler.Options.annotate = True - -setup( - name="cyintegrate", - ext_modules=cythonize('cyintegrate.pyx', compiler_directives={'embedsignature': True}), -) diff --git a/cython/optimize_python/.gitignore b/cython/optimize_python/.gitignore deleted file mode 100644 index 85188f2..0000000 --- a/cython/optimize_python/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -fib.c -fib.html diff --git a/cython/optimize_python/Readme.md b/cython/optimize_python/Readme.md deleted file mode 100644 index c7bb70c..0000000 --- a/cython/optimize_python/Readme.md +++ /dev/null @@ -1,28 +0,0 @@ -# Optimizing existing Python code using Cython -Example code for optimizing existing Python code by selectively compiling a portion of it to C using Cython. - -## Building - -### Mac OS X or Linux -Build the Cython extension using the following shell script: - - ./build_cython.sh - -### Windows -Build the Cython extension using the following batch file: - - build_cython.bat - -## Evaluating -Compare the results of a pure Python implementation to that of the Cython extension: - - ./cython_speedup.py - -## Code Files -* Pure Python implementation - * fib_python.py -* Cython implementation - * Cython code - * fib.pyx - * Setuptools script - * setup.py diff --git a/cython/optimize_python/build_cython.bat b/cython/optimize_python/build_cython.bat deleted file mode 100755 index 35154d4..0000000 --- a/cython/optimize_python/build_cython.bat +++ /dev/null @@ -1 +0,0 @@ -python setup.py build_ext --inplace diff --git a/cython/optimize_python/build_cython.sh b/cython/optimize_python/build_cython.sh deleted file mode 100755 index 35154d4..0000000 --- a/cython/optimize_python/build_cython.sh +++ /dev/null @@ -1 +0,0 @@ -python setup.py build_ext --inplace diff --git a/cython/optimize_python/cython_speedup.py b/cython/optimize_python/cython_speedup.py deleted file mode 100755 index 7a8b271..0000000 --- a/cython/optimize_python/cython_speedup.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env python -# coding=utf-8 -""" Python wrapper to time the Cython implementation for computing the nth fibonacci number -in a non-recursive fashion. -""" -from fib_python import compute_fibonacci -from fib import compute_fibonacci_cython - -if __name__ == '__main__': - import sys - import timeit - - n = 20 - try: - n = int(sys.argv[1]) - except Exception: - pass - - number_of_times = 100000 - try: - number_of_times = int(sys.argv[2]) - except Exception: - pass - - fib_py = compute_fibonacci(n) - fib_cy = compute_fibonacci_cython(n) - if fib_py != fib_cy: - raise(ValueError(fib_cy)) - - py_tot = timeit.timeit("compute_fibonacci({})".format(n), - setup="from fib_python import compute_fibonacci", - number=number_of_times) - cy_tot = timeit.timeit("compute_fibonacci_cython({})".format(n), - setup="from fib import compute_fibonacci_cython", - number=number_of_times) - py_avg = py_tot / number_of_times - cy_avg = cy_tot / number_of_times - - print("fib({}) = {}".format(n, fib_py)) - print("Python average time: {0:.2g}".format(py_avg)) - print("Cython average time: {0:.2g}".format(cy_avg)) - print("Cython speedup: {0:.2g} times".format(py_avg/cy_avg)) diff --git a/cython/optimize_python/fib.pyx b/cython/optimize_python/fib.pyx deleted file mode 100644 index e349352..0000000 --- a/cython/optimize_python/fib.pyx +++ /dev/null @@ -1,15 +0,0 @@ -# coding=utf-8 -""" Cython implementation for computing the nth fibonacci number in a -non-recursive fashion. -""" - -cpdef int compute_fibonacci_cython(int n): - """ Compute the nth fibonacci number in a non-recursive fashion. - """ - cdef int a, b, intermediate, x - a, b = 1, 1 - for x in range(n): - intermediate = a - a += b - b = intermediate - return a diff --git a/cython/optimize_python/fib_cython.py b/cython/optimize_python/fib_cython.py deleted file mode 100755 index eedf348..0000000 --- a/cython/optimize_python/fib_cython.py +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env python -# coding=utf-8 -""" Python wrapper to time the Cython implementation for computing the nth fibonacci number -in a non-recursive fashion and compare it to the pure Python implementation. -""" -from fib import compute_fibonacci_cython - -if __name__ == '__main__': - import sys - import timeit - - n = 20 - try: - n = int(sys.argv[1]) - except Exception: - pass - - fib_n = compute_fibonacci_cython(n) - - number_of_times = 100000 - try: - number_of_times = int(sys.argv[2]) - except Exception: - pass - - total_time = timeit.timeit("compute_fibonacci_cython({})".format(n), - setup="from fib import compute_fibonacci_cython", - number=number_of_times) - avg_time = total_time / number_of_times - print("fib({0}) = {1} [average execution time: {2:.2g} s]".format(n, fib_n, avg_time)) diff --git a/cython/optimize_python/fib_python.py b/cython/optimize_python/fib_python.py deleted file mode 100755 index 527dc7f..0000000 --- a/cython/optimize_python/fib_python.py +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env python -# coding=utf-8 -""" Pure Python implementation for computing the nth fibonacci number in a -non-recursive fashion. -""" - - -def compute_fibonacci(n): - """ - Computes fibonacci sequence - """ - a = 1 - b = 1 - intermediate = 0 - for x in range(n): - intermediate = a - a = a + b - b = intermediate - return a - - -if __name__ == '__main__': - import sys - import timeit - - n = 20 - try: - n = int(sys.argv[1]) - except Exception: - pass - - fib_n = compute_fibonacci(n) - - number_of_times = 100000 - try: - number_of_times = int(sys.argv[2]) - except Exception: - pass - - total_time = timeit.timeit("compute_fibonacci({})".format(n), - setup="from __main__ import compute_fibonacci", - number=number_of_times) - avg_time = total_time / number_of_times - print("fib({0}) = {1} [average execution time: {2:.2g} s]".format(n, fib_n, avg_time)) diff --git a/cython/optimize_python/setup.py b/cython/optimize_python/setup.py deleted file mode 100644 index 973d6c9..0000000 --- a/cython/optimize_python/setup.py +++ /dev/null @@ -1,11 +0,0 @@ -# coding=utf-8 -from setuptools import setup -from Cython.Build import cythonize -import Cython.Compiler.Options - -Cython.Compiler.Options.annotate = True - -setup( - name="fib", - ext_modules=cythonize('fib.pyx', compiler_directives={'embedsignature': True}), -) diff --git a/cython/wrap_arrays/.gitignore b/cython/wrap_arrays/.gitignore deleted file mode 100644 index c88cab6..0000000 --- a/cython/wrap_arrays/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -cyfastlz.c -cyfastlz.html -*.o diff --git a/cython/wrap_arrays/Readme.md b/cython/wrap_arrays/Readme.md deleted file mode 100644 index b077904..0000000 --- a/cython/wrap_arrays/Readme.md +++ /dev/null @@ -1,54 +0,0 @@ -This code uses Cython to wrap C functions which take pointers to arrays as both IN and INOUT arguments. - -# Wrapping existing C code using Cython -Example code for wrapping an existing C dynamic library in Python by using Cython. - -## Building -Build the dynamic library and Cython wrapper using the following shell script: - - ./build_cython.sh - -## Evaluating -Run pytest unit tests to verify everything is working as intended for the Cython wrapper: - ./py.test -v - -## Code Files -* C implementation - * fastlz.h/.c -* Cython wrapper - * Cython declaration - * cfastlz.pxd - * Cython wrapper - * cyfastlz.pyx - * Setuptools script - * setup.py - * pytest unit tests - * test_cython_wrapper.py - - -## Exercise -You need to fill in the **TODO:** blocks in **cfastlz.pxd** and **cyfastlz.pyx** - -Some useful things to keep in mind: - -1. Read the documentation in fastlz.h to understand how the compress() and decompress() functions work. -2. You can cast from a Python type to a C type using syntax like the following: - -```python -in_buf -``` -3. In Python, you can use *slicing* to return a subarray, substring, etc using syntax similar to: - -```python -my_array = range(10) -my_array[2:7] -[2, 3, 4, 5, 6] -``` - -The slice includes the starting index, but excludes the ending index. - -You know you are done when the unit test passes. - - -### Solution -The solution is on the **solutions** branch. Don't peak until you have given this an honest effort. diff --git a/cython/wrap_arrays/build_cython.sh b/cython/wrap_arrays/build_cython.sh deleted file mode 100755 index 9ba9751..0000000 --- a/cython/wrap_arrays/build_cython.sh +++ /dev/null @@ -1,8 +0,0 @@ -# Compile fastlz.c with position-independent code -cc -std=c11 -c -Wall -Werror -g0 -O3 -fpic fastlz.c - -# Create a shared library from an object file -cc -shared -o libfastlz.so fastlz.o - -# Build the Cython wrapper using setuptools -python setup.py build_ext --inplace diff --git a/cython/wrap_arrays/cfastlz.pxd b/cython/wrap_arrays/cfastlz.pxd deleted file mode 100644 index 67f1774..0000000 --- a/cython/wrap_arrays/cfastlz.pxd +++ /dev/null @@ -1,10 +0,0 @@ -# coding=utf-8 -""" -Cython declaration file specifying what function(s) we are using from which external C header. -""" -from libc.stdint cimport uint8_t - - -cdef extern from "fastlz.h": - # TODO: Copy function prototypes you want to wrap from the C header file here (without ending semicolon) - diff --git a/cython/wrap_arrays/cyfastlz.pyx b/cython/wrap_arrays/cyfastlz.pyx deleted file mode 100644 index 23baadb..0000000 --- a/cython/wrap_arrays/cyfastlz.pyx +++ /dev/null @@ -1,47 +0,0 @@ -# coding=utf-8 -# distutils: libraries = "fastlz" -# distutils: library_dirs = "." -cimport cfastlz -from libc.stdint cimport uint8_t - - -cpdef bytes compress(bytes in_buf): - cdef int N, M - - N = len(in_buf) - - # The minimum input buffer size is 16. - if N < 16: - return None - - # The output buffer must be at least 5% larger than the input buffer and can't be smaller than 66 bytes - M = max(int(1.5*N), 66) - - # Create the output buffer - output = bytearray(M) - - # TODO: Call cfastlz.fastlz_compress(). Make sure to get the return value and to cast Python array type to C type. - - # TODO: Check for invalid return value and return None if that occurs - - # TODO: Return the compressed data as a bytes object - - -cpdef bytes decompress(bytes in_buf): - cdef int N, M - - N = len(in_buf) - - # Bounds check length, just make sure it is positive - if N < 1: - return None - - # Create an output buffer of sufficient size - M = max(int(4*N), 66) - output = bytearray(M) - - # TODO: Call cfastlz.fastlz_decompress(). Make sure to get the return value and to cast Python array type to C type. - - # TODO: Check for invalid return value and return None if that occurs - - # TODO: Return the uncompressed data as a bytes object diff --git a/cython/wrap_arrays/fastlz.c b/cython/wrap_arrays/fastlz.c deleted file mode 100644 index fa3e3ce..0000000 --- a/cython/wrap_arrays/fastlz.c +++ /dev/null @@ -1,551 +0,0 @@ -/* - FastLZ - lightning-fast lossless compression library - - Copyright (C) 2007 Ariya Hidayat (ariya@kde.org) - Copyright (C) 2006 Ariya Hidayat (ariya@kde.org) - Copyright (C) 2005 Ariya Hidayat (ariya@kde.org) - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -#include -#if !defined(FASTLZ__COMPRESSOR) && !defined(FASTLZ_DECOMPRESSOR) - -/* - * Always check for bound when decompressing. - * Generally it is best to leave it defined. - */ -#define FASTLZ_SAFE - -/* - * Give hints to the compiler for branch prediction optimization. - */ -#if defined(__GNUC__) && (__GNUC__ > 2) -#define FASTLZ_EXPECT_CONDITIONAL(c) (__builtin_expect((c), 1)) -#define FASTLZ_UNEXPECT_CONDITIONAL(c) (__builtin_expect((c), 0)) -#else -#define FASTLZ_EXPECT_CONDITIONAL(c) (c) -#define FASTLZ_UNEXPECT_CONDITIONAL(c) (c) -#endif - -/* - * Use inlined functions for supported systems. - */ -#if defined(__GNUC__) || defined(__DMC__) || defined(__POCC__) || defined(__WATCOMC__) || defined(__SUNPRO_C) -#define FASTLZ_INLINE inline -#elif defined(__BORLANDC__) || defined(_MSC_VER) || defined(__LCC__) -#define FASTLZ_INLINE __inline -#else -#define FASTLZ_INLINE -#endif - -/* - * Prevent accessing more than 8-bit at once, except on x86 architectures. - */ -#if !defined(FASTLZ_STRICT_ALIGN) -#define FASTLZ_STRICT_ALIGN -#if defined(__i386__) || defined(__386) /* GNU C, Sun Studio */ -#undef FASTLZ_STRICT_ALIGN -#elif defined(__i486__) || defined(__i586__) || defined(__i686__) /* GNU C */ -#undef FASTLZ_STRICT_ALIGN -#elif defined(_M_IX86) /* Intel, MSVC */ -#undef FASTLZ_STRICT_ALIGN -#elif defined(__386) -#undef FASTLZ_STRICT_ALIGN -#elif defined(_X86_) /* MinGW */ -#undef FASTLZ_STRICT_ALIGN -#elif defined(__I86__) /* Digital Mars */ -#undef FASTLZ_STRICT_ALIGN -#endif -#endif - -/* - * FIXME: use preprocessor magic to set this on different platforms! - */ -typedef unsigned char flzuint8; -typedef unsigned short flzuint16; -typedef unsigned int flzuint32; - -/* prototypes */ -int fastlz_compress(const uint8_t* input, int length, uint8_t* output); -int fastlz_compress_level(int level, const uint8_t* input, int length, uint8_t* output); -int fastlz_decompress(const uint8_t* input, int length, uint8_t* output, int maxout); - -#define MAX_COPY 32 -#define MAX_LEN 264 /* 256 + 8 */ -#define MAX_DISTANCE 8192 - -#if !defined(FASTLZ_STRICT_ALIGN) -#define FASTLZ_READU16(p) *((const flzuint16*)(p)) -#else -#define FASTLZ_READU16(p) ((p)[0] | (p)[1]<<8) -#endif - -#define HASH_LOG 13 -#define HASH_SIZE (1<< HASH_LOG) -#define HASH_MASK (HASH_SIZE-1) -#define HASH_FUNCTION(v,p) { v = FASTLZ_READU16(p); v ^= FASTLZ_READU16(p+1)^(v>>(16-HASH_LOG));v &= HASH_MASK; } - -#undef FASTLZ_LEVEL -#define FASTLZ_LEVEL 1 - -#undef FASTLZ_COMPRESSOR -#undef FASTLZ_DECOMPRESSOR -#define FASTLZ_COMPRESSOR fastlz1_compress -#define FASTLZ_DECOMPRESSOR fastlz1_decompress -static FASTLZ_INLINE int FASTLZ_COMPRESSOR(const uint8_t* input, int length, uint8_t* output); -static FASTLZ_INLINE int FASTLZ_DECOMPRESSOR(const uint8_t* input, int length, uint8_t* output, int maxout); -#include "fastlz.c" - -#undef FASTLZ_LEVEL -#define FASTLZ_LEVEL 2 - -#undef MAX_DISTANCE -#define MAX_DISTANCE 8191 -#define MAX_FARDISTANCE (65535+MAX_DISTANCE-1) - -#undef FASTLZ_COMPRESSOR -#undef FASTLZ_DECOMPRESSOR -#define FASTLZ_COMPRESSOR fastlz2_compress -#define FASTLZ_DECOMPRESSOR fastlz2_decompress -static FASTLZ_INLINE int FASTLZ_COMPRESSOR(const uint8_t* input, int length, uint8_t* output); -static FASTLZ_INLINE int FASTLZ_DECOMPRESSOR(const uint8_t* input, int length, uint8_t* output, int maxout); -#include "fastlz.c" - -int fastlz_compress(const uint8_t* input, int length, uint8_t* output) -{ - /* for short block, choose fastlz1 */ - if(length < 65536) - return fastlz1_compress(input, length, output); - - /* else... */ - return fastlz2_compress(input, length, output); -} - -int fastlz_decompress(const uint8_t* input, int length, uint8_t* output, int maxout) -{ - /* magic identifier for compression level */ - int level = ((*(const flzuint8*)input) >> 5) + 1; - - if(level == 1) - return fastlz1_decompress(input, length, output, maxout); - if(level == 2) - return fastlz2_decompress(input, length, output, maxout); - - /* unknown level, trigger error */ - return 0; -} - -int fastlz_compress_level(int level, const uint8_t* input, int length, uint8_t* output) -{ - if(level == 1) - return fastlz1_compress(input, length, output); - if(level == 2) - return fastlz2_compress(input, length, output); - - return 0; -} - -#else /* !defined(FASTLZ_COMPRESSOR) && !defined(FASTLZ_DECOMPRESSOR) */ - -static FASTLZ_INLINE int FASTLZ_COMPRESSOR(const uint8_t* input, int length, uint8_t* output) -{ - const flzuint8* ip = (const flzuint8*) input; - const flzuint8* ip_bound = ip + length - 2; - const flzuint8* ip_limit = ip + length - 12; - flzuint8* op = (flzuint8*) output; - - const flzuint8* htab[HASH_SIZE]; - const flzuint8** hslot; - flzuint32 hval; - - flzuint32 copy; - - /* sanity check */ - if(FASTLZ_UNEXPECT_CONDITIONAL(length < 4)) - { - if(length) - { - /* create literal copy only */ - *op++ = length-1; - ip_bound++; - while(ip <= ip_bound) - *op++ = *ip++; - return length+1; - } - else - return 0; - } - - /* initializes hash table */ - for (hslot = htab; hslot < htab + HASH_SIZE; hslot++) - *hslot = ip; - - /* we start with literal copy */ - copy = 2; - *op++ = MAX_COPY-1; - *op++ = *ip++; - *op++ = *ip++; - - /* main loop */ - while(FASTLZ_EXPECT_CONDITIONAL(ip < ip_limit)) - { - const flzuint8* ref; - flzuint32 distance; - - /* minimum match length */ - flzuint32 len = 3; - - /* comparison starting-point */ - const flzuint8* anchor = ip; - - /* check for a run */ -#if FASTLZ_LEVEL==2 - if(ip[0] == ip[-1] && FASTLZ_READU16(ip-1)==FASTLZ_READU16(ip+1)) - { - distance = 1; - ip += 3; - ref = anchor - 1 + 3; - goto match; - } -#endif - - /* find potential match */ - HASH_FUNCTION(hval,ip); - hslot = htab + hval; - ref = htab[hval]; - - /* calculate distance to the match */ - distance = anchor - ref; - - /* update hash table */ - *hslot = anchor; - - /* is this a match? check the first 3 bytes */ - if(distance==0 || -#if FASTLZ_LEVEL==1 - (distance >= MAX_DISTANCE) || -#else - (distance >= MAX_FARDISTANCE) || -#endif - *ref++ != *ip++ || *ref++!=*ip++ || *ref++!=*ip++) - goto literal; - -#if FASTLZ_LEVEL==2 - /* far, needs at least 5-byte match */ - if(distance >= MAX_DISTANCE) - { - if(*ip++ != *ref++ || *ip++!= *ref++) - goto literal; - len += 2; - } - - match: -#endif - - /* last matched byte */ - ip = anchor + len; - - /* distance is biased */ - distance--; - - if(!distance) - { - /* zero distance means a run */ - flzuint8 x = ip[-1]; - while(ip < ip_bound) - if(*ref++ != x) break; else ip++; - } - else - for(;;) - { - /* safe because the outer check against ip limit */ - if(*ref++ != *ip++) break; - if(*ref++ != *ip++) break; - if(*ref++ != *ip++) break; - if(*ref++ != *ip++) break; - if(*ref++ != *ip++) break; - if(*ref++ != *ip++) break; - if(*ref++ != *ip++) break; - if(*ref++ != *ip++) break; - while(ip < ip_bound) - if(*ref++ != *ip++) break; - break; - } - - /* if we have copied something, adjust the copy count */ - if(copy) - /* copy is biased, '0' means 1 byte copy */ - *(op-copy-1) = copy-1; - else - /* back, to overwrite the copy count */ - op--; - - /* reset literal counter */ - copy = 0; - - /* length is biased, '1' means a match of 3 bytes */ - ip -= 3; - len = ip - anchor; - - /* encode the match */ -#if FASTLZ_LEVEL==2 - if(distance < MAX_DISTANCE) - { - if(len < 7) - { - *op++ = (len << 5) + (distance >> 8); - *op++ = (distance & 255); - } - else - { - *op++ = (7 << 5) + (distance >> 8); - for(len-=7; len >= 255; len-= 255) - *op++ = 255; - *op++ = len; - *op++ = (distance & 255); - } - } - else - { - /* far away, but not yet in the another galaxy... */ - if(len < 7) - { - distance -= MAX_DISTANCE; - *op++ = (len << 5) + 31; - *op++ = 255; - *op++ = distance >> 8; - *op++ = distance & 255; - } - else - { - distance -= MAX_DISTANCE; - *op++ = (7 << 5) + 31; - for(len-=7; len >= 255; len-= 255) - *op++ = 255; - *op++ = len; - *op++ = 255; - *op++ = distance >> 8; - *op++ = distance & 255; - } - } -#else - - if(FASTLZ_UNEXPECT_CONDITIONAL(len > MAX_LEN-2)) - while(len > MAX_LEN-2) - { - *op++ = (7 << 5) + (distance >> 8); - *op++ = MAX_LEN - 2 - 7 -2; - *op++ = (distance & 255); - len -= MAX_LEN-2; - } - - if(len < 7) - { - *op++ = (len << 5) + (distance >> 8); - *op++ = (distance & 255); - } - else - { - *op++ = (7 << 5) + (distance >> 8); - *op++ = len - 7; - *op++ = (distance & 255); - } -#endif - - /* update the hash at match boundary */ - HASH_FUNCTION(hval,ip); - htab[hval] = ip++; - HASH_FUNCTION(hval,ip); - htab[hval] = ip++; - - /* assuming literal copy */ - *op++ = MAX_COPY-1; - - continue; - - literal: - *op++ = *anchor++; - ip = anchor; - copy++; - if(FASTLZ_UNEXPECT_CONDITIONAL(copy == MAX_COPY)) - { - copy = 0; - *op++ = MAX_COPY-1; - } - } - - /* left-over as literal copy */ - ip_bound++; - while(ip <= ip_bound) - { - *op++ = *ip++; - copy++; - if(copy == MAX_COPY) - { - copy = 0; - *op++ = MAX_COPY-1; - } - } - - /* if we have copied something, adjust the copy length */ - if(copy) - *(op-copy-1) = copy-1; - else - op--; - -#if FASTLZ_LEVEL==2 - /* marker for fastlz2 */ - *(flzuint8*)output |= (1 << 5); -#endif - - return op - (flzuint8*)output; -} - -static FASTLZ_INLINE int FASTLZ_DECOMPRESSOR(const uint8_t* input, int length, uint8_t* output, int maxout) -{ - const flzuint8* ip = (const flzuint8*) input; - const flzuint8* ip_limit = ip + length; - flzuint8* op = (flzuint8*) output; - flzuint8* op_limit = op + maxout; - flzuint32 ctrl = (*ip++) & 31; - int loop = 1; - - do - { - const flzuint8* ref = op; - flzuint32 len = ctrl >> 5; - flzuint32 ofs = (ctrl & 31) << 8; - - if(ctrl >= 32) - { -#if FASTLZ_LEVEL==2 - flzuint8 code; -#endif - len--; - ref -= ofs; - if (len == 7-1) -#if FASTLZ_LEVEL==1 - len += *ip++; - ref -= *ip++; -#else - do - { - code = *ip++; - len += code; - } while (code==255); - code = *ip++; - ref -= code; - - /* match from 16-bit distance */ - if(FASTLZ_UNEXPECT_CONDITIONAL(code==255)) - if(FASTLZ_EXPECT_CONDITIONAL(ofs==(31 << 8))) - { - ofs = (*ip++) << 8; - ofs += *ip++; - ref = op - ofs - MAX_DISTANCE; - } -#endif - -#ifdef FASTLZ_SAFE - if (FASTLZ_UNEXPECT_CONDITIONAL(op + len + 3 > op_limit)) - return 0; - - if (FASTLZ_UNEXPECT_CONDITIONAL(ref-1 < (flzuint8 *)output)) - return 0; -#endif - - if(FASTLZ_EXPECT_CONDITIONAL(ip < ip_limit)) - ctrl = *ip++; - else - loop = 0; - - if(ref == op) - { - /* optimize copy for a run */ - flzuint8 b = ref[-1]; - *op++ = b; - *op++ = b; - *op++ = b; - for(; len; --len) - *op++ = b; - } - else - { -#if !defined(FASTLZ_STRICT_ALIGN) - const flzuint16* p; - flzuint16* q; -#endif - /* copy from reference */ - ref--; - *op++ = *ref++; - *op++ = *ref++; - *op++ = *ref++; - -#if !defined(FASTLZ_STRICT_ALIGN) - /* copy a byte, so that now it's word aligned */ - if(len & 1) - { - *op++ = *ref++; - len--; - } - - /* copy 16-bit at once */ - q = (flzuint16*) op; - op += len; - p = (const flzuint16*) ref; - for(len>>=1; len > 4; len-=4) - { - *q++ = *p++; - *q++ = *p++; - *q++ = *p++; - *q++ = *p++; - } - for(; len; --len) - *q++ = *p++; -#else - for(; len; --len) - *op++ = *ref++; -#endif - } - } - else - { - ctrl++; -#ifdef FASTLZ_SAFE - if (FASTLZ_UNEXPECT_CONDITIONAL(op + ctrl > op_limit)) - return 0; - if (FASTLZ_UNEXPECT_CONDITIONAL(ip + ctrl > ip_limit)) - return 0; -#endif - - *op++ = *ip++; - for(--ctrl; ctrl; ctrl--) - *op++ = *ip++; - - loop = FASTLZ_EXPECT_CONDITIONAL(ip < ip_limit); - if(loop) - ctrl = *ip++; - } - } - while(FASTLZ_EXPECT_CONDITIONAL(loop)); - - return op - (flzuint8*)output; -} - -#endif /* !defined(FASTLZ_COMPRESSOR) && !defined(FASTLZ_DECOMPRESSOR) */ diff --git a/cython/wrap_arrays/fastlz.h b/cython/wrap_arrays/fastlz.h deleted file mode 100644 index 64f6939..0000000 --- a/cython/wrap_arrays/fastlz.h +++ /dev/null @@ -1,101 +0,0 @@ -/* - FastLZ - lightning-fast lossless compression library - - Copyright (C) 2007 Ariya Hidayat (ariya@kde.org) - Copyright (C) 2006 Ariya Hidayat (ariya@kde.org) - Copyright (C) 2005 Ariya Hidayat (ariya@kde.org) - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -#include - -#ifndef FASTLZ_H -#define FASTLZ_H - -#define FASTLZ_VERSION 0x000100 - -#define FASTLZ_VERSION_MAJOR 0 -#define FASTLZ_VERSION_MINOR 0 -#define FASTLZ_VERSION_REVISION 0 - -#define FASTLZ_VERSION_STRING "0.1.0" - -#if defined (__cplusplus) -extern "C" { -#endif - -/** - Compress a block of data in the input buffer and returns the size of - compressed block. The size of input buffer is specified by length. The - minimum input buffer size is 16. - - The output buffer must be at least 5% larger than the input buffer - and can not be smaller than 66 bytes. - - If the input is not compressible, the return value might be larger than - length (input buffer size). - - The input buffer and the output buffer can not overlap. -*/ - -int fastlz_compress(const uint8_t* input, int length, uint8_t* output); - -/** - Decompress a block of compressed data and returns the size of the - decompressed block. If error occurs, e.g. the compressed data is - corrupted or the output buffer is not large enough, then 0 (zero) - will be returned instead. - - The input buffer and the output buffer can not overlap. - - Decompression is memory safe and guaranteed not to write the output buffer - more than what is specified in maxout. - */ - -int fastlz_decompress(const uint8_t* input, int length, uint8_t* output, int maxout); - -/** - Compress a block of data in the input buffer and returns the size of - compressed block. The size of input buffer is specified by length. The - minimum input buffer size is 16. - - The output buffer must be at least 5% larger than the input buffer - and can not be smaller than 66 bytes. - - If the input is not compressible, the return value might be larger than - length (input buffer size). - - The input buffer and the output buffer can not overlap. - - Compression level can be specified in parameter level. At the moment, - only level 1 and level 2 are supported. - Level 1 is the fastest compression and generally useful for short data. - Level 2 is slightly slower but it gives better compression ratio. - - Note that the compressed data, regardless of the level, can always be - decompressed using the function fastlz_decompress above. -*/ - -int fastlz_compress_level(int level, const uint8_t* input, int length, uint8_t* output); - -#if defined (__cplusplus) -} -#endif - -#endif /* FASTLZ_H */ diff --git a/cython/wrap_arrays/run_test.sh b/cython/wrap_arrays/run_test.sh deleted file mode 100755 index 91c0191..0000000 --- a/cython/wrap_arrays/run_test.sh +++ /dev/null @@ -1 +0,0 @@ -LD_LIBRARY_PATH=. py.test diff --git a/cython/wrap_arrays/setup.py b/cython/wrap_arrays/setup.py deleted file mode 100644 index 61166c0..0000000 --- a/cython/wrap_arrays/setup.py +++ /dev/null @@ -1,11 +0,0 @@ -# coding=utf-8 -from setuptools import setup -from Cython.Build import cythonize -import Cython.Compiler.Options - -Cython.Compiler.Options.annotate = True - -setup( - name="cyfastlz", - ext_modules=cythonize('cyfastlz.pyx', compiler_directives={'embedsignature': True}), -) diff --git a/cython/wrap_arrays/test_cython_wrapper.py b/cython/wrap_arrays/test_cython_wrapper.py deleted file mode 100644 index 366b02f..0000000 --- a/cython/wrap_arrays/test_cython_wrapper.py +++ /dev/null @@ -1,39 +0,0 @@ -# coding=utf-8 -import cyfastlz - -def test_compress_and_decompress_roundtrip(): - # Beginning of the United States Constitution - text ="""We the People of the United States, in Order to form a more perfect Union, establish Justice, insure domestic Tranquility, provide for the common defence, promote the general Welfare, and secure the Blessings of Liberty to ourselves and our Posterity, do ordain and establish this Constitution for the United States of America. - -Article I (Article 1 - Legislative) -Section 1 -All legislative Powers herein granted shall be vested in a Congress of the United States, which shall consist of a Senate and House of Representatives. - -Section 2 -1: The House of Representatives shall be composed of Members chosen every second Year by the People of the several States, and the Electors in each State shall have the Qualifications requisite for Electors of the most numerous Branch of the State Legislature. - -2: No Person shall be a Representative who shall not have attained to the Age of twenty five Years, and been seven Years a Citizen of the United States, and who shall not, when elected, be an Inhabitant of that State in which he shall be chosen. - -3: Representatives and direct Taxes shall be apportioned among the several States which may be included within this Union, according to their respective Numbers, which shall be determined by adding to the whole Number of free Persons, including those bound to Service for a Term of Years, and excluding Indians not taxed, three fifths of all other Persons.2 The actual Enumeration shall be made within three Years after the first Meeting of the Congress of the United States, and within every subsequent Term of ten Years, in such Manner as they shall by Law direct. The Number of Representatives shall not exceed one for every thirty Thousand, but each State shall have at Least one Representative; and until such enumeration shall be made, the State of New Hampshire shall be entitled to chuse three, Massachusetts eight, Rhode-Island and Providence Plantations one, Connecticut five, New-York six, New Jersey four, Pennsylvania eight, Delaware one, Maryland six, Virginia ten, North Carolina five, South Carolina five, and Georgia three. - -4: When vacancies happen in the Representation from any State, the Executive Authority thereof shall issue Writs of Election to fill such Vacancies. - -5: The House of Representatives shall chuse their Speaker and other Officers; and shall have the sole Power of Impeachment.""" - - # Convert the ntext to a bytes - text_bytes = text.encode() - - # Compress a known text - compressed = cyfastlz.compress(text_bytes) - - # Verify that the compressed text is actually smaller than the original - assert len(compressed) < len(text_bytes) - - # Decompress the compressed text to reconstruct the original as a a bytes - reconstructed_bytes = cyfastlz.decompress(compressed) - - # Convert back to a Python 3 unicode string - reconstructed = reconstructed_bytes.decode() - - # Verify the reconstructed text is the same as the original - assert text == reconstructed diff --git a/cython/wrap_c/.gitignore b/cython/wrap_c/.gitignore deleted file mode 100644 index c84ec61..0000000 --- a/cython/wrap_c/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -cyfib.c -cyfib.html -fibonacci.o diff --git a/cython/wrap_c/Readme.md b/cython/wrap_c/Readme.md deleted file mode 100644 index d98a5b6..0000000 --- a/cython/wrap_c/Readme.md +++ /dev/null @@ -1,25 +0,0 @@ -# Wrapping existing C code using Cython -Example code for wrapping an existing C dynamic library in Python by using Cython. - -## Building -Build the dynamic library and Cython wrapper using the following shell script: - - ./build_cython.sh - -## Evaluating -Compare the results of a pure Python implementation to that of the Cython wrapper using: - - ./cython_wrapper_speedup.py - -## Code Files -* Pure Python implementation - * fib_python.py -* C implementation - * fibonacci.h/.c -* Cython wrapper - * Cython declaration - * cfib.pxd - * Cython wrapper - * cyfib.pyx - * Setuptools script - * setup.py diff --git a/cython/wrap_c/build_cython.sh b/cython/wrap_c/build_cython.sh deleted file mode 100755 index 5aeec60..0000000 --- a/cython/wrap_c/build_cython.sh +++ /dev/null @@ -1,8 +0,0 @@ -# Compile fibonacci.c with position-independent code -cc -std=c11 -c -Wall -Werror -g0 -O3 -fpic fibonacci.c - -# Create a shared library from an object file -cc -shared -o libfibonacci.so fibonacci.o - -# Build the Cython wrapper using setuptools -python setup.py build_ext --inplace diff --git a/cython/wrap_c/cfib.pxd b/cython/wrap_c/cfib.pxd deleted file mode 100644 index e354139..0000000 --- a/cython/wrap_c/cfib.pxd +++ /dev/null @@ -1,6 +0,0 @@ -# coding=utf-8 -""" -Cython declaration file specifying what function(s) we are using from which external C header. -""" -cdef extern from "fibonacci.h": - int compute_fibonacci(int n) diff --git a/cython/wrap_c/cyfib.pyx b/cython/wrap_c/cyfib.pyx deleted file mode 100644 index cba1648..0000000 --- a/cython/wrap_c/cyfib.pyx +++ /dev/null @@ -1,7 +0,0 @@ -# coding=utf-8 -# distutils: libraries = "fibonacci" -# distutils: library_dirs = "." -cimport cfib - -cpdef int compute_fibonacci_wrapper(int n): - return cfib.compute_fibonacci(n) diff --git a/cython/wrap_c/cython_wrapper_speedup.py b/cython/wrap_c/cython_wrapper_speedup.py deleted file mode 100755 index 3ade499..0000000 --- a/cython/wrap_c/cython_wrapper_speedup.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env python -# coding=utf-8 -""" Python wrapper to time the Cython implementation for computing the nth fibonacci number -in a non-recursive fashion. -""" -from fib_python import compute_fibonacci -from cyfib import compute_fibonacci_wrapper - -if __name__ == '__main__': - import sys - import timeit - - n = 20 - try: - n = int(sys.argv[1]) - except Exception: - pass - - number_of_times = 100000 - try: - number_of_times = int(sys.argv[2]) - except Exception: - pass - - fib_py = compute_fibonacci(n) - fib_cy = compute_fibonacci_wrapper(n) - if fib_py != fib_cy: - raise(ValueError(fib_cy)) - - py_tot = timeit.timeit("compute_fibonacci({})".format(n), - setup="from fib_python import compute_fibonacci", - number=number_of_times) - cy_tot = timeit.timeit("compute_fibonacci_wrapper({})".format(n), - setup="from cyfib import compute_fibonacci_wrapper", - number=number_of_times) - py_avg = py_tot / number_of_times - cy_avg = cy_tot / number_of_times - - print("fib({}) = {}".format(n, fib_py)) - print("Python average time: {0:.2g}".format(py_avg)) - print("Cython Wrapper average time: {0:.2g}".format(cy_avg)) - print("Cython Wrapper speedup: {0:.2g} times".format(py_avg/cy_avg)) diff --git a/cython/wrap_c/fib_python.py b/cython/wrap_c/fib_python.py deleted file mode 100755 index 527dc7f..0000000 --- a/cython/wrap_c/fib_python.py +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env python -# coding=utf-8 -""" Pure Python implementation for computing the nth fibonacci number in a -non-recursive fashion. -""" - - -def compute_fibonacci(n): - """ - Computes fibonacci sequence - """ - a = 1 - b = 1 - intermediate = 0 - for x in range(n): - intermediate = a - a = a + b - b = intermediate - return a - - -if __name__ == '__main__': - import sys - import timeit - - n = 20 - try: - n = int(sys.argv[1]) - except Exception: - pass - - fib_n = compute_fibonacci(n) - - number_of_times = 100000 - try: - number_of_times = int(sys.argv[2]) - except Exception: - pass - - total_time = timeit.timeit("compute_fibonacci({})".format(n), - setup="from __main__ import compute_fibonacci", - number=number_of_times) - avg_time = total_time / number_of_times - print("fib({0}) = {1} [average execution time: {2:.2g} s]".format(n, fib_n, avg_time)) diff --git a/cython/wrap_c/fibonacci.c b/cython/wrap_c/fibonacci.c deleted file mode 100644 index e5026af..0000000 --- a/cython/wrap_c/fibonacci.c +++ /dev/null @@ -1,18 +0,0 @@ -/* File : fibonacci.c - * - * Implementation of the algorithm in C to be compiled to a dynamic library - */ - -int compute_fibonacci(int n) -{ - int temp; - int a = 1; - int b = 1; - for (int x=0; x>> from native_examples import cffi_fib, cython_fib, cython_typed, swig_fib +>>> [m.compute_fibonacci(5) for m in (cffi_fib, cython_fib, cython_typed, swig_fib)] +[13, 13, 13, 13] +>>> message = swig_fib.populate_struct(7, 42, 1024) +>>> message.type, message.job, message.size +(7, 42, 1024) +``` + +The CFFI example is useful when a library already exposes a C ABI and can ship as a shared object. Cython can call an existing C function or compile the hot loop itself. SWIG is useful when you have headers to expose and want the generator to produce wrappers. Compare the [CFFI modes](https://cffi.readthedocs.io/en/stable/overview.html), [Cython language guide](https://cython.readthedocs.io/en/stable/src/userguide/index.html), and [SWIG Python guide](https://www.swig.org/Doc4.5/Python.html). + +## Inspect the C++ and Rust interfaces + +Read the C++ module definitions side by side in `native/bindings/`. Both call the implementation in `native/core/`. pybind11 offers an extensive set of conversions and integrations. nanobind was designed with smaller extension binaries and lower binding overhead in mind. The [pybind11 build guide](https://pybind11.readthedocs.io/en/stable/compiling.html) and [nanobind design notes](https://nanobind.readthedocs.io/en/latest/why.html) explain their tradeoffs. + +For Rust, start at `rust/src/lib.rs`. Follow the Python argument into the native loop and the result back into Python. Cargo resolves Rust dependencies, PyO3 handles Python objects and exceptions, and maturin builds an installable extension. See the [PyO3 guide](https://pyo3.rs/) and [maturin guide](https://www.maturin.rs/). + +PyPy is an alternative Python interpreter. This workshop tests CPython so that changes in interpreter and changes in binding library can be studied separately. The [CFFI documentation](https://cffi.readthedocs.io/en/stable/overview.html) also covers use with PyPy. diff --git a/docs/exercises.md b/docs/exercises.md new file mode 100644 index 0000000..5122ba6 --- /dev/null +++ b/docs/exercises.md @@ -0,0 +1,134 @@ +# Workshop labs + +These four labs have working implementations and tests. From the repository root, run +`uv run --locked python` to try the Python snippets interactively. After editing a +`.pyx`, `.i`, or C++ file, exit Python and run the corresponding pytest command. uv +rebuilds the local package when its native sources change. + +## 1. Integrate a cosine with Cython + +The left-rectangle rule divides an interval into equal widths, samples the function +at each rectangle's left edge, and sums the areas. The integral of cosine from zero +to π/2 is exactly one, so you can measure the approximation error directly. + +```python +from math import pi +from native_examples.integration import integrate_cos + +for steps in (10, 100, 1_000): + estimate = integrate_cos(0, pi / 2, steps) + print(steps, round(estimate, 6)) +# 10 1.076484 +# 100 1.007833 +# 1000 1.000785 +``` + +Read the Cython loop. The index uses `Py_ssize_t`, the accumulator and width use +`double`, and `cos` comes from the C math library. The positive-step check runs +once before the loop. [Integration source](https://github.com/tleonhardt/Python_Interface_Cpp/blob/master/native/labs/integration.pyx) + +**Try it.** Reimplement the same loop in Python with `math.cos`. Compare both answers +for two rectangles on the interval from zero to π, then reverse the bounds. Which +endpoint does each approximation sample first? + +```sh +uv run --locked pytest tests/test_labs.py -k integration +``` + +## 2. Pass a Python buffer to zlib with Cython + +The buffer binding accepts any one-dimensional, contiguous buffer of unsigned bytes, +including `bytes` and `bytearray`. A sliced memoryview can select the region to +compress without copying the input. + +```python +import zlib +from native_examples import buffer_codec + +packet = bytearray(b"HDR" + b"AB" * 500) +payload = memoryview(packet)[3:] +packed = buffer_codec.compress(payload) +assert zlib.decompress(packed) == payload +assert buffer_codec.decompress(packed, len(payload)) == payload +``` + +The declaration `const unsigned char[::1]` gives the wrapper a contiguous input view. +The compressor allocates the output using `compressBound`. For decompression the caller +supplies the original size. zlib updates the output length, and the wrapper checks it +before returning Python bytes. [Buffer binding](https://github.com/tleonhardt/Python_Interface_Cpp/blob/master/native/labs/buffer_codec.pyx) · [zlib utility functions](https://zlib.net/manual.html#Utility) + +**Try it.** Compress 100,000 copies of the same byte, then decompress with the exact +size and with an expected size one byte smaller. Which call raises `ValueError`? +Why would allocating a fixed multiple of the compressed size be unreliable? + +```sh +uv run --locked pytest tests/test_labs.py -k buffer_codec +``` + +## 3. Wrap a C++ byte vector with SWIG + +This binding uses the same zlib format. SWIG's `std_vector.i` converts a Python +sequence of integers into a `std::vector`. The interface also exposes +the vector class as `ByteVector` so you can build or mutate a C++ container from Python. + +```python +import zlib +from native_examples import vector_codec + +samples = vector_codec.ByteVector([0, 127, 255]) +samples.append(42) +packed = bytes(vector_codec.compress(samples)) +assert zlib.decompress(packed) == bytes([0, 127, 255, 42]) +restored = vector_codec.decompress(list(packed), len(samples)) +assert list(restored) == [0, 127, 255, 42] +``` + +Read the `%template(ByteVector)` declaration and the compression signature together. +The C++ function borrows its input by const reference and returns its output by value. +SWIG handles conversion to a Python sequence at the return boundary. +[SWIG interface](https://github.com/tleonhardt/Python_Interface_Cpp/blob/master/native/labs/vector_codec.i) · [C++ implementation](https://github.com/tleonhardt/Python_Interface_Cpp/blob/master/native/labs/vector_codec.cpp) + +**Try it.** Change the final element in `samples`, compress it again and decompress +with the Cython binding from lab 2. Predict the last byte before inspecting it. + +```sh +uv run --locked pytest tests/test_labs.py -k vector_codec +``` + +## 4. Call a Python logger from C++ + +A SWIG director routes a C++ virtual method call to an override on a Python subclass. +Here, `emit_message` takes a `Logger&` and calls its `log` method synchronously. + +```python +from native_examples.callbacks import Logger, emit_message + +class Recorder(Logger): + def __init__(self): + super().__init__() + self.messages = [] + + def log(self, level, message): + self.messages.append((level, message)) + +recorder = Recorder() +emit_message(recorder, 30, "low battery") +assert recorder.messages == [(30, "low battery")] +``` + +Python owns the recorder throughout. The C++ function borrows it for one call and +keeps no pointer afterward. The SWIG interface enables directors for `Logger` and +returns any exception from the Python override to the original caller. +[Logger and dispatch function](https://github.com/tleonhardt/Python_Interface_Cpp/blob/master/native/labs/callbacks.hpp) · [Director interface](https://github.com/tleonhardt/Python_Interface_Cpp/blob/master/native/labs/callbacks.i) · [SWIG director exceptions](https://www.swig.org/Doc4.5/Python.html#Python_director_exception_unrolling) + +**Try it.** Add a Python subclass whose `log` raises `LookupError(message)`. Call +`emit_message` with it and catch the exception in Python. Trace the path from the +call site through the C++ function to the override and back. + +```sh +uv run --locked pytest tests/test_labs.py -k callback +``` + +The full lab test file includes standard-library interoperability, invalid output +sizes, empty streams, callback exceptions and object lifetimes. +[Lab tests](https://github.com/tleonhardt/Python_Interface_Cpp/blob/master/tests/test_labs.py) diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..07d853a --- /dev/null +++ b/docs/index.md @@ -0,0 +1,48 @@ +# Call native code from Python + +Build the extensions once and try two versions of the same function. Follow the [binding comparison](bindings.md) to see what crosses the Python/native boundary in each version. + +## Install the toolchain + +Use CPython 3.11 through 3.15. The repository selects CPython 3.15 by default, and uv can provision it. Install [uv](https://docs.astral.sh/uv/getting-started/installation/) and [stable Rust with Cargo](https://rustup.rs/). uv installs the Python build backends, binding generators, and development tools. You also need a C and C++17 compiler and zlib development files. + +| Platform | Native prerequisites | +| --- | --- | +| macOS | Install Xcode Command Line Tools with `xcode-select --install`. The macOS SDK supplies zlib. | +| Ubuntu / Debian | Install the compiler, Make, and zlib headers with `sudo apt-get install build-essential zlib1g-dev`. | +| Windows x64 | Install Visual Studio Build Tools with **Desktop development with C++**, the Windows SDK, and the MSVC Rust toolchain. Install zlib using [vcpkg](https://learn.microsoft.com/vcpkg/get_started/get-started). | + +On Windows, run the following in a Developer PowerShell with vcpkg on your PATH. Set the root to your vcpkg checkout first. The static zlib build uses the same dynamic C runtime as CPython. + +```powershell +$env:VCPKG_ROOT = 'C:\src\vcpkg' +vcpkg install zlib:x64-windows-static-md --classic +$env:ZLIB_ROOT = "$env:VCPKG_ROOT/installed/x64-windows-static-md" +``` + +## Build and run + +From the repository root, run these commands on any supported platform. The first sync compiles a C/C++ package with scikit-build-core and a Rust package with maturin. Later syncs reuse the builds until their inputs change. + +```sh +uv sync --locked +uv run --locked python -m pytest +uv run --locked python +``` + +At the Python prompt, compare the two C++ bindings and Rust. + +```pycon +>>> from native_examples import pybind_fib, nanobind_fib +>>> import rust_fibonacci +>>> [m.compute_fibonacci(20) for m in (pybind_fib, nanobind_fib, rust_fibonacci)] +[17711, 17711, 17711] +``` + +## Develop locally + +With Make installed, use `make hooks` once to install prek, `make check` to run the hooks across the repository, and `make test` after editing code. The Python and Cargo lockfiles are committed. To test another supported interpreter, set `UV_PYTHON` to the desired version before running Make, or run `uv run --locked --python 3.11 python -m pytest`. + +Run `make docs` for a live preview and `make docs-test` for a strict build. GitHub Actions builds the documentation on pull requests and uploads the rendered site as an artifact. A merge to `master` publishes the site through GitHub Pages. + +Continue to the [worked examples and optional exercises](exercises.md). diff --git a/native/CMakeLists.txt b/native/CMakeLists.txt new file mode 100644 index 0000000..902b9d5 --- /dev/null +++ b/native/CMakeLists.txt @@ -0,0 +1,74 @@ +cmake_minimum_required(VERSION 3.22) +project(native_examples LANGUAGES C CXX) + +set(CMAKE_C_STANDARD 11) +set(CMAKE_C_STANDARD_REQUIRED ON) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +find_package(Python 3.11 REQUIRED COMPONENTS Interpreter Development.Module) +find_package(pybind11 CONFIG REQUIRED) +find_package(nanobind CONFIG REQUIRED) +find_package(SWIG REQUIRED) +include(UseSWIG) + +function(install_example target) + install(TARGETS ${target} + LIBRARY DESTINATION native_examples + RUNTIME DESTINATION native_examples) +endfunction() + +# Compile each .pyx into an importable CPython extension. +function(add_cython_example module source) + set(generated "${CMAKE_CURRENT_BINARY_DIR}/${module}.c") + add_custom_command(OUTPUT "${generated}" + COMMAND Python::Interpreter -m cython -3 --depfile + -o "${generated}" "${CMAKE_CURRENT_SOURCE_DIR}/${source}" + DEPENDS "${source}" + DEPFILE "${generated}.dep" + VERBATIM) + Python_add_library(${module} MODULE WITH_SOABI "${generated}" ${ARGN}) + install_example(${module}) +endfunction() + +# SWIG generates both the Python proxy and the extension that it imports. +function(add_swig_example module interface) + set(proxy_dir "${CMAKE_CURRENT_BINARY_DIR}/${module}_proxy") + set_source_files_properties("${interface}" PROPERTIES USE_SWIG_DEPENDENCIES TRUE) + swig_add_library(${module} TYPE MODULE LANGUAGE python + OUTPUT_DIR "${proxy_dir}" SOURCES "${interface}" ${ARGN}) + set_property(TARGET ${module} PROPERTY SWIG_USE_TARGET_INCLUDE_DIRECTORIES TRUE) + target_link_libraries(${module} PRIVATE Python::Module) + install_example(${module}) + install(FILES "${proxy_dir}/${module}.py" DESTINATION native_examples) +endfunction() + +# CFFI opens a regular shared library, without linking it to CPython. +add_library(fibonacci SHARED core/fibonacci.c) +set_target_properties(fibonacci PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON) +install_example(fibonacci) +file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/cffi_fib.py" + INPUT "${CMAKE_CURRENT_SOURCE_DIR}/bindings/cffi_fib.py.in") +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/cffi_fib.py" DESTINATION native_examples) + +add_cython_example(cython_fib bindings/cython_fib.pyx core/fibonacci.c) +target_include_directories(cython_fib PRIVATE core) +add_cython_example(cython_typed bindings/cython_typed.pyx) + +add_swig_example(swig_fib bindings/swig_fib.i core/fibonacci.c core/metadata.c) +target_include_directories(swig_fib PRIVATE core) + +# Both C++ bindings expose the same implementation and exception contract. +add_library(fibonacci_cpp STATIC core/fibonacci.cpp) +set_target_properties(fibonacci_cpp PROPERTIES POSITION_INDEPENDENT_CODE ON) +target_include_directories(fibonacci_cpp PUBLIC core) + +pybind11_add_module(pybind_fib bindings/pybind_fib.cpp) +target_link_libraries(pybind_fib PRIVATE fibonacci_cpp) +install_example(pybind_fib) + +nanobind_add_module(nanobind_fib bindings/nanobind_fib.cpp) +target_link_libraries(nanobind_fib PRIVATE fibonacci_cpp) +install_example(nanobind_fib) + +include(labs.cmake) diff --git a/native/LICENSE b/native/LICENSE new file mode 100644 index 0000000..1496144 --- /dev/null +++ b/native/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Todd Leonhardt + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/native/bindings/cffi_fib.py.in b/native/bindings/cffi_fib.py.in new file mode 100644 index 0000000..8762160 --- /dev/null +++ b/native/bindings/cffi_fib.py.in @@ -0,0 +1,17 @@ +"""Call the packaged shared library using its C ABI.""" + +from pathlib import Path + +from cffi import FFI + +ffi = FFI() +ffi.cdef("int compute_fibonacci(int n);") +# CMake supplies the platform-specific filename when it builds the package. +lib = ffi.dlopen(str(Path(__file__).with_name("$"))) + + +def compute_fibonacci(n: int) -> int: + result = lib.compute_fibonacci(n) + if result < 0: + raise ValueError("n must be between 0 and 44") + return result diff --git a/native/bindings/cython_fib.pyx b/native/bindings/cython_fib.pyx new file mode 100644 index 0000000..eb676d6 --- /dev/null +++ b/native/bindings/cython_fib.pyx @@ -0,0 +1,11 @@ +"""Expose an existing C function through its header.""" + +cdef extern from "fibonacci.h": + int c_compute_fibonacci "compute_fibonacci"(int n) + + +def compute_fibonacci(int n): + cdef int result = c_compute_fibonacci(n) + if result < 0: + raise ValueError("n must be between 0 and 44") + return result diff --git a/native/bindings/cython_typed.pyx b/native/bindings/cython_typed.pyx new file mode 100644 index 0000000..5ce93c0 --- /dev/null +++ b/native/bindings/cython_typed.pyx @@ -0,0 +1,13 @@ +"""Compile the algorithm itself using Cython's native integer types.""" + + +cpdef int compute_fibonacci(int n): + if n < 0 or n > 44: + raise ValueError("n must be between 0 and 44") + + cdef int current = 1 + cdef int previous = 1 + cdef int i + for i in range(n): + current, previous = current + previous, current + return current diff --git a/native/bindings/nanobind_fib.cpp b/native/bindings/nanobind_fib.cpp new file mode 100644 index 0000000..ff6a15f --- /dev/null +++ b/native/bindings/nanobind_fib.cpp @@ -0,0 +1,8 @@ +#include + +#include "fibonacci.hpp" + +NB_MODULE(nanobind_fib, module) +{ + module.def("compute_fibonacci", &workshop::compute_fibonacci, nanobind::arg("n")); +} diff --git a/native/bindings/pybind_fib.cpp b/native/bindings/pybind_fib.cpp new file mode 100644 index 0000000..c349356 --- /dev/null +++ b/native/bindings/pybind_fib.cpp @@ -0,0 +1,8 @@ +#include + +#include "fibonacci.hpp" + +PYBIND11_MODULE(pybind_fib, module) +{ + module.def("compute_fibonacci", &workshop::compute_fibonacci, pybind11::arg("n")); +} diff --git a/native/bindings/swig_fib.i b/native/bindings/swig_fib.i new file mode 100644 index 0000000..b4994fd --- /dev/null +++ b/native/bindings/swig_fib.i @@ -0,0 +1,17 @@ +%module swig_fib + +%{ +#include "fibonacci.h" +#include "metadata.h" +%} + +%include "stdint.i" + +%exception compute_fibonacci { + $action + if (result < 0) + SWIG_exception_fail(SWIG_ValueError, "n must be between 0 and 44"); +} + +%include "fibonacci.h" +%include "metadata.h" diff --git a/native/core/fibonacci.c b/native/core/fibonacci.c new file mode 100644 index 0000000..55b648b --- /dev/null +++ b/native/core/fibonacci.c @@ -0,0 +1,16 @@ +#include "fibonacci.h" + +int compute_fibonacci(int n) +{ + if (n < 0 || n > 44) + return -1; + + int current = 1; + int previous = 1; + for (int i = 0; i < n; ++i) { + int next = current + previous; + previous = current; + current = next; + } + return current; +} diff --git a/native/core/fibonacci.cpp b/native/core/fibonacci.cpp new file mode 100644 index 0000000..e51d31d --- /dev/null +++ b/native/core/fibonacci.cpp @@ -0,0 +1,18 @@ +#include "fibonacci.hpp" + +#include + +int workshop::compute_fibonacci(int n) +{ + if (n < 0 || n > 44) + throw std::invalid_argument("n must be between 0 and 44"); + + int current = 1; + int previous = 1; + for (int i = 0; i < n; ++i) { + int next = current + previous; + previous = current; + current = next; + } + return current; +} diff --git a/native/core/fibonacci.h b/native/core/fibonacci.h new file mode 100644 index 0000000..5a8eb1b --- /dev/null +++ b/native/core/fibonacci.h @@ -0,0 +1,4 @@ +#pragma once + +/* Return F(n + 2), or -1 for inputs outside the signed 32-bit result range. */ +int compute_fibonacci(int n); diff --git a/native/core/fibonacci.hpp b/native/core/fibonacci.hpp new file mode 100644 index 0000000..77fa901 --- /dev/null +++ b/native/core/fibonacci.hpp @@ -0,0 +1,5 @@ +#pragma once + +namespace workshop { +int compute_fibonacci(int n); +} diff --git a/native/core/metadata.c b/native/core/metadata.c new file mode 100644 index 0000000..ec49bcb --- /dev/null +++ b/native/core/metadata.c @@ -0,0 +1,7 @@ +#include "metadata.h" + +struct MsgMetaData populate_struct(uint32_t type, uint32_t job, uint32_t size) +{ + struct MsgMetaData message = {type, job, size}; + return message; +} diff --git a/native/core/metadata.h b/native/core/metadata.h new file mode 100644 index 0000000..7ef024d --- /dev/null +++ b/native/core/metadata.h @@ -0,0 +1,11 @@ +#pragma once + +#include + +struct MsgMetaData { + uint32_t type; + uint32_t job; + uint32_t size; +}; + +struct MsgMetaData populate_struct(uint32_t type, uint32_t job, uint32_t size); diff --git a/native/labs.cmake b/native/labs.cmake new file mode 100644 index 0000000..269601a --- /dev/null +++ b/native/labs.cmake @@ -0,0 +1,17 @@ +find_package(ZLIB REQUIRED) + +add_cython_example(integration labs/integration.pyx) +if(UNIX) + target_link_libraries(integration PRIVATE m) +endif() + +add_cython_example(buffer_codec labs/buffer_codec.pyx) +target_link_libraries(buffer_codec PRIVATE ZLIB::ZLIB) + +set_source_files_properties(labs/vector_codec.i labs/callbacks.i PROPERTIES CPLUSPLUS ON) +add_swig_example(vector_codec labs/vector_codec.i labs/vector_codec.cpp) +target_include_directories(vector_codec PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/labs") +target_link_libraries(vector_codec PRIVATE ZLIB::ZLIB) + +add_swig_example(callbacks labs/callbacks.i) +target_include_directories(callbacks PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/labs") diff --git a/native/labs/buffer_codec.pyx b/native/labs/buffer_codec.pyx new file mode 100644 index 0000000..6d0db4e --- /dev/null +++ b/native/labs/buffer_codec.pyx @@ -0,0 +1,50 @@ +"""Expose zlib's one-shot C functions to contiguous Python byte buffers.""" + +from cpython.pyport cimport PY_SSIZE_T_MAX +from libc.limits cimport ULONG_MAX + +cdef extern from "zlib.h": + int Z_OK, Z_MEM_ERROR + unsigned long compressBound(unsigned long source_size) + int z_compress "compress"(unsigned char *dest, unsigned long *dest_size, + const unsigned char *source, unsigned long source_size) + int uncompress(unsigned char *dest, unsigned long *dest_size, + const unsigned char *source, unsigned long source_size) + + +cdef unsigned long zlib_size(Py_ssize_t size) except? 0: + if size < 0: + raise ValueError("size must be nonnegative") + if size > ULONG_MAX: + raise OverflowError("size exceeds zlib's unsigned long limit") + return size + + +def compress(const unsigned char[::1] data not None): + cdef unsigned long size = zlib_size(data.shape[0]) + cdef unsigned long capacity = compressBound(size) + if capacity < size or capacity > PY_SSIZE_T_MAX: + raise OverflowError("compressed buffer would be too large") + + cdef bytearray output = bytearray(capacity) + cdef const unsigned char *source = &data[0] if size else NULL + cdef int status = z_compress(output, &capacity, source, size) + if status == Z_MEM_ERROR: + raise MemoryError() + if status != Z_OK: + raise RuntimeError("zlib compression failed") + return bytes(memoryview(output)[:capacity]) + + +def decompress(const unsigned char[::1] data not None, Py_ssize_t expected_size): + cdef unsigned long size = zlib_size(data.shape[0]) + # Give zlib room to distinguish zero output bytes from one. + cdef unsigned long written = max(1, zlib_size(expected_size)) + cdef bytearray output = bytearray(written) + cdef const unsigned char *source = &data[0] if size else NULL + cdef int status = uncompress(output, &written, source, size) + if status == Z_MEM_ERROR: + raise MemoryError() + if status != Z_OK or written != expected_size: + raise ValueError("invalid zlib stream or incorrect expected_size") + return bytes(memoryview(output)[:written]) diff --git a/native/labs/callbacks.hpp b/native/labs/callbacks.hpp new file mode 100644 index 0000000..727fa72 --- /dev/null +++ b/native/labs/callbacks.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include + +class Logger { +public: + virtual ~Logger() = default; + virtual void log(int level, const std::string& message) = 0; +}; + +// Borrow the logger for this call. Python retains ownership of its subclass. +inline void emit_message(Logger& logger, int level, const std::string& message) { + logger.log(level, message); +} diff --git a/native/labs/callbacks.i b/native/labs/callbacks.i new file mode 100644 index 0000000..db2655c --- /dev/null +++ b/native/labs/callbacks.i @@ -0,0 +1,21 @@ +%module(directors="1") callbacks +%{ +#include "callbacks.hpp" +%} + +%include +%feature("director") Logger; +%feature("director:except") Logger::log { + if ($error != NULL) { + throw Swig::DirectorMethodException(); + } +} +%exception { + try { + $action + } catch (const Swig::DirectorException&) { + // The director left the original exception in Python's error indicator. + SWIG_fail; + } +} +%include "callbacks.hpp" diff --git a/native/labs/integration.pyx b/native/labs/integration.pyx new file mode 100644 index 0000000..964a051 --- /dev/null +++ b/native/labs/integration.pyx @@ -0,0 +1,15 @@ +"""Approximate the integral of cos(x) using left-endpoint rectangles.""" + +from libc.math cimport cos + + +def integrate_cos(double start, double stop, Py_ssize_t steps): + if steps <= 0: + raise ValueError("steps must be positive") + + cdef double width = (stop - start) / steps + cdef double total = 0.0 + cdef Py_ssize_t i + for i in range(steps): + total += cos(start + i * width) + return total * width diff --git a/native/labs/vector_codec.cpp b/native/labs/vector_codec.cpp new file mode 100644 index 0000000..3e67efa --- /dev/null +++ b/native/labs/vector_codec.cpp @@ -0,0 +1,52 @@ +#include "vector_codec.hpp" + +#include +#include +#include +#include + +namespace lab { +namespace { +uLong zlib_size(std::size_t size) { + if (size > (std::numeric_limits::max)()) { + throw std::overflow_error("size exceeds zlib's unsigned long limit"); + } + return static_cast(size); +} +} + +std::vector compress(const std::vector& data) { + const uLong size = zlib_size(data.size()); + uLongf written = compressBound(size); + if (written < size) { + throw std::overflow_error("compressed buffer would be too large"); + } + std::vector output(written); + const int status = ::compress(output.data(), &written, data.data(), size); + if (status == Z_MEM_ERROR) { + throw std::bad_alloc(); + } + if (status != Z_OK) { + throw std::runtime_error("zlib compression failed"); + } + output.resize(written); + return output; +} + +std::vector decompress(const std::vector& data, + std::size_t expected_size) { + const uLong size = zlib_size(data.size()); + // Give zlib room to distinguish zero output bytes from one. + uLongf written = expected_size ? zlib_size(expected_size) : 1; + std::vector output(written); + const int status = uncompress(output.data(), &written, data.data(), size); + if (status == Z_MEM_ERROR) { + throw std::bad_alloc(); + } + if (status != Z_OK || written != expected_size) { + throw std::invalid_argument("invalid zlib stream or incorrect expected_size"); + } + output.resize(written); + return output; +} +} diff --git a/native/labs/vector_codec.hpp b/native/labs/vector_codec.hpp new file mode 100644 index 0000000..ec4ca6a --- /dev/null +++ b/native/labs/vector_codec.hpp @@ -0,0 +1,10 @@ +#pragma once + +#include +#include + +namespace lab { +std::vector compress(const std::vector& data); +std::vector decompress(const std::vector& data, + std::size_t expected_size); +} diff --git a/native/labs/vector_codec.i b/native/labs/vector_codec.i new file mode 100644 index 0000000..652e48b --- /dev/null +++ b/native/labs/vector_codec.i @@ -0,0 +1,23 @@ +%module vector_codec +%{ +#include "vector_codec.hpp" +%} + +%include +%include +%template(ByteVector) std::vector; + +%exception { + try { + $action + } catch (const std::invalid_argument& e) { + SWIG_exception(SWIG_ValueError, e.what()); + } catch (const std::overflow_error& e) { + SWIG_exception(SWIG_OverflowError, e.what()); + } catch (const std::bad_alloc& e) { + SWIG_exception(SWIG_MemoryError, e.what()); + } catch (const std::exception& e) { + SWIG_exception(SWIG_RuntimeError, e.what()); + } +} +%include "vector_codec.hpp" diff --git a/native/pyproject.toml b/native/pyproject.toml new file mode 100644 index 0000000..c9202e6 --- /dev/null +++ b/native/pyproject.toml @@ -0,0 +1,33 @@ +[build-system] +requires = [ + "scikit-build-core==1.1.2", + "cython==3.3.2", + "nanobind==3.1.0", + "pybind11==3.1.0", + "swig==4.5.1", +] +build-backend = "scikit_build_core.build" + +[project] +name = "native-examples" +version = "0.1.0" +description = "Runnable examples of Python interfaces to C and C++" +requires-python = ">=3.11" +license = "MIT" +license-files = ["LICENSE"] +dependencies = ["cffi==2.1.1"] + +[tool.scikit-build] +minimum-version = "build-system.requires" +wheel.packages = ["src/native_examples"] + +[tool.uv] +cache-keys = [ + { file = "pyproject.toml" }, + { file = "CMakeLists.txt" }, + { file = "labs.cmake" }, + { file = "bindings/**/*" }, + { file = "core/**/*" }, + { file = "labs/**/*" }, + { file = "src/native_examples/*.py" }, +] diff --git a/native/src/native_examples/__init__.py b/native/src/native_examples/__init__.py new file mode 100644 index 0000000..63ff97f --- /dev/null +++ b/native/src/native_examples/__init__.py @@ -0,0 +1 @@ +"""Python interfaces to the native workshop examples.""" diff --git a/pybind11/.gitignore b/pybind11/.gitignore deleted file mode 100644 index a3bb7f4..0000000 --- a/pybind11/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -*.o -*.so -*.dSYM diff --git a/pybind11/Readme.md b/pybind11/Readme.md deleted file mode 100644 index 02c7863..0000000 --- a/pybind11/Readme.md +++ /dev/null @@ -1,20 +0,0 @@ -# Interfacing with C++ from Python using pybind11 -Example code for interfacing with C++ code from Python using pybind11. - -## Building -Build the pybind11 Python wrapper using the following shell script: - - ./build_pybind11.sh - -## Evaluating -Compare the results of a pure Python implementation to that of the pybind11 wrapper using: - - ./test_pybind11.py - -## Code Files -* Pure Python implementation - * fib_python.py -* C++ implementation - * fibonacci.h/.cpp -* pybind11 wrapper - * test_pybind11.py diff --git a/pybind11/build_pybind11.sh b/pybind11/build_pybind11.sh deleted file mode 100755 index f6b0414..0000000 --- a/pybind11/build_pybind11.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash -# Path to pybind11 headers -PYBIND11_INCLUDE=/usr/local/include - -# On Linux and Mac OS, this example can be compiled using the following command (for Windows, use CMake) -c++ -O3 -shared -std=c++11 -Wall -fPIC -I ${PYBIND11_INCLUDE} `python-config --cflags --ldflags` fibonacci.cpp -o fibonacci.so diff --git a/pybind11/fib_python.py b/pybind11/fib_python.py deleted file mode 100755 index 527dc7f..0000000 --- a/pybind11/fib_python.py +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env python -# coding=utf-8 -""" Pure Python implementation for computing the nth fibonacci number in a -non-recursive fashion. -""" - - -def compute_fibonacci(n): - """ - Computes fibonacci sequence - """ - a = 1 - b = 1 - intermediate = 0 - for x in range(n): - intermediate = a - a = a + b - b = intermediate - return a - - -if __name__ == '__main__': - import sys - import timeit - - n = 20 - try: - n = int(sys.argv[1]) - except Exception: - pass - - fib_n = compute_fibonacci(n) - - number_of_times = 100000 - try: - number_of_times = int(sys.argv[2]) - except Exception: - pass - - total_time = timeit.timeit("compute_fibonacci({})".format(n), - setup="from __main__ import compute_fibonacci", - number=number_of_times) - avg_time = total_time / number_of_times - print("fib({0}) = {1} [average execution time: {2:.2g} s]".format(n, fib_n, avg_time)) diff --git a/pybind11/fibonacci.cpp b/pybind11/fibonacci.cpp deleted file mode 100644 index 79c82ec..0000000 --- a/pybind11/fibonacci.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* File : fibonacci.cpp - * - * Implementation of the algorithm in C++. - * - * For simplicity, we put both this function and the binding code into a single file. - * - * In practice, implementation and binding code will generally be located in separate files. - */ - -#include - -int compute_fibonacci(int n) -{ - int temp; - int a = 1; - int b = 1; - for (int x=0; x=9.2,<10"] +quality = ["prek>=0.6,<1", "ruff>=0.17.6,<1"] +docs = ["zensical>=0.1.5,<1"] + +[tool.uv] +package = false +default-groups = ["test", "quality", "docs"] + +[tool.uv.workspace] +members = ["native", "rust"] + +[tool.uv.sources] +native-examples = { workspace = true } +rust-fibonacci = { workspace = true } + +[tool.pytest.ini_options] +testpaths = ["tests"] +addopts = "-ra --strict-config --strict-markers" + +[tool.ruff] +line-length = 100 +extend-exclude = ["build", "site"] + +[tool.ruff.lint] +extend-select = ["I"] diff --git a/rust/Cargo.lock b/rust/Cargo.lock new file mode 100644 index 0000000..883e944 --- /dev/null +++ b/rust/Cargo.lock @@ -0,0 +1,132 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "libc" +version = "0.2.191" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a" + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "portable-atomic" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85" + +[[package]] +name = "proc-macro2" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "pyo3" +version = "0.30.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "229ca13b8a15bb0d1487b81ab975bfcd97513416499a8312011b6036e42e0de4" +dependencies = [ + "libc", + "once_cell", + "portable-atomic", + "pyo3-build-config", + "pyo3-ffi", + "pyo3-macros", +] + +[[package]] +name = "pyo3-build-config" +version = "0.30.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70130e2b6dd1ee589a8788026a429561ca5c40fa7a2fa7914c2282eddae24700" +dependencies = [ + "target-lexicon", +] + +[[package]] +name = "pyo3-ffi" +version = "0.30.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e7ff73c555c286d212d4ce7e5fbda845a973c4f61bd5f160f5f2c3c2a04d1c4" +dependencies = [ + "libc", + "pyo3-build-config", +] + +[[package]] +name = "pyo3-macros" +version = "0.30.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c46d2e5862c7bb8207e3b639f713dda3c499933444784154c11d013c5a691b60" +dependencies = [ + "proc-macro2", + "pyo3-macros-backend", + "quote", + "syn", +] + +[[package]] +name = "pyo3-macros-backend" +version = "0.30.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b89f066f2ae72a2aef52d1537ca2fcd104440ebfadee06e97aa90738a25b9b" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "quote" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rust-fibonacci" +version = "0.1.0" +dependencies = [ + "pyo3", +] + +[[package]] +name = "syn" +version = "3.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "target-lexicon" +version = "0.13.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c447be3a2abfa84b2d91680c56600bd6b2873866de27b36ec911be705e291da" + +[[package]] +name = "unicode-ident" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563" diff --git a/rust/Cargo.toml b/rust/Cargo.toml new file mode 100644 index 0000000..9db0d5c --- /dev/null +++ b/rust/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "rust-fibonacci" +version = "0.1.0" +description = "A Rust Fibonacci function exposed to Python with PyO3" +edition = "2024" +license = "MIT" + +[lib] +name = "rust_fibonacci" +crate-type = ["cdylib"] + +[dependencies] +pyo3 = { version = "0.30.1", features = ["abi3-py311"] } diff --git a/rust/pyproject.toml b/rust/pyproject.toml new file mode 100644 index 0000000..a6405b0 --- /dev/null +++ b/rust/pyproject.toml @@ -0,0 +1,19 @@ +[build-system] +requires = ["maturin==1.16.0"] +build-backend = "maturin" + +[project] +name = "rust-fibonacci" +dynamic = ["version", "description"] +requires-python = ">=3.11" + +[tool.maturin] +locked = true + +[tool.uv] +cache-keys = [ + { file = "pyproject.toml" }, + { file = "Cargo.toml" }, + { file = "Cargo.lock" }, + { file = "src/**/*.rs" }, +] diff --git a/rust/src/lib.rs b/rust/src/lib.rs new file mode 100644 index 0000000..546673f --- /dev/null +++ b/rust/src/lib.rs @@ -0,0 +1,24 @@ +fn fibonacci(n: u8) -> u32 { + let (mut previous, mut current) = (1, 1); + for _ in 0..n { + (previous, current) = (current, previous + current); + } + current +} + +/// Fibonacci example implemented in Rust. +#[pyo3::pymodule] +mod rust_fibonacci { + use pyo3::exceptions::PyValueError; + use pyo3::prelude::*; + use pyo3::types::PyInt; + + /// Return the term at index n (0 through 44) in the sequence 1, 2, 3, 5, ... + #[pyfunction] + fn compute_fibonacci(n: &Bound<'_, PyInt>) -> PyResult { + match n.extract::() { + Ok(index @ 0..=44) => Ok(super::fibonacci(index)), + _ => Err(PyValueError::new_err("n must be between 0 and 44")), + } + } +} diff --git a/swig/fastlz/.gitignore b/swig/fastlz/.gitignore deleted file mode 100644 index 398565b..0000000 --- a/swig/fastlz/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -fastlz_c -Compress.py -Compress_wrap.cpp -*.egg-info -*.o diff --git a/swig/fastlz/Compress.cpp b/swig/fastlz/Compress.cpp deleted file mode 100644 index b3eba6b..0000000 --- a/swig/fastlz/Compress.cpp +++ /dev/null @@ -1,86 +0,0 @@ -#include "Compress.h" - -#include -#include "fastlz.h" - -// Intermediate private helper function which wraps fastlz function for compression -static bool _compress(const void *buffer, uint32_t inSize, void *bufOut, uint32_t &sizeOut) -{ - // Has a minimum input buffer size of 16 bytes - if (inSize < 16) - { - return false; - } - - int ret = fastlz_compress(buffer, inSize, bufOut); - sizeOut = ret; - if (0 != ret) - { - return true; - } - - return false; -} - -static bool _decompress(const void *buffer, uint32_t inSize, void *bufOut, uint32_t &sizeOut) -{ - int ret = fastlz_decompress(buffer, inSize, bufOut, sizeOut); - sizeOut = ret; - if (0 != ret) - { - return true; - } - - return false; -} - - -// Public functions - -bool Compress(const std::vector& in, std::vector& out) -{ - size_t N = in.size(); - - // Compressed buffer should be *at least* 5% larger than the input buffer - // We'll err on the side of caution and make it 50% larger - size_t M = 1.5 * N; - - // Compressed buffer needs to have a minimum size of 66 bytes - if (M < 66) - { - M = 66; - } - - // If output vector isn't big enough, resize it - if (out.size() < M) - { - out.resize(M); - } - - // Call file-scope _compress() wrapper around the fastlz function - bool ok; - uint32_t compLen = 0; - ok = _compress(in.data(), N, out.data(), compLen); - if (ok) - { - // Compression succeeded, resize the output vector to correct length - out.resize(compLen); - } - - return ok; -} - -bool Decompress(const std::vector& in, std::vector& out) -{ - // Call the file-scope _decompress() wrapper around the fastlz function - bool ok; - uint32_t uncLen = out.size(); - ok = _decompress(in.data(), in.size(), out.data(), uncLen); - if (ok) - { - // Decompression succeeded, resize the output vector to correct length - out.resize(uncLen); - } - - return ok; -} diff --git a/swig/fastlz/Compress.h b/swig/fastlz/Compress.h deleted file mode 100644 index f5c9be9..0000000 --- a/swig/fastlz/Compress.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include -#include - -// Convenience wrappers around fastlz C functions which use STL vectors instead of C arrays - -/** Compress an input vector of bytes and store it in an output vector. - * - * @param in - std::vector input vector of uncompressed bytes - * @param out - std::vector output vector of compressed bytes - * @return bool - true if successful, false otherwise - */ -bool Compress(const std::vector& in, std::vector& out); - -/** Decompress an input vector of bytes and store it in an output vector. - * - * @param in - std::vector input vector of compressed bytes - * @param out - std::vector output vector of uncompressed bytes - * @return bool - true if successful, false otherwise - */ -bool Decompress(const std::vector& in, std::vector& out); diff --git a/swig/fastlz/Compress.i b/swig/fastlz/Compress.i deleted file mode 100644 index 8b95558..0000000 --- a/swig/fastlz/Compress.i +++ /dev/null @@ -1,21 +0,0 @@ -/* Compress.i */ - %module Compress - %{ - /* Includes the header in the wrapper code */ - #include "Compress.h" - %} - -// SWIG library file for ISO C99 types such as uint32_t -%include "stdint.i" - -// Provide support for the C++ vector class in the STL -%include "std_vector.i" - -// Instantiate a Python class called VectorUint8 which wraps a C++ vector STL container of bytes -namespace std -{ - %template(VectorUint8) vector; -} - -/* Parse the header file to generate wrappers */ - %include "Compress.h" diff --git a/swig/fastlz/Readme.md b/swig/fastlz/Readme.md deleted file mode 100644 index 5fa6fe6..0000000 --- a/swig/fastlz/Readme.md +++ /dev/null @@ -1,32 +0,0 @@ -# Wrapping C++ code using STL containers with SWIG -This code uses SWIG to wrap C++ functions which use STL container classes. It demonstrates how to wrap -C++ code which uses STL container class and instantiate STL container wrappers in Python. In the process -it also demonstrates how to link SWIG wrapper code to dynamic libraries. - -## Building -First build the fastlz C compression code into a dynamic library: - - ./build_fastlz_lib.sh - -Then build the SWIG wrapper using the following shell script: - - ./build_swig_python_wrapper.sh - -## Evaluating -Test a full round-trip compression and decompression using the wrapper with py.test - - py.test -v - -## Code Files -* C compression code which gets built into a dynamic library - * fastlz.h/.c -* C++ compression wrapper which wraps the C library and gets wrapped by SWIG - * Compress.h/.cpp -* SWIG - * Interface File - * Compress.i - * Distutils script - * setup.py - -## Exercise -Fill in the **TODO:** blocks present in **test_swig.py** diff --git a/swig/fastlz/build_fastlz_lib.sh b/swig/fastlz/build_fastlz_lib.sh deleted file mode 100755 index cad1496..0000000 --- a/swig/fastlz/build_fastlz_lib.sh +++ /dev/null @@ -1,5 +0,0 @@ -# Compile fastlz.c with position-independent code -cc -std=c11 -c -Wall -Werror -g0 -O3 -fpic fastlz.c - -# Create a shared library from an object file -cc -shared -o libfastlz.so fastlz.o diff --git a/swig/fastlz/build_swig_python_wrapper.sh b/swig/fastlz/build_swig_python_wrapper.sh deleted file mode 100755 index 807f0e2..0000000 --- a/swig/fastlz/build_swig_python_wrapper.sh +++ /dev/null @@ -1,2 +0,0 @@ -python setup.py build_ext -python setup.py install --install-platlib=. diff --git a/swig/fastlz/fastlz.c b/swig/fastlz/fastlz.c deleted file mode 100644 index fa3e3ce..0000000 --- a/swig/fastlz/fastlz.c +++ /dev/null @@ -1,551 +0,0 @@ -/* - FastLZ - lightning-fast lossless compression library - - Copyright (C) 2007 Ariya Hidayat (ariya@kde.org) - Copyright (C) 2006 Ariya Hidayat (ariya@kde.org) - Copyright (C) 2005 Ariya Hidayat (ariya@kde.org) - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -#include -#if !defined(FASTLZ__COMPRESSOR) && !defined(FASTLZ_DECOMPRESSOR) - -/* - * Always check for bound when decompressing. - * Generally it is best to leave it defined. - */ -#define FASTLZ_SAFE - -/* - * Give hints to the compiler for branch prediction optimization. - */ -#if defined(__GNUC__) && (__GNUC__ > 2) -#define FASTLZ_EXPECT_CONDITIONAL(c) (__builtin_expect((c), 1)) -#define FASTLZ_UNEXPECT_CONDITIONAL(c) (__builtin_expect((c), 0)) -#else -#define FASTLZ_EXPECT_CONDITIONAL(c) (c) -#define FASTLZ_UNEXPECT_CONDITIONAL(c) (c) -#endif - -/* - * Use inlined functions for supported systems. - */ -#if defined(__GNUC__) || defined(__DMC__) || defined(__POCC__) || defined(__WATCOMC__) || defined(__SUNPRO_C) -#define FASTLZ_INLINE inline -#elif defined(__BORLANDC__) || defined(_MSC_VER) || defined(__LCC__) -#define FASTLZ_INLINE __inline -#else -#define FASTLZ_INLINE -#endif - -/* - * Prevent accessing more than 8-bit at once, except on x86 architectures. - */ -#if !defined(FASTLZ_STRICT_ALIGN) -#define FASTLZ_STRICT_ALIGN -#if defined(__i386__) || defined(__386) /* GNU C, Sun Studio */ -#undef FASTLZ_STRICT_ALIGN -#elif defined(__i486__) || defined(__i586__) || defined(__i686__) /* GNU C */ -#undef FASTLZ_STRICT_ALIGN -#elif defined(_M_IX86) /* Intel, MSVC */ -#undef FASTLZ_STRICT_ALIGN -#elif defined(__386) -#undef FASTLZ_STRICT_ALIGN -#elif defined(_X86_) /* MinGW */ -#undef FASTLZ_STRICT_ALIGN -#elif defined(__I86__) /* Digital Mars */ -#undef FASTLZ_STRICT_ALIGN -#endif -#endif - -/* - * FIXME: use preprocessor magic to set this on different platforms! - */ -typedef unsigned char flzuint8; -typedef unsigned short flzuint16; -typedef unsigned int flzuint32; - -/* prototypes */ -int fastlz_compress(const uint8_t* input, int length, uint8_t* output); -int fastlz_compress_level(int level, const uint8_t* input, int length, uint8_t* output); -int fastlz_decompress(const uint8_t* input, int length, uint8_t* output, int maxout); - -#define MAX_COPY 32 -#define MAX_LEN 264 /* 256 + 8 */ -#define MAX_DISTANCE 8192 - -#if !defined(FASTLZ_STRICT_ALIGN) -#define FASTLZ_READU16(p) *((const flzuint16*)(p)) -#else -#define FASTLZ_READU16(p) ((p)[0] | (p)[1]<<8) -#endif - -#define HASH_LOG 13 -#define HASH_SIZE (1<< HASH_LOG) -#define HASH_MASK (HASH_SIZE-1) -#define HASH_FUNCTION(v,p) { v = FASTLZ_READU16(p); v ^= FASTLZ_READU16(p+1)^(v>>(16-HASH_LOG));v &= HASH_MASK; } - -#undef FASTLZ_LEVEL -#define FASTLZ_LEVEL 1 - -#undef FASTLZ_COMPRESSOR -#undef FASTLZ_DECOMPRESSOR -#define FASTLZ_COMPRESSOR fastlz1_compress -#define FASTLZ_DECOMPRESSOR fastlz1_decompress -static FASTLZ_INLINE int FASTLZ_COMPRESSOR(const uint8_t* input, int length, uint8_t* output); -static FASTLZ_INLINE int FASTLZ_DECOMPRESSOR(const uint8_t* input, int length, uint8_t* output, int maxout); -#include "fastlz.c" - -#undef FASTLZ_LEVEL -#define FASTLZ_LEVEL 2 - -#undef MAX_DISTANCE -#define MAX_DISTANCE 8191 -#define MAX_FARDISTANCE (65535+MAX_DISTANCE-1) - -#undef FASTLZ_COMPRESSOR -#undef FASTLZ_DECOMPRESSOR -#define FASTLZ_COMPRESSOR fastlz2_compress -#define FASTLZ_DECOMPRESSOR fastlz2_decompress -static FASTLZ_INLINE int FASTLZ_COMPRESSOR(const uint8_t* input, int length, uint8_t* output); -static FASTLZ_INLINE int FASTLZ_DECOMPRESSOR(const uint8_t* input, int length, uint8_t* output, int maxout); -#include "fastlz.c" - -int fastlz_compress(const uint8_t* input, int length, uint8_t* output) -{ - /* for short block, choose fastlz1 */ - if(length < 65536) - return fastlz1_compress(input, length, output); - - /* else... */ - return fastlz2_compress(input, length, output); -} - -int fastlz_decompress(const uint8_t* input, int length, uint8_t* output, int maxout) -{ - /* magic identifier for compression level */ - int level = ((*(const flzuint8*)input) >> 5) + 1; - - if(level == 1) - return fastlz1_decompress(input, length, output, maxout); - if(level == 2) - return fastlz2_decompress(input, length, output, maxout); - - /* unknown level, trigger error */ - return 0; -} - -int fastlz_compress_level(int level, const uint8_t* input, int length, uint8_t* output) -{ - if(level == 1) - return fastlz1_compress(input, length, output); - if(level == 2) - return fastlz2_compress(input, length, output); - - return 0; -} - -#else /* !defined(FASTLZ_COMPRESSOR) && !defined(FASTLZ_DECOMPRESSOR) */ - -static FASTLZ_INLINE int FASTLZ_COMPRESSOR(const uint8_t* input, int length, uint8_t* output) -{ - const flzuint8* ip = (const flzuint8*) input; - const flzuint8* ip_bound = ip + length - 2; - const flzuint8* ip_limit = ip + length - 12; - flzuint8* op = (flzuint8*) output; - - const flzuint8* htab[HASH_SIZE]; - const flzuint8** hslot; - flzuint32 hval; - - flzuint32 copy; - - /* sanity check */ - if(FASTLZ_UNEXPECT_CONDITIONAL(length < 4)) - { - if(length) - { - /* create literal copy only */ - *op++ = length-1; - ip_bound++; - while(ip <= ip_bound) - *op++ = *ip++; - return length+1; - } - else - return 0; - } - - /* initializes hash table */ - for (hslot = htab; hslot < htab + HASH_SIZE; hslot++) - *hslot = ip; - - /* we start with literal copy */ - copy = 2; - *op++ = MAX_COPY-1; - *op++ = *ip++; - *op++ = *ip++; - - /* main loop */ - while(FASTLZ_EXPECT_CONDITIONAL(ip < ip_limit)) - { - const flzuint8* ref; - flzuint32 distance; - - /* minimum match length */ - flzuint32 len = 3; - - /* comparison starting-point */ - const flzuint8* anchor = ip; - - /* check for a run */ -#if FASTLZ_LEVEL==2 - if(ip[0] == ip[-1] && FASTLZ_READU16(ip-1)==FASTLZ_READU16(ip+1)) - { - distance = 1; - ip += 3; - ref = anchor - 1 + 3; - goto match; - } -#endif - - /* find potential match */ - HASH_FUNCTION(hval,ip); - hslot = htab + hval; - ref = htab[hval]; - - /* calculate distance to the match */ - distance = anchor - ref; - - /* update hash table */ - *hslot = anchor; - - /* is this a match? check the first 3 bytes */ - if(distance==0 || -#if FASTLZ_LEVEL==1 - (distance >= MAX_DISTANCE) || -#else - (distance >= MAX_FARDISTANCE) || -#endif - *ref++ != *ip++ || *ref++!=*ip++ || *ref++!=*ip++) - goto literal; - -#if FASTLZ_LEVEL==2 - /* far, needs at least 5-byte match */ - if(distance >= MAX_DISTANCE) - { - if(*ip++ != *ref++ || *ip++!= *ref++) - goto literal; - len += 2; - } - - match: -#endif - - /* last matched byte */ - ip = anchor + len; - - /* distance is biased */ - distance--; - - if(!distance) - { - /* zero distance means a run */ - flzuint8 x = ip[-1]; - while(ip < ip_bound) - if(*ref++ != x) break; else ip++; - } - else - for(;;) - { - /* safe because the outer check against ip limit */ - if(*ref++ != *ip++) break; - if(*ref++ != *ip++) break; - if(*ref++ != *ip++) break; - if(*ref++ != *ip++) break; - if(*ref++ != *ip++) break; - if(*ref++ != *ip++) break; - if(*ref++ != *ip++) break; - if(*ref++ != *ip++) break; - while(ip < ip_bound) - if(*ref++ != *ip++) break; - break; - } - - /* if we have copied something, adjust the copy count */ - if(copy) - /* copy is biased, '0' means 1 byte copy */ - *(op-copy-1) = copy-1; - else - /* back, to overwrite the copy count */ - op--; - - /* reset literal counter */ - copy = 0; - - /* length is biased, '1' means a match of 3 bytes */ - ip -= 3; - len = ip - anchor; - - /* encode the match */ -#if FASTLZ_LEVEL==2 - if(distance < MAX_DISTANCE) - { - if(len < 7) - { - *op++ = (len << 5) + (distance >> 8); - *op++ = (distance & 255); - } - else - { - *op++ = (7 << 5) + (distance >> 8); - for(len-=7; len >= 255; len-= 255) - *op++ = 255; - *op++ = len; - *op++ = (distance & 255); - } - } - else - { - /* far away, but not yet in the another galaxy... */ - if(len < 7) - { - distance -= MAX_DISTANCE; - *op++ = (len << 5) + 31; - *op++ = 255; - *op++ = distance >> 8; - *op++ = distance & 255; - } - else - { - distance -= MAX_DISTANCE; - *op++ = (7 << 5) + 31; - for(len-=7; len >= 255; len-= 255) - *op++ = 255; - *op++ = len; - *op++ = 255; - *op++ = distance >> 8; - *op++ = distance & 255; - } - } -#else - - if(FASTLZ_UNEXPECT_CONDITIONAL(len > MAX_LEN-2)) - while(len > MAX_LEN-2) - { - *op++ = (7 << 5) + (distance >> 8); - *op++ = MAX_LEN - 2 - 7 -2; - *op++ = (distance & 255); - len -= MAX_LEN-2; - } - - if(len < 7) - { - *op++ = (len << 5) + (distance >> 8); - *op++ = (distance & 255); - } - else - { - *op++ = (7 << 5) + (distance >> 8); - *op++ = len - 7; - *op++ = (distance & 255); - } -#endif - - /* update the hash at match boundary */ - HASH_FUNCTION(hval,ip); - htab[hval] = ip++; - HASH_FUNCTION(hval,ip); - htab[hval] = ip++; - - /* assuming literal copy */ - *op++ = MAX_COPY-1; - - continue; - - literal: - *op++ = *anchor++; - ip = anchor; - copy++; - if(FASTLZ_UNEXPECT_CONDITIONAL(copy == MAX_COPY)) - { - copy = 0; - *op++ = MAX_COPY-1; - } - } - - /* left-over as literal copy */ - ip_bound++; - while(ip <= ip_bound) - { - *op++ = *ip++; - copy++; - if(copy == MAX_COPY) - { - copy = 0; - *op++ = MAX_COPY-1; - } - } - - /* if we have copied something, adjust the copy length */ - if(copy) - *(op-copy-1) = copy-1; - else - op--; - -#if FASTLZ_LEVEL==2 - /* marker for fastlz2 */ - *(flzuint8*)output |= (1 << 5); -#endif - - return op - (flzuint8*)output; -} - -static FASTLZ_INLINE int FASTLZ_DECOMPRESSOR(const uint8_t* input, int length, uint8_t* output, int maxout) -{ - const flzuint8* ip = (const flzuint8*) input; - const flzuint8* ip_limit = ip + length; - flzuint8* op = (flzuint8*) output; - flzuint8* op_limit = op + maxout; - flzuint32 ctrl = (*ip++) & 31; - int loop = 1; - - do - { - const flzuint8* ref = op; - flzuint32 len = ctrl >> 5; - flzuint32 ofs = (ctrl & 31) << 8; - - if(ctrl >= 32) - { -#if FASTLZ_LEVEL==2 - flzuint8 code; -#endif - len--; - ref -= ofs; - if (len == 7-1) -#if FASTLZ_LEVEL==1 - len += *ip++; - ref -= *ip++; -#else - do - { - code = *ip++; - len += code; - } while (code==255); - code = *ip++; - ref -= code; - - /* match from 16-bit distance */ - if(FASTLZ_UNEXPECT_CONDITIONAL(code==255)) - if(FASTLZ_EXPECT_CONDITIONAL(ofs==(31 << 8))) - { - ofs = (*ip++) << 8; - ofs += *ip++; - ref = op - ofs - MAX_DISTANCE; - } -#endif - -#ifdef FASTLZ_SAFE - if (FASTLZ_UNEXPECT_CONDITIONAL(op + len + 3 > op_limit)) - return 0; - - if (FASTLZ_UNEXPECT_CONDITIONAL(ref-1 < (flzuint8 *)output)) - return 0; -#endif - - if(FASTLZ_EXPECT_CONDITIONAL(ip < ip_limit)) - ctrl = *ip++; - else - loop = 0; - - if(ref == op) - { - /* optimize copy for a run */ - flzuint8 b = ref[-1]; - *op++ = b; - *op++ = b; - *op++ = b; - for(; len; --len) - *op++ = b; - } - else - { -#if !defined(FASTLZ_STRICT_ALIGN) - const flzuint16* p; - flzuint16* q; -#endif - /* copy from reference */ - ref--; - *op++ = *ref++; - *op++ = *ref++; - *op++ = *ref++; - -#if !defined(FASTLZ_STRICT_ALIGN) - /* copy a byte, so that now it's word aligned */ - if(len & 1) - { - *op++ = *ref++; - len--; - } - - /* copy 16-bit at once */ - q = (flzuint16*) op; - op += len; - p = (const flzuint16*) ref; - for(len>>=1; len > 4; len-=4) - { - *q++ = *p++; - *q++ = *p++; - *q++ = *p++; - *q++ = *p++; - } - for(; len; --len) - *q++ = *p++; -#else - for(; len; --len) - *op++ = *ref++; -#endif - } - } - else - { - ctrl++; -#ifdef FASTLZ_SAFE - if (FASTLZ_UNEXPECT_CONDITIONAL(op + ctrl > op_limit)) - return 0; - if (FASTLZ_UNEXPECT_CONDITIONAL(ip + ctrl > ip_limit)) - return 0; -#endif - - *op++ = *ip++; - for(--ctrl; ctrl; ctrl--) - *op++ = *ip++; - - loop = FASTLZ_EXPECT_CONDITIONAL(ip < ip_limit); - if(loop) - ctrl = *ip++; - } - } - while(FASTLZ_EXPECT_CONDITIONAL(loop)); - - return op - (flzuint8*)output; -} - -#endif /* !defined(FASTLZ_COMPRESSOR) && !defined(FASTLZ_DECOMPRESSOR) */ diff --git a/swig/fastlz/fastlz.h b/swig/fastlz/fastlz.h deleted file mode 100644 index 8e4977f..0000000 --- a/swig/fastlz/fastlz.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - FastLZ - lightning-fast lossless compression library - - Copyright (C) 2007 Ariya Hidayat (ariya@kde.org) - Copyright (C) 2006 Ariya Hidayat (ariya@kde.org) - Copyright (C) 2005 Ariya Hidayat (ariya@kde.org) - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. -*/ -#ifndef FASTLZ_H -#define FASTLZ_H - -#define FASTLZ_VERSION 0x000100 - -#define FASTLZ_VERSION_MAJOR 0 -#define FASTLZ_VERSION_MINOR 0 -#define FASTLZ_VERSION_REVISION 0 - -#define FASTLZ_VERSION_STRING "0.1.0" - -#if defined (__cplusplus) -extern "C" { -#endif - -/** - Compress a block of data in the input buffer and returns the size of - compressed block. The size of input buffer is specified by length. The - minimum input buffer size is 16. - - The output buffer must be at least 5% larger than the input buffer - and can not be smaller than 66 bytes. - - If the input is not compressible, the return value might be larger than - length (input buffer size). - - The input buffer and the output buffer can not overlap. -*/ - -int fastlz_compress(const void* input, int length, void* output); - -/** - Decompress a block of compressed data and returns the size of the - decompressed block. If error occurs, e.g. the compressed data is - corrupted or the output buffer is not large enough, then 0 (zero) - will be returned instead. - - The input buffer and the output buffer can not overlap. - - Decompression is memory safe and guaranteed not to write the output buffer - more than what is specified in maxout. - */ - -int fastlz_decompress(const void* input, int length, void* output, int maxout); - -/** - Compress a block of data in the input buffer and returns the size of - compressed block. The size of input buffer is specified by length. The - minimum input buffer size is 16. - - The output buffer must be at least 5% larger than the input buffer - and can not be smaller than 66 bytes. - - If the input is not compressible, the return value might be larger than - length (input buffer size). - - The input buffer and the output buffer can not overlap. - - Compression level can be specified in parameter level. At the moment, - only level 1 and level 2 are supported. - Level 1 is the fastest compression and generally useful for short data. - Level 2 is slightly slower but it gives better compression ratio. - - Note that the compressed data, regardless of the level, can always be - decompressed using the function fastlz_decompress above. -*/ - -int fastlz_compress_level(int level, const void* input, int length, void* output); - -#if defined (__cplusplus) -} -#endif - -#endif /* FASTLZ_H */ diff --git a/swig/fastlz/setup.py b/swig/fastlz/setup.py deleted file mode 100644 index a9be164..0000000 --- a/swig/fastlz/setup.py +++ /dev/null @@ -1,16 +0,0 @@ -# coding=utf-8 -from distutils.core import setup, Extension - -name = "Compress" # name of the module -version = "1.0" # the module's version number - -setup(name=name, version=version, - # distutils detects .i files and compiles them automatically - ext_modules=[Extension(name='_{}'.format(name), # SWIG requires _ as a prefix for the module name - sources=["Compress.i", "Compress.cpp"], - include_dirs=[], - libraries=['fastlz'], - library_dirs=['.'], - extra_compile_args=["-std=c++11"], - swig_opts=['-c++']) - ]) diff --git a/swig/fastlz/test_swig.py b/swig/fastlz/test_swig.py deleted file mode 100644 index 915e317..0000000 --- a/swig/fastlz/test_swig.py +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/env python -# coding=utf-8 -""" pytest unit test for the SWIG wrapper for compressing and decompressing -using the fastlz C library. -""" -import numpy as np -from Compress import VectorUint8, Compress, Decompress - - -def test_compress_and_decompress_roundtrip(): - # Beginning of the United States Constitution - text ="""We the People of the United States, in Order to form a more perfect Union, establish Justice, insure domestic Tranquility, provide for the common defence, promote the general Welfare, and secure the Blessings of Liberty to ourselves and our Posterity, do ordain and establish this Constitution for the United States of America. - -Article I (Article 1 - Legislative) -Section 1 -All legislative Powers herein granted shall be vested in a Congress of the United States, which shall consist of a Senate and House of Representatives. - -Section 2 -1: The House of Representatives shall be composed of Members chosen every second Year by the People of the several States, and the Electors in each State shall have the Qualifications requisite for Electors of the most numerous Branch of the State Legislature. - -2: No Person shall be a Representative who shall not have attained to the Age of twenty five Years, and been seven Years a Citizen of the United States, and who shall not, when elected, be an Inhabitant of that State in which he shall be chosen. - -3: Representatives and direct Taxes shall be apportioned among the several States which may be included within this Union, according to their respective Numbers, which shall be determined by adding to the whole Number of free Persons, including those bound to Service for a Term of Years, and excluding Indians not taxed, three fifths of all other Persons.2 The actual Enumeration shall be made within three Years after the first Meeting of the Congress of the United States, and within every subsequent Term of ten Years, in such Manner as they shall by Law direct. The Number of Representatives shall not exceed one for every thirty Thousand, but each State shall have at Least one Representative; and until such enumeration shall be made, the State of New Hampshire shall be entitled to chuse three, Massachusetts eight, Rhode-Island and Providence Plantations one, Connecticut five, New-York six, New Jersey four, Pennsylvania eight, Delaware one, Maryland six, Virginia ten, North Carolina five, South Carolina five, and Georgia three. - -4: When vacancies happen in the Representation from any State, the Executive Authority thereof shall issue Writs of Election to fill such Vacancies. - -5: The House of Representatives shall chuse their Speaker and other Officers; and shall have the sole Power of Impeachment.""" - - # TODO: Convert the text to a VectorUint8 which can be passed to Compress - - # TODO: Create a vector to store the compressed data - - # Compress the input text - success = Compress(text_vec, compressed_vec) - assert success - - # Verify that the compressed text is actually smaller than the original - assert len(compressed_vec) < len(text_vec) - - # TODO: Create a vector for the reconstructed text - - # Decmopress the compressed text to reconstruct a vector of original bytes - success = Decompress(compressed_vec, recon_vec) - assert success - - # TODO: Convert the reconstructed text to a bytes - - # TODO: And finally back to a str - - # Verify the reconstructed text is the same as the original - assert text == reconstructed diff --git a/swig/fibonacci/.gitignore b/swig/fibonacci/.gitignore deleted file mode 100644 index 6471107..0000000 --- a/swig/fibonacci/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -fibonacci_c -fibonacci.py -fibonacci_wrap.c -*.egg-info -*.o -Makefile -*.bundle -.RUBYARCHDIR.time diff --git a/swig/fibonacci/CMakeLists.txt b/swig/fibonacci/CMakeLists.txt deleted file mode 100644 index eeff4ac..0000000 --- a/swig/fibonacci/CMakeLists.txt +++ /dev/null @@ -1,20 +0,0 @@ -# This is a CMake example for SWIG and Python -cmake_minimum_required(VERSION 3.8) - -FIND_PACKAGE(SWIG REQUIRED) -INCLUDE(${SWIG_USE_FILE}) - -FIND_PACKAGE(PythonLibs) -INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH}) - -INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) - -SET(CMAKE_SWIG_FLAGS "") - -SET_SOURCE_FILES_PROPERTIES(fibonacci.i PROPERTIES SWIG_FLAGS "-includeall") - -SWIG_ADD_LIBRARY(fibonacci - LANGUAGE python - SOURCES fibonacci.i fibonacci.c) - -SWIG_LINK_LIBRARIES(fibonacci ${PYTHON_LIBRARIES}) diff --git a/swig/fibonacci/Readme.md b/swig/fibonacci/Readme.md deleted file mode 100644 index a26d2fd..0000000 --- a/swig/fibonacci/Readme.md +++ /dev/null @@ -1,32 +0,0 @@ -# Interfacing with C code from Python using SWIG -Example code for interfacing with C code from Python using SWIG. - - -## Building - -### Mac OS X or Linus -Build the SWIG wrapper using the following shell script: - - ./build_swig_python_wrapper.sh - -### Windows -Build the SWIG wrapper using the following batch file: - - build_swig_python_wrapper.bat - - -## Evaluating -Compare the results of a pure Python implementation to that of the SWIG wrapper using: - - ./test_swig.py - -## Code Files -* Pure Python implementation - * fib_python.py -* C implementation - * fibonacci.h/.c -* SWIG - * Interface File - * fibonacci.i - * Distutils script - * setup.py diff --git a/swig/fibonacci/build_c.sh b/swig/fibonacci/build_c.sh deleted file mode 100755 index 351d419..0000000 --- a/swig/fibonacci/build_c.sh +++ /dev/null @@ -1 +0,0 @@ -cc -std=c11 -Wall -Wextra -g0 -O3 -o fibonacci_c fibonacci.c diff --git a/swig/fibonacci/build_swig_python_wrapper.bat b/swig/fibonacci/build_swig_python_wrapper.bat deleted file mode 100755 index 35154d4..0000000 --- a/swig/fibonacci/build_swig_python_wrapper.bat +++ /dev/null @@ -1 +0,0 @@ -python setup.py build_ext --inplace diff --git a/swig/fibonacci/build_swig_python_wrapper.sh b/swig/fibonacci/build_swig_python_wrapper.sh deleted file mode 100755 index 35154d4..0000000 --- a/swig/fibonacci/build_swig_python_wrapper.sh +++ /dev/null @@ -1 +0,0 @@ -python setup.py build_ext --inplace diff --git a/swig/fibonacci/build_swig_ruby_wrapper.sh b/swig/fibonacci/build_swig_ruby_wrapper.sh deleted file mode 100755 index b39c89c..0000000 --- a/swig/fibonacci/build_swig_ruby_wrapper.sh +++ /dev/null @@ -1,4 +0,0 @@ -swig -ruby fibonacci.i -ruby extconf.rb -make -sudo make install diff --git a/swig/fibonacci/extconf.rb b/swig/fibonacci/extconf.rb deleted file mode 100644 index cb176d2..0000000 --- a/swig/fibonacci/extconf.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'mkmf' - -$CFLAGS << ' -std=c11 -Wall -Wextra -g0 -O3 ' - -create_makefile('fibonacci') diff --git a/swig/fibonacci/fib_python.py b/swig/fibonacci/fib_python.py deleted file mode 100755 index 527dc7f..0000000 --- a/swig/fibonacci/fib_python.py +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env python -# coding=utf-8 -""" Pure Python implementation for computing the nth fibonacci number in a -non-recursive fashion. -""" - - -def compute_fibonacci(n): - """ - Computes fibonacci sequence - """ - a = 1 - b = 1 - intermediate = 0 - for x in range(n): - intermediate = a - a = a + b - b = intermediate - return a - - -if __name__ == '__main__': - import sys - import timeit - - n = 20 - try: - n = int(sys.argv[1]) - except Exception: - pass - - fib_n = compute_fibonacci(n) - - number_of_times = 100000 - try: - number_of_times = int(sys.argv[2]) - except Exception: - pass - - total_time = timeit.timeit("compute_fibonacci({})".format(n), - setup="from __main__ import compute_fibonacci", - number=number_of_times) - avg_time = total_time / number_of_times - print("fib({0}) = {1} [average execution time: {2:.2g} s]".format(n, fib_n, avg_time)) diff --git a/swig/fibonacci/fibonacci.c b/swig/fibonacci/fibonacci.c deleted file mode 100644 index 9e95ea3..0000000 --- a/swig/fibonacci/fibonacci.c +++ /dev/null @@ -1,61 +0,0 @@ -/* File : fibonacci.c - * - * Implementation of the algorithm in C - */ -#include // printf() -#include // atoi() -#include // clock_t, clock() - -int compute_fibonacci(int n) -{ - int temp; - int a = 1; - int b = 1; - for (int x=0; x 1) - { - n = atoi(argv[1]); - } - - int number_of_times = 100000; - if (argc > 2) - { - number_of_times = atoi(argv[2]); - } - - int fib_n = compute_fibonacci(n); - - // Compute single execution time - clock_t begin = clock(); - compute_fibonacci(n); - clock_t end = clock(); - double single_time = (double)(end - begin) / CLOCKS_PER_SEC; - printf("single execution time: %.2g s\n", single_time); - - // Compute average execution time over many times - double time_spent = 0; - for (int i = 0; i < number_of_times; i++) - { - begin = clock(); - compute_fibonacci(n); - end = clock(); - time_spent += (double)(end - begin) / CLOCKS_PER_SEC; - } - double avg_time = time_spent / number_of_times; - - printf("fib(%d) = %d [average execution time: %.2g s]\n", n, fib_n, avg_time); - - return EXIT_SUCCESS; -} diff --git a/swig/fibonacci/fibonacci.h b/swig/fibonacci/fibonacci.h deleted file mode 100644 index 740f255..0000000 --- a/swig/fibonacci/fibonacci.h +++ /dev/null @@ -1,7 +0,0 @@ -/* File : fibonacci.h - * - * Header declaring the public interface. - */ - -#pragma once -extern int compute_fibonacci(int n); diff --git a/swig/fibonacci/fibonacci.i b/swig/fibonacci/fibonacci.i deleted file mode 100644 index f48d49b..0000000 --- a/swig/fibonacci/fibonacci.i +++ /dev/null @@ -1,9 +0,0 @@ -/* fibonacci.i */ - %module fibonacci - %{ - /* Includes the header in the wrapper code */ - #include "fibonacci.h" - %} - -/* Parse the header file to generate wrappers */ - %include "fibonacci.h" diff --git a/swig/fibonacci/setup.py b/swig/fibonacci/setup.py deleted file mode 100644 index 7511b00..0000000 --- a/swig/fibonacci/setup.py +++ /dev/null @@ -1,14 +0,0 @@ -# coding=utf-8 -from distutils.core import setup, Extension - -name = "fibonacci" # name of the module -version = "1.0" # the module's version number - -setup(name=name, version=version, - # distutils detects .i files and compiles them automatically - ext_modules=[Extension(name='_{}'.format(name), # SWIG requires _ as a prefix for the module name - sources=["fibonacci.i", "fibonacci.c"], - include_dirs=[], - extra_compile_args=["-std=c11"], - swig_opts=[]) - ]) diff --git a/swig/fibonacci/test_swig.py b/swig/fibonacci/test_swig.py deleted file mode 100755 index e81ad05..0000000 --- a/swig/fibonacci/test_swig.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env python -# coding=utf-8 -""" Python wrapper to time the SWIG wrapper for computing the nth fibonacci number -in a non-recursive fashion and compare it to the pure Python implementation. -""" -import fibonacci -import fib_python - -if __name__ == '__main__': - import sys - import timeit - - n = 20 - try: - n = int(sys.argv[1]) - except Exception: - pass - - number_of_times = 100000 - try: - number_of_times = int(sys.argv[2]) - except Exception: - pass - - fib_py = fib_python.compute_fibonacci(n) - fib_swig = fibonacci.compute_fibonacci(n) - if fib_py != fib_swig: - raise (ValueError(fib_swig)) - - py_tot = timeit.timeit("compute_fibonacci({})".format(n), - setup="from fib_python import compute_fibonacci", - number=number_of_times) - swig_tot = timeit.timeit("compute_fibonacci({})".format(n), - setup="from fibonacci import compute_fibonacci", - number=number_of_times) - py_avg = py_tot / number_of_times - swig_avg = swig_tot / number_of_times - - print("fib({}) = {}".format(n, fib_py)) - print("Python average time: {0:.2g}".format(py_avg)) - print("SWIG/C average time: {0:.2g}".format(swig_avg)) - print("SWIG/C speedup: {0:.2g} times".format(py_avg / swig_avg)) diff --git a/swig/fibonacci/test_swig.rb b/swig/fibonacci/test_swig.rb deleted file mode 100755 index ba635fb..0000000 --- a/swig/fibonacci/test_swig.rb +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env ruby - -# The feature name begins with a lowercase letter... -require 'fibonacci' - -# ... but the module name begins with an uppercase letter -puts "fib(20): #{Fibonacci.compute_fibonacci(20)}" diff --git a/swig/logger/.gitignore b/swig/logger/.gitignore deleted file mode 100644 index 6b78145..0000000 --- a/swig/logger/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -*.egg-info -example.py -example_wrap.* - diff --git a/swig/logger/Readme.md b/swig/logger/Readme.md deleted file mode 100644 index 6eeef70..0000000 --- a/swig/logger/Readme.md +++ /dev/null @@ -1,37 +0,0 @@ -# Cross-language polymorphism -This example demonstrates cross language polymorphism using SWIG directors. - -This allows you to define a base class in C++ which contains some virtual methods. Then you can -derive from that class in Python. Then you instantiate a C++ object from Python where this C++ -object takes a pointer to the base class type. Then you can call a virtual method from C++. - -If a base class type was used, then it calls the C++ virtual method. But if a Python derived class -is used, it calls the Python virtual method from C++! If this doesn't blow your mind at least a -little bit, then I don't think you understand what is going on, go through the example more -slowly until your mind is blown ;-) - - -## Building -Build the SWIG wrapper using the following shell script: - - ./build_swig.sh - -## Evaluating -The **runme.py** example constructs the class first using a base class type as implemented in C++, then -using a derived class type as implemented in Python. - - ./runme.py - -## Code Files -* C++ implementation - * example.h/.cpp -* SWIG - * Interface File - * example.i - * Distutils script - * setup.py -* Test code to run it all - * runme.py - -## Exercise -Fill in the **TODO:** blocks present in **runme.py**. diff --git a/swig/logger/build_swig.sh b/swig/logger/build_swig.sh deleted file mode 100755 index 807f0e2..0000000 --- a/swig/logger/build_swig.sh +++ /dev/null @@ -1,2 +0,0 @@ -python setup.py build_ext -python setup.py install --install-platlib=. diff --git a/swig/logger/example.cpp b/swig/logger/example.cpp deleted file mode 100644 index 96e1d9d..0000000 --- a/swig/logger/example.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/* File : example.cxx */ - -#include "example.h" - -Logger::~Logger() -{ - std::cout << "Logger::~Logger()" << std:: endl; -} - -void Logger::log(int level, std::string message) -{ - std::cout << "C++ Logger - Level: "; - - switch(level) - { - case LOG_ERROR: - std::cout << "ERROR"; - break; - case LOG_WARNING: - std::cout << "WARNING"; - break; - case LOG_INFO: - std::cout << "INFO"; - break; - default: - std::cout << "UNKNOWN"; - break; - } - - std::cout << ", message: " << message << std::endl; -} diff --git a/swig/logger/example.h b/swig/logger/example.h deleted file mode 100644 index 87861bf..0000000 --- a/swig/logger/example.h +++ /dev/null @@ -1,37 +0,0 @@ -/* File : example.h */ - -#include -#include - - -enum LOG_LEVEL -{ - LOG_INFO = 20, - LOG_WARNING = 30, - LOG_ERROR = 40 -}; - - -class Logger -{ -public: - virtual ~Logger(); - virtual void log(int level, std::string message); -}; - - -class Log -{ -private: - Logger *_logger; -public: - Log(): _logger(nullptr) {} - ~Log() { delLogger(); } - void delLogger() { delete _logger; _logger = nullptr; } - void setLogger(Logger *cb) { delLogger(); _logger = cb; } - void log(int level, std::string msg) { if (_logger) _logger->log(level, msg); } - void err(std::string msg) {log(LOG_ERROR, msg);} - void war(std::string msg) {log(LOG_WARNING, msg);} - void inf(std::string msg) {log(LOG_INFO, msg);} -}; - diff --git a/swig/logger/example.i b/swig/logger/example.i deleted file mode 100644 index 1e68d4c..0000000 --- a/swig/logger/example.i +++ /dev/null @@ -1,14 +0,0 @@ -/* File : example.i */ -%module(directors="1") example -%{ -#include "example.h" -%} - -/* The std_string.i library provides typemaps for converting C++ std::string objects to and from Python strings */ -%include "std_string.i" - -/* turn on director wrapping Logger - directors enable cross-language polymorphism */ -%feature("director") Logger; - -%include "example.h" - diff --git a/swig/logger/runme.py b/swig/logger/runme.py deleted file mode 100755 index 512a20d..0000000 --- a/swig/logger/runme.py +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env python -""" -This file illustrates the cross language polymorphism using SWIG directors. -""" -from colorama import Fore -import logging - -import example - - -class PyLogger(example.Logger): - - def __init__(self): - example.Logger.__init__(self) - - # Configure Python logging module root logger - logging.basicConfig(format='%(asctime)s %(levelname)s: %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p', - level=logging.INFO) - - def log(self, level, message): - if level == logging.ERROR: - message = Fore.RED + message + Fore.RESET - elif level == logging.WARNING: - message = Fore.YELLOW + message + Fore.RESET - logging.log(level, message) - - -if __name__ == '__main__': - # Create an instance of the C++ Log class, which has a pointer to a C++ Logger class within it - log = example.Log() - - # Add a simple C++ Logger (log owns the Logger, so we disown it first by clearing the .thisown flag). - print("Adding and calling a normal C++ Logger") - print("--------------------------------------") - logger = example.Logger() - logger.thisown = 0 - log.setLogger(logger) - log.inf("Hello") - log.war("World") - log.log(5, "Yo") - log.delLogger() - - # Add a Python Logger (log owns the logger, so we disown it first by calling __disown__). - print() - print("Adding and calling a Python Logger") - print("----------------------------------") - # TODO: Add a Python Logger (make sure to call .__disown__() on it - # TODO: Set the Logger to this new Python Logger - # TODO: Log a mix of ERROR, INFO, and WARNING messages - # TODO: Don't forget to delete the logger to prevent a memory leak - - # All done. - print() - print("python exit") diff --git a/swig/logger/setup.py b/swig/logger/setup.py deleted file mode 100644 index 41541f1..0000000 --- a/swig/logger/setup.py +++ /dev/null @@ -1,14 +0,0 @@ -# coding=utf-8 -from distutils.core import setup, Extension - -name = "example" # name of the module -version = "1.0" # the module's version number - -setup(name=name, version=version, - # distutils detects .i files and compiles them automatically - ext_modules=[Extension(name='_{}'.format(name), # SWIG requires _ as a prefix for the module name - sources=["example.i", "example.cpp"], - include_dirs=[], - extra_compile_args=["-std=c++11"], - swig_opts=['-c++']) - ]) diff --git a/swig/structs/.gitignore b/swig/structs/.gitignore deleted file mode 100644 index 6471107..0000000 --- a/swig/structs/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -fibonacci_c -fibonacci.py -fibonacci_wrap.c -*.egg-info -*.o -Makefile -*.bundle -.RUBYARCHDIR.time diff --git a/swig/structs/Readme.md b/swig/structs/Readme.md deleted file mode 100644 index e3e4e7b..0000000 --- a/swig/structs/Readme.md +++ /dev/null @@ -1,23 +0,0 @@ -# Interfacing with C code from Python using SWIG -Example code for interfacing with C code from Python using SWIG. - -## Building -Build the SWIG wrapper using the following shell script: - - ./build_swig_python_wrapper.sh - -## Evaluating -Compare the results of a pure Python implementation to that of the SWIG wrapper using: - - ./test_swig.py - -## Code Files -* Pure Python implementation - * fib_python.py -* C implementation - * fibonacci.h/.c -* SWIG - * Interface File - * fibonacci.i - * Distutils script - * setup.py diff --git a/swig/structs/build_c.sh b/swig/structs/build_c.sh deleted file mode 100755 index 351d419..0000000 --- a/swig/structs/build_c.sh +++ /dev/null @@ -1 +0,0 @@ -cc -std=c11 -Wall -Wextra -g0 -O3 -o fibonacci_c fibonacci.c diff --git a/swig/structs/build_swig_python_wrapper.sh b/swig/structs/build_swig_python_wrapper.sh deleted file mode 100755 index 807f0e2..0000000 --- a/swig/structs/build_swig_python_wrapper.sh +++ /dev/null @@ -1,2 +0,0 @@ -python setup.py build_ext -python setup.py install --install-platlib=. diff --git a/swig/structs/clean.sh b/swig/structs/clean.sh deleted file mode 100755 index d0b49a3..0000000 --- a/swig/structs/clean.sh +++ /dev/null @@ -1,12 +0,0 @@ -# Remove the C binary -rm fibonacci_c - -# Cleanup SWIG wrapper stuff -rm -rf build -rm *.egg-info -rm *.so -rm fibonacci.py -rm fibonacci_wrap.c - -# Remove *.pyc files -rm -rf __pycache__ diff --git a/swig/structs/fib_python.py b/swig/structs/fib_python.py deleted file mode 100755 index 527dc7f..0000000 --- a/swig/structs/fib_python.py +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env python -# coding=utf-8 -""" Pure Python implementation for computing the nth fibonacci number in a -non-recursive fashion. -""" - - -def compute_fibonacci(n): - """ - Computes fibonacci sequence - """ - a = 1 - b = 1 - intermediate = 0 - for x in range(n): - intermediate = a - a = a + b - b = intermediate - return a - - -if __name__ == '__main__': - import sys - import timeit - - n = 20 - try: - n = int(sys.argv[1]) - except Exception: - pass - - fib_n = compute_fibonacci(n) - - number_of_times = 100000 - try: - number_of_times = int(sys.argv[2]) - except Exception: - pass - - total_time = timeit.timeit("compute_fibonacci({})".format(n), - setup="from __main__ import compute_fibonacci", - number=number_of_times) - avg_time = total_time / number_of_times - print("fib({0}) = {1} [average execution time: {2:.2g} s]".format(n, fib_n, avg_time)) diff --git a/swig/structs/fibonacci.c b/swig/structs/fibonacci.c deleted file mode 100644 index 7e85929..0000000 --- a/swig/structs/fibonacci.c +++ /dev/null @@ -1,79 +0,0 @@ -/* File : fibonacci.c - * - * Implementation of the algorithm in C - */ -#include "fibonacci.h" - -#include // printf() -#include // atoi() -#include // clock_t, clock() - -int compute_fibonacci(int n) -{ - int temp; - int a = 1; - int b = 1; - for (int x=0; x 1) - { - n = atoi(argv[1]); - } - - int number_of_times = 100000; - if (argc > 2) - { - number_of_times = atoi(argv[2]); - } - - int fib_n = compute_fibonacci(n); - - // Compute single execution time - clock_t begin = clock(); - compute_fibonacci(n); - clock_t end = clock(); - double single_time = (double)(end - begin) / CLOCKS_PER_SEC; - printf("single execution time: %.2g s\n", single_time); - - // Compute average execution time over many times - double time_spent = 0; - for (int i = 0; i < number_of_times; i++) - { - begin = clock(); - compute_fibonacci(n); - end = clock(); - time_spent += (double)(end - begin) / CLOCKS_PER_SEC; - } - double avg_time = time_spent / number_of_times; - - printf("fib(%d) = %d [average execution time: %.2g s]\n", n, fib_n, avg_time); - - - // Create and populate a struct - struct MsgMetaData myStruct = populate_struct(1, 2, 3); - - printf("msg type = %d, job id = %d, msg size = %d\n", myStruct.type, myStruct.job, - myStruct.size); - - return EXIT_SUCCESS; -} diff --git a/swig/structs/fibonacci.h b/swig/structs/fibonacci.h deleted file mode 100644 index 9d95e09..0000000 --- a/swig/structs/fibonacci.h +++ /dev/null @@ -1,21 +0,0 @@ -/* File : fibonacci.h - * - * Header declaring the public interface. - */ - -#pragma once - -#include - -typedef uint32_t dtype; - -struct MsgMetaData -{ - dtype type; // Message Type - dtype job; // Job ID - dtype size; // Message Size (not including the metadata header) -}; - -extern int compute_fibonacci(int n); - -struct MsgMetaData populate_struct(dtype msgType, dtype jobId, dtype msgSize); diff --git a/swig/structs/fibonacci.i b/swig/structs/fibonacci.i deleted file mode 100644 index 697074d..0000000 --- a/swig/structs/fibonacci.i +++ /dev/null @@ -1,12 +0,0 @@ -/* fibonacci.i */ - %module fibonacci - %{ - /* Includes the header in the wrapper code */ - #include "fibonacci.h" - %} - -// Include types such as uint32_t, uint8_t, etc. - %include "stdint.i" - -/* Parse the header file to generate wrappers */ - %include "fibonacci.h" diff --git a/swig/structs/setup.py b/swig/structs/setup.py deleted file mode 100644 index 7511b00..0000000 --- a/swig/structs/setup.py +++ /dev/null @@ -1,14 +0,0 @@ -# coding=utf-8 -from distutils.core import setup, Extension - -name = "fibonacci" # name of the module -version = "1.0" # the module's version number - -setup(name=name, version=version, - # distutils detects .i files and compiles them automatically - ext_modules=[Extension(name='_{}'.format(name), # SWIG requires _ as a prefix for the module name - sources=["fibonacci.i", "fibonacci.c"], - include_dirs=[], - extra_compile_args=["-std=c11"], - swig_opts=[]) - ]) diff --git a/swig/structs/test_swig.py b/swig/structs/test_swig.py deleted file mode 100755 index 541d623..0000000 --- a/swig/structs/test_swig.py +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env python -# coding=utf-8 -""" Python wrapper to time the SWIG wrapper for computing the nth fibonacci number -in a non-recursive fashion and compare it to the pure Python implementation. -""" -import fibonacci -import fib_python - -if __name__ == '__main__': - import sys - import timeit - - n = 20 - try: - n = int(sys.argv[1]) - except Exception: - pass - - number_of_times = 100000 - try: - number_of_times = int(sys.argv[2]) - except Exception: - pass - - fib_py = fib_python.compute_fibonacci(n) - fib_swig = fibonacci.compute_fibonacci(n) - if fib_py != fib_swig: - raise (ValueError(fib_swig)) - - py_tot = timeit.timeit("compute_fibonacci({})".format(n), - setup="from fib_python import compute_fibonacci", - number=number_of_times) - swig_tot = timeit.timeit("compute_fibonacci({})".format(n), - setup="from fibonacci import compute_fibonacci", - number=number_of_times) - py_avg = py_tot / number_of_times - swig_avg = swig_tot / number_of_times - - print("fib({}) = {}".format(n, fib_py)) - print("Python average time: {0:.2g}".format(py_avg)) - print("SWIG/C average time: {0:.2g}".format(swig_avg)) - print("SWIG/C speedup: {0:.2g} times".format(py_avg / swig_avg)) - - # MetaData struct - md = fibonacci.populate_struct(1, 2, 3) - print("md.type = {}, md.job = {}, md.size = {}".format(md.type, md.job, md.size)) diff --git a/tests/test_fibonacci.py b/tests/test_fibonacci.py new file mode 100644 index 0000000..9a7e81b --- /dev/null +++ b/tests/test_fibonacci.py @@ -0,0 +1,41 @@ +"""One contract for Python and every compiled binding taught in the guide.""" + +from importlib import import_module + +import pytest + +MODULES = ( + "comparison.reference", + "native_examples.cffi_fib", + "native_examples.cython_fib", + "native_examples.cython_typed", + "native_examples.swig_fib", + "native_examples.pybind_fib", + "native_examples.nanobind_fib", + "rust_fibonacci", +) + + +@pytest.fixture(params=MODULES) +def fibonacci(request): + return import_module(request.param).compute_fibonacci + + +def test_workshop_sequence(fibonacci): + previous, current = 1, 1 + for n in range(45): + assert fibonacci(n) == current + previous, current = current, previous + current + + +@pytest.mark.parametrize("n", [-1, 45]) +def test_outside_native_range(fibonacci, n): + with pytest.raises(ValueError): + fibonacci(n) + + +def test_wrapped_struct(): + from native_examples.swig_fib import populate_struct + + message = populate_struct(7, 42, 1024) + assert (message.type, message.job, message.size) == (7, 42, 1024) diff --git a/tests/test_labs.py b/tests/test_labs.py new file mode 100644 index 0000000..75c1efb --- /dev/null +++ b/tests/test_labs.py @@ -0,0 +1,92 @@ +import math +import weakref +import zlib +from importlib import import_module + +import pytest + +PAYLOADS = [ + pytest.param(b"", id="empty"), + pytest.param(bytes(range(256)), id="binary"), + pytest.param(b"A\x00" * 10_000, id="repetitive"), +] + + +def test_integration_uses_left_endpoints(): + from native_examples.integration import integrate_cos + + assert integrate_cos(0, math.pi, 2) == pytest.approx(math.pi / 2) + assert integrate_cos(0, math.pi / 2, 10_000) == pytest.approx(1, abs=0.0001) + assert integrate_cos(math.pi / 2, 0, 10_000) == pytest.approx(-1, abs=0.0001) + + +@pytest.mark.parametrize("count", [0, -1]) +def test_integration_rejects_nonpositive_counts(count): + from native_examples.integration import integrate_cos + + with pytest.raises(ValueError): + integrate_cos(0, 1, count) + + +@pytest.mark.parametrize("data", PAYLOADS) +def test_buffer_codec_uses_zlib_format(data): + from native_examples import buffer_codec + + packed = buffer_codec.compress(memoryview(bytearray(data))) + assert isinstance(packed, bytes) + assert zlib.decompress(packed) == data + assert buffer_codec.decompress(zlib.compress(data), len(data)) == data + + +@pytest.mark.parametrize("data", PAYLOADS) +def test_vector_codec_uses_zlib_format(data): + from native_examples import vector_codec + + vector = vector_codec.ByteVector(list(data)) + assert zlib.decompress(bytes(vector_codec.compress(vector))) == data + assert bytes(vector_codec.decompress(list(zlib.compress(data)), len(data))) == data + + +@pytest.mark.parametrize("module_name", ["buffer_codec", "vector_codec"]) +@pytest.mark.parametrize( + ("packed", "size"), + [ + pytest.param(b"bad header", 3, id="corrupt"), + pytest.param(zlib.compress(b"abc"), 2, id="too-small"), + pytest.param(zlib.compress(b"abc"), 4, id="too-large"), + pytest.param(zlib.compress(b"x"), 0, id="expected-empty"), + ], +) +def test_codecs_reject_bad_stream_or_size(module_name, packed, size): + codec = import_module(f"native_examples.{module_name}") + source = list(packed) if module_name == "vector_codec" else packed + with pytest.raises(ValueError): + codec.decompress(source, size) + + +def test_callback_dispatches_without_retaining_logger(): + from native_examples.callbacks import Logger, emit_message + + records = [] + + class Recorder(Logger): + def log(self, level, message): + records.append((level, message)) + + recorder = Recorder() + ref = weakref.ref(recorder) + emit_message(recorder, 30, "temperature Δ") + assert records == [(30, "temperature Δ")] + del recorder + assert ref() is None + + +def test_callback_exception_returns_to_python(): + from native_examples.callbacks import Logger, emit_message + + class BrokenLogger(Logger): + def log(self, level, message): + raise LookupError(message) + + with pytest.raises(LookupError, match="offline"): + emit_message(BrokenLogger(), 40, "offline") diff --git a/uv.lock b/uv.lock new file mode 100644 index 0000000..85eb154 --- /dev/null +++ b/uv.lock @@ -0,0 +1,657 @@ +version = 1 +revision = 5 +requires-python = ">=3.11" +resolution-markers = [ + "python_full_version >= '3.11.5'", + "python_full_version < '3.11.5'", +] + +[manifest] +members = [ + "native-examples", + "python-native-workshop", + "rust-fibonacci", +] + +[[package]] +name = "cffi" +version = "2.1.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "pycparser", marker = "implementation_name != 'PyPy'" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/9e/ef/008a1939e372c06329a3fce4279c02f328488f3526744906eeec3da7ad5f/cffi-2.1.1.tar.gz", hash = "sha256:dd31f52ea1086513bb9df30f8fcee9b8918323ae067a3d5b78bc826a000712be", size = 530807, upload-time = "2026-08-03T21:21:18.939Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/70/d2/16d99a0c4948febc0ebd133a13b2f688ff7f8cb04da971e1128872ce0c03/cffi-2.1.1-cp311-cp311-macosx_10_15_x86_64.whl", hash = "sha256:c8d2c9fd1f2d16f780d15127abb050d13d1a76c03a4bd87d7e4980e45e511e12", size = 183838, upload-time = "2026-08-03T21:19:29.637Z" }, + { url = "https://files.pythonhosted.org/packages/cd/95/31b535a9f0220ae9f357de4a08d57ce89cb417653c2fd9f075f50822a388/cffi-2.1.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:398aff33cee2767e3e781d2554c54bd0dff386bb437581e0d8011fde1a942ec1", size = 184168, upload-time = "2026-08-03T21:19:30.764Z" }, + { url = "https://files.pythonhosted.org/packages/ad/5a/4707a0dc1f203f5dde5a907b0d4e3c25d71120241048bd5bc6f1bb9d4e71/cffi-2.1.1-cp311-cp311-manylinux1_i686.manylinux2014_i686.manylinux_2_17_i686.manylinux_2_5_i686.whl", hash = "sha256:154852545011f779917b11c78db2358d095da62a9a172b78ad0a583ee5adc0d0", size = 211805, upload-time = "2026-08-03T21:19:31.867Z" }, + { url = "https://files.pythonhosted.org/packages/ad/66/c19feabb28485b6e0bbaaafa90837a1ef5d302e90f2178bd33f17a49879b/cffi-2.1.1-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:3311ed60d36f83378794e1009ac6258bafbf81f7888b4caa7b35a521e3f95813", size = 218716, upload-time = "2026-08-03T21:19:32.896Z" }, + { url = "https://files.pythonhosted.org/packages/a7/92/500760486c8baab49a7a8a58ba7fc3355ec3974b454b8a09e528efde9e1d/cffi-2.1.1-cp311-cp311-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:6e192623c49c94421616a5778fba35cf0d5a8d000650c1967ef4448ee5cdd990", size = 205569, upload-time = "2026-08-03T21:19:34.142Z" }, + { url = "https://files.pythonhosted.org/packages/a5/a7/a67c733254d6e7373f7822f8082d8d6beade791e0cf12a7611f376fa61c7/cffi-2.1.1-cp311-cp311-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:a6e721d4b0e45d5b65e87534470e67b18dcd092c83f68fba09f152b9cbc061af", size = 204907, upload-time = "2026-08-03T21:19:35.174Z" }, + { url = "https://files.pythonhosted.org/packages/f7/a4/4399daaf8f7dfee9d7c3327fdb0426ee041cc63edc358b93911ceb2bfc7a/cffi-2.1.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:34e261f78cb6ceaaa36f42f2613f4380d94d9c759a9c73c769ee6e0247364632", size = 217807, upload-time = "2026-08-03T21:19:36.286Z" }, + { url = "https://files.pythonhosted.org/packages/28/f7/dabe6da2466ecbd82dc62e7342dc6b1065dad990c06f00f0ede9ebf2a0ed/cffi-2.1.1-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:7225e4514edb64eb6740324353e0da0711954fd8d7da4576755b1c6e09b697cd", size = 221252, upload-time = "2026-08-03T21:19:37.416Z" }, + { url = "https://files.pythonhosted.org/packages/ce/87/616202d8e51342c07d2534c510111c4cc37201775ce8f60802c9335d1edd/cffi-2.1.1-cp311-cp311-musllinux_1_2_i686.whl", hash = "sha256:df913725b79db7bcf03448f36b7bf8815363417d5b58deecf9305e3e30f0f21a", size = 214214, upload-time = "2026-08-03T21:19:38.507Z" }, + { url = "https://files.pythonhosted.org/packages/b4/c6/ab025d75d2c26c19b087c0124e75ee31cb65032f4fe345d356d8c507ab97/cffi-2.1.1-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:f5cfbc5fe74540d335175b656c725d74d90e3730c626d92575eea35029d9afaa", size = 219408, upload-time = "2026-08-03T21:19:39.809Z" }, + { url = "https://files.pythonhosted.org/packages/db/e2/7e8109f65445bdc673a7b54f02c677de462db75674220fd1335efc8eb598/cffi-2.1.1-cp311-cp311-win32.whl", hash = "sha256:f8ec5e643a9a937f64e1999eb9f75d072263751912dc5cd06d3c85f8f44be7c3", size = 174470, upload-time = "2026-08-03T21:19:41.246Z" }, + { url = "https://files.pythonhosted.org/packages/73/c0/77ba02423c2f7d7091143c45cd49e0e6575c4c1967394bb542bd923a9b74/cffi-2.1.1-cp311-cp311-win_amd64.whl", hash = "sha256:42f6930c31dc7f50732c9ae793c2786c7b6b044195967bbdde40bb9be81c4cc0", size = 185096, upload-time = "2026-08-03T21:19:42.615Z" }, + { url = "https://files.pythonhosted.org/packages/7c/47/9f1f85f9672ceda4984dc6c4f8824e8558992a2972c3d3c81fb8eb28d4ba/cffi-2.1.1-cp311-cp311-win_arm64.whl", hash = "sha256:c7659f22557c5a0bc4855cd635f55edec690cc008a40768527762cb9fb263455", size = 179941, upload-time = "2026-08-03T21:19:43.747Z" }, + { url = "https://files.pythonhosted.org/packages/10/69/43965eccfdead3b9220015fd1320e117be8c6ed01a62ffab76eeb752f5d5/cffi-2.1.1-cp312-cp312-macosx_10_15_x86_64.whl", hash = "sha256:c8c69575568085ba0b1b10c0249d779a214aea6f6522e949a0fc9fb0fcb449d0", size = 184821, upload-time = "2026-08-03T21:19:44.887Z" }, + { url = "https://files.pythonhosted.org/packages/54/7d/16e5a096677b5e313ca80cd5e5170efa3ea44624a82bb111925522da64b1/cffi-2.1.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:f81b3b8f3d4e343550fa4baa0e479bba9f2d29ce9c2e9b51d1ce1718d7442fcf", size = 184719, upload-time = "2026-08-03T21:19:46.129Z" }, + { url = "https://files.pythonhosted.org/packages/56/e6/8941622732edec876dd17d0453dce07317ae96db34f2ec1436c9d3785986/cffi-2.1.1-cp312-cp312-manylinux1_i686.manylinux2014_i686.manylinux_2_17_i686.manylinux_2_5_i686.whl", hash = "sha256:811bd1e21d32de12efca32393a0ab3f5133b54fce9bd44b8bd77ab07da14bf6a", size = 214799, upload-time = "2026-08-03T21:19:47.218Z" }, + { url = "https://files.pythonhosted.org/packages/44/de/f98430906df1545ffde0d543dd124a7a439bc2cd32b36b9c53f805df7333/cffi-2.1.1-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:68e62fe11f30d5ca8289242866f0a5291402d8529ca2178ab8afc5c9694ae890", size = 222389, upload-time = "2026-08-03T21:19:48.331Z" }, + { url = "https://files.pythonhosted.org/packages/6a/5b/717f1526b9957b34456313c31645c5b82b8fb5c3fe9e4752999be7128bfc/cffi-2.1.1-cp312-cp312-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:4a7c934f7360e8cd64fe9efadcbd10c7c6364f531e432b9a4bf5ccbc9e0e8b50", size = 210249, upload-time = "2026-08-03T21:19:49.543Z" }, + { url = "https://files.pythonhosted.org/packages/64/b3/f8aa4f3e34986c7e4ec45072d1b1b9dd295b6b18007b45518d79726dd725/cffi-2.1.1-cp312-cp312-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:3143d81e29e1e20a9ce10901ec369012947876596f75a222235965f2b7ae832e", size = 208775, upload-time = "2026-08-03T21:19:50.918Z" }, + { url = "https://files.pythonhosted.org/packages/b1/db/dceb9dd5b231e1da801793f8acc9f3c52a7e1afe40bb1aae37e02b0faad5/cffi-2.1.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:c1453022f490d2459a11819d83ad1d586e9ff65a12ac3e705ffebd46d3685dcf", size = 221822, upload-time = "2026-08-03T21:19:52.054Z" }, + { url = "https://files.pythonhosted.org/packages/a0/d2/6cd24ae3be000a634109c247d1475d62e5616d0dc78c82770942ec384248/cffi-2.1.1-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:208f941bb9d18e768138677f0a6d2ce01f590df56043dda1df1535ac57c88517", size = 225232, upload-time = "2026-08-03T21:19:53.109Z" }, + { url = "https://files.pythonhosted.org/packages/cb/52/3fa190537004dd7f0ab860a6dc7c0175b8667f68d1e618a46f5498d30250/cffi-2.1.1-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:210019b6c7cf07f081b4c54635c8cf744377001350e29cc0f81c4377b4797735", size = 223597, upload-time = "2026-08-03T21:19:54.515Z" }, + { url = "https://files.pythonhosted.org/packages/80/fb/0bb75b7039588c074b37ae99f40d9bfddf990ecb2fbc346ebccd2e56b9be/cffi-2.1.1-cp312-cp312-win32.whl", hash = "sha256:046bfc24911b37851ee1b51aab8bffe713d89c68c6a057b09484ce9fd5f69b4e", size = 175292, upload-time = "2026-08-03T21:19:55.566Z" }, + { url = "https://files.pythonhosted.org/packages/d9/79/615cc094e2fb508cade7de88d3b4f6c4ec2bab695c97bce9153dc65aadf5/cffi-2.1.1-cp312-cp312-win_amd64.whl", hash = "sha256:f53e442b08449d42821fa4a4fba000095af9f62742a500f978a9f557ec44339a", size = 185919, upload-time = "2026-08-03T21:19:56.89Z" }, + { url = "https://files.pythonhosted.org/packages/70/c6/d0ea84713fe46b243a436a18fcd47d639732747e21635c8a27191b06dc30/cffi-2.1.1-cp312-cp312-win_arm64.whl", hash = "sha256:7bde5e4cc5c10140859842b9d383af292b22639a4dffb725314baf45968cef80", size = 180093, upload-time = "2026-08-03T21:19:58.155Z" }, + { url = "https://files.pythonhosted.org/packages/9d/f4/035513d4117049066b4779dc3b7c0c0fdad175fa13731c9f4003f1cd1478/cffi-2.1.1-cp313-cp313-ios_13_0_arm64_iphoneos.whl", hash = "sha256:b5bdfd1c873d4e093aabc0ca84c4ca6dbc4f752afb5c86f146d9742580c9da2e", size = 194248, upload-time = "2026-08-03T21:19:59.399Z" }, + { url = "https://files.pythonhosted.org/packages/76/af/2aeb4dbb5fc41a04161ae9ff1518de7cec08e164f44a8ce6a4cf7fd2cd1d/cffi-2.1.1-cp313-cp313-ios_13_0_arm64_iphonesimulator.whl", hash = "sha256:31348097ff5bbe827ccc41795d4dd099d9f0625e7def00ee653c137a490c2a6c", size = 196908, upload-time = "2026-08-03T21:20:00.746Z" }, + { url = "https://files.pythonhosted.org/packages/a7/46/2e5fdde8555706dd98139a910ca11be02809f3f605ce956f655d0214e100/cffi-2.1.1-cp313-cp313-macosx_10_15_x86_64.whl", hash = "sha256:9d2055050ea716bd38b7f7f1579c275386646b4894c155a3e2f3cd62ed41b7c6", size = 184805, upload-time = "2026-08-03T21:20:02.02Z" }, + { url = "https://files.pythonhosted.org/packages/55/41/4c7042f317b9217502988f0873af87e16ad606dc20f84e546e3e6ce9764c/cffi-2.1.1-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:19ee6127ee34de7d83ce3d371ebc5ed91addbdcc39f9ab15ce4eb35a4e534971", size = 184764, upload-time = "2026-08-03T21:20:03.141Z" }, + { url = "https://files.pythonhosted.org/packages/43/1f/1c3d90d91811c8f86ced9ed637956c54bfe5b79ca98fe976d7f8c8979f6b/cffi-2.1.1-cp313-cp313-manylinux1_i686.manylinux2014_i686.manylinux_2_17_i686.manylinux_2_5_i686.whl", hash = "sha256:6a8dddef476fab96d066d578fc88526767b836ab5ab21754e1d5bf3879c31c7c", size = 214722, upload-time = "2026-08-03T21:20:04.377Z" }, + { url = "https://files.pythonhosted.org/packages/37/6f/3b5ce4c3b2192d250f04908f2bfd91ef34552ec8f7716a5d4abdb8d67bb2/cffi-2.1.1-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:f16c709686a78c727bbbf059f92b0bf41c6fc60deec706d2dc19f529175a6125", size = 222369, upload-time = "2026-08-03T21:20:05.544Z" }, + { url = "https://files.pythonhosted.org/packages/02/10/4b3c75dde3d9663c9e02ba05c2668b954f671d4bbe346413ca8c696b295a/cffi-2.1.1-cp313-cp313-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:fcd22650c908d7b7da162bbfaab594a1227a15d1643a98c68b122ac642fa2264", size = 210175, upload-time = "2026-08-03T21:20:06.75Z" }, + { url = "https://files.pythonhosted.org/packages/df/62/14f74b9543e605d17701dc797b815958b8bb70b7624ce1b832ddad48ed6c/cffi-2.1.1-cp313-cp313-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:aa9511c62d14da7aacc9b4bf51f3f697a621e83b2d6919008243c3aad168eea3", size = 208670, upload-time = "2026-08-03T21:20:08.04Z" }, + { url = "https://files.pythonhosted.org/packages/95/95/86342356ff5953b3fb06f7ef7c5bee212d45e770abc7218d451b9148313c/cffi-2.1.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:a931079504ecc49efed7744c476a5c343a92fabf66dec2db95edb1b2fdc770e2", size = 221824, upload-time = "2026-08-03T21:20:09.274Z" }, + { url = "https://files.pythonhosted.org/packages/eb/ff/7b3429ff53aafe931ed8a5fc69f481bbef7ba6de87ddcbb63d08f483f613/cffi-2.1.1-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:a2d7755bef5a12ed488f4ef1f1b69ee9191d7396083b755a5d2295f6edb4768b", size = 225148, upload-time = "2026-08-03T21:20:10.7Z" }, + { url = "https://files.pythonhosted.org/packages/34/34/a95870b9221e09cf4f2ce3178b1a210abdfe63a1bd357da940418d7b8d15/cffi-2.1.1-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:e0bcb7e0f677f543555d2adff3bf19c05f66cdb4796e5ff602442ab2fe3c4ef7", size = 223564, upload-time = "2026-08-03T21:20:12.165Z" }, + { url = "https://files.pythonhosted.org/packages/70/ea/839b50531021a647fb5e929f72cf97bc1ff702b5472166164b5b6e76b851/cffi-2.1.1-cp313-cp313-win32.whl", hash = "sha256:334644fbac4eff73d985a17a91226df55d0f394160c4cfb880e084c8f7161cac", size = 175263, upload-time = "2026-08-03T21:20:13.559Z" }, + { url = "https://files.pythonhosted.org/packages/60/a6/8b149b2c3f2e11aaa1618ef64500b45f50f22c57a977a4dff1aff1f91042/cffi-2.1.1-cp313-cp313-win_amd64.whl", hash = "sha256:1aa5645c30469b09530c4ebca77ebf8f17618293c58f8549cb1a543a50236e7d", size = 185688, upload-time = "2026-08-03T21:20:14.69Z" }, + { url = "https://files.pythonhosted.org/packages/01/9a/11f687cb39d6a3504060d5242f04f48c735afb4d3d533958a20594890cb2/cffi-2.1.1-cp313-cp313-win_arm64.whl", hash = "sha256:63bbfd5ded17c4840ac07cd8f1c21ba9d9708141f840b324f422f41b207e3973", size = 180078, upload-time = "2026-08-03T21:20:15.917Z" }, + { url = "https://files.pythonhosted.org/packages/d3/7b/d6bbf82b8b96e7391438898c42f5bd96dd02030fd5b64937d248220003e2/cffi-2.1.1-cp314-cp314-ios_13_0_arm64_iphoneos.whl", hash = "sha256:7dbb61fe3a7699468030f71bbe5f8a0e326a151daa91beb11a6fc1f980c55e1c", size = 194064, upload-time = "2026-08-03T21:20:17.148Z" }, + { url = "https://files.pythonhosted.org/packages/94/e6/bcc91b283be94735e268487a054004f0aa19947b6348fa367db53230abc8/cffi-2.1.1-cp314-cp314-ios_13_0_arm64_iphonesimulator.whl", hash = "sha256:f24fb43132a4c6b4cb4eb029492919b2db645be6808d738f244fd146c03c32cb", size = 196720, upload-time = "2026-08-03T21:20:18.268Z" }, + { url = "https://files.pythonhosted.org/packages/d9/99/c4b0c17cacdc9c3b8f280026286a9826d6a208c0f047591a3c3ce99b91fd/cffi-2.1.1-cp314-cp314-macosx_10_15_x86_64.whl", hash = "sha256:d28630f5854ab07ab1fd4aba756de52326c82e6be15d414b12793f1975048b54", size = 184964, upload-time = "2026-08-03T21:20:19.708Z" }, + { url = "https://files.pythonhosted.org/packages/b3/a9/9db617d05d7367c1ad0ab00b3aa6e6f9281edd689b4ee9ea0e5a84e89c97/cffi-2.1.1-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:661c298b4821edebead0c91edd2b00374d67ad7c5a1f7a91d4442633b79d6a72", size = 184962, upload-time = "2026-08-03T21:20:20.833Z" }, + { url = "https://files.pythonhosted.org/packages/67/b8/b42132ca113dc567d37684437b46ca1dafc885902b02a110a02d5b511857/cffi-2.1.1-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:58acb8ab8e295e6c5ea12f888cbb13cf21511ef2a3303a23f4325c29d17fe5c1", size = 222328, upload-time = "2026-08-03T21:20:22.118Z" }, + { url = "https://files.pythonhosted.org/packages/80/10/c5c0cbf0a657aecf59ef511409734230bf556f05a0d6c9eed7aa5c0a0166/cffi-2.1.1-cp314-cp314-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:456a61fa52d579ebf9df2e9552ead5129855dbaff6c1e5a9b1bc408809bdc062", size = 209985, upload-time = "2026-08-03T21:20:23.401Z" }, + { url = "https://files.pythonhosted.org/packages/d5/6c/bfa0b87b03b9238148beca990292843c9396ba069b54496596594173de7b/cffi-2.1.1-cp314-cp314-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:a4f00aa42f75d6e4595e8866e748cc1705adc0cddfeb2ca86d0d03993d63ba03", size = 208530, upload-time = "2026-08-03T21:20:24.628Z" }, + { url = "https://files.pythonhosted.org/packages/e9/02/4e7d553a7ac4b4238b38b3c1b80d486e9d4436f8d2acbf87a0997fe3f402/cffi-2.1.1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:b0431303acaea1089ad4b3e9ce4e6518193def1118d4073ca848635ee4ea2e96", size = 221525, upload-time = "2026-08-03T21:20:25.758Z" }, + { url = "https://files.pythonhosted.org/packages/82/1d/a4aaf9babd75acb4d5f223bff71533bee748dd770a382619a798960ee9ba/cffi-2.1.1-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:64faea20f4e2613363a1a9b9c7dd73058f3ecd00133a511e72ad7c511658f527", size = 225053, upload-time = "2026-08-03T21:20:26.985Z" }, + { url = "https://files.pythonhosted.org/packages/81/10/5dc0e7bdd18e22107054288283380fc97a06ae3f1656a106908d666a3c88/cffi-2.1.1-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:5c58fe613dc5e5336357eff555824a314d8e43282600435c8d1cb6a7a2fedd13", size = 223213, upload-time = "2026-08-03T21:20:28.277Z" }, + { url = "https://files.pythonhosted.org/packages/0b/e9/d0061c364cde06ee43168a0d076ac1da512cbc380d44767b844ba34fe2b6/cffi-2.1.1-cp314-cp314-win32.whl", hash = "sha256:1a18a57b58cfb21fc28d72e876acf10eaed67a1ed96226f92af4df681d571c4c", size = 177682, upload-time = "2026-08-03T21:20:44.288Z" }, + { url = "https://files.pythonhosted.org/packages/a7/06/1c3e01e3ba14c39f6d10bfbac52753b7e22259e38088e5cfe1d704918690/cffi-2.1.1-cp314-cp314-win_amd64.whl", hash = "sha256:3222ba5d678f80a030e6afbcc33dc1ae5cb45facabb61cee2c7016b8432fde48", size = 187949, upload-time = "2026-08-03T21:20:45.623Z" }, + { url = "https://files.pythonhosted.org/packages/87/5b/da4e39efe18eeb89cf580ea9cfc66b6a7c3eadb808fc0cc1d3a295cb5a5d/cffi-2.1.1-cp314-cp314-win_arm64.whl", hash = "sha256:ab36d55f9ed2d067327667c2fea18dda018eb628dd6347aa01dda6cf1f5d3836", size = 182947, upload-time = "2026-08-03T21:20:46.955Z" }, + { url = "https://files.pythonhosted.org/packages/23/59/40338bf421c5accea1d45158170c87006ef1cd371b05c077e76476949728/cffi-2.1.1-cp314-cp314t-macosx_10_15_x86_64.whl", hash = "sha256:7750c6449dff7864bb9bb27ddfb0267756189201a3afc911d82b3caacd70dfc3", size = 188504, upload-time = "2026-08-03T21:20:29.495Z" }, + { url = "https://files.pythonhosted.org/packages/7d/47/5ecf1023850036e674c77ec4de86182d309ae344e39e7cba984b7df5d647/cffi-2.1.1-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:0beceaabe56af686895136a2de78db54ecd8e4046b236b8fd6d6cb61389e9bf2", size = 188259, upload-time = "2026-08-03T21:20:31.291Z" }, + { url = "https://files.pythonhosted.org/packages/2a/9c/92934c3bea9f785b23eba304538c0b4d37a2a96d2431eb3a1bc87a11aa19/cffi-2.1.1-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:49cbc70e6542d4ccccb936558d1064a8012541e78f821f955cff24e357776c94", size = 223864, upload-time = "2026-08-03T21:20:32.571Z" }, + { url = "https://files.pythonhosted.org/packages/4d/45/ba4c93527bc38616a8bd36488acb69a2212d60486794f0c1f318949bbb76/cffi-2.1.1-cp314-cp314t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:e2d65b31f36619cda3999b78b2aa9632e76b78448e7a56fc4240824200e7c4fc", size = 211538, upload-time = "2026-08-03T21:20:33.808Z" }, + { url = "https://files.pythonhosted.org/packages/80/e9/b6ef565e452acb932fb0cb5443f44a78efbd1233e566f02b5a83855e9115/cffi-2.1.1-cp314-cp314t-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:28907ab9bfb6aa13184cfc17c6b8e1023c5ab6fd7076d8c20a35e59fe04f8f29", size = 210688, upload-time = "2026-08-03T21:20:34.974Z" }, + { url = "https://files.pythonhosted.org/packages/9a/95/eff5f0cee78d2eabc7eebffec40d3fc1876b5f3c95582e018bb4b99601f2/cffi-2.1.1-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:51b31d1c98274844cfd7838ce00bfc27c7423a4dc00fc0772fc3331c2cc90676", size = 223803, upload-time = "2026-08-03T21:20:36.564Z" }, + { url = "https://files.pythonhosted.org/packages/fa/01/579d39fb8bef00a335a23d83757b44feb24cd6345a2c451b64cb67b9c362/cffi-2.1.1-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:5e7cecbaadb83884793e05828cee59b210b24583b9c7425d0ba6a754fe22eb4e", size = 226763, upload-time = "2026-08-03T21:20:37.816Z" }, + { url = "https://files.pythonhosted.org/packages/8d/b0/0b44f47c60b01b57b6e2bbd92343f13a85a1d93bc46ccf6e47e244acd99c/cffi-2.1.1-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:25792eac27877609e7bb06d42ff88278a6624fff2ba9bbb523c09616b117e80f", size = 225688, upload-time = "2026-08-03T21:20:38.959Z" }, + { url = "https://files.pythonhosted.org/packages/eb/d2/3b7176cb570a1d3e27faf67b72f591af508036e0d8b2be2ef9af9e8c84bb/cffi-2.1.1-cp314-cp314t-win32.whl", hash = "sha256:8ef53b2de9bcb9197d31854256575d59dbac0cba72ac627bb291ef5eceb74be4", size = 182868, upload-time = "2026-08-03T21:20:40.388Z" }, + { url = "https://files.pythonhosted.org/packages/56/78/31f00c1bcd97c9bbf55f1bfdf5bc809a5de8887473e90bb9960dca825e80/cffi-2.1.1-cp314-cp314t-win_amd64.whl", hash = "sha256:616f097f2fe415bc92a247f02e11f634e1f9e9a83d327e3c915c15089c87869e", size = 194104, upload-time = "2026-08-03T21:20:41.725Z" }, + { url = "https://files.pythonhosted.org/packages/7b/1b/58496f2ed0a35de575250c02a43ab3cc2c04d494a88fed31c1cabc0fd176/cffi-2.1.1-cp314-cp314t-win_arm64.whl", hash = "sha256:ad2c86c495b899d862ea0f4b42891b8713a3bd45dd4105c7fd51c2a72f39f3a5", size = 186402, upload-time = "2026-08-03T21:20:43.042Z" }, + { url = "https://files.pythonhosted.org/packages/c1/8f/9ebe220eab48a093d1a5a5e339ab0dc7316eef3bb04d63c42f0251b61f50/cffi-2.1.1-cp315-cp315-ios_13_0_arm64_iphoneos.whl", hash = "sha256:dddad92b554513a31f272570678ba307fb9f618f05e3d4a5eacafff9eae03e1d", size = 194043, upload-time = "2026-08-03T21:20:48.179Z" }, + { url = "https://files.pythonhosted.org/packages/ff/69/844bad3ece306c4782c2ecb93597035b6690d48704b803914c199da1e8b3/cffi-2.1.1-cp315-cp315-ios_13_0_arm64_iphonesimulator.whl", hash = "sha256:da0e573f9f97159390c89d9f1a9e41908b66d408cc5b58d08cf3847d844c531b", size = 196737, upload-time = "2026-08-03T21:20:49.457Z" }, + { url = "https://files.pythonhosted.org/packages/1b/8a/af668013284634733f02d683458a0728739c7d6ddb5e14cb0c20832266fe/cffi-2.1.1-cp315-cp315-macosx_10_15_x86_64.whl", hash = "sha256:fb92203a88b3d3053034db775110081c49d28be6551923805e039924093761e4", size = 184933, upload-time = "2026-08-03T21:20:50.639Z" }, + { url = "https://files.pythonhosted.org/packages/0c/75/2f5207ff6d1a613133b23a5203cc0c2a628313b5eb3974d7956ae3c57950/cffi-2.1.1-cp315-cp315-macosx_11_0_arm64.whl", hash = "sha256:2ae64be792b8966f2c69538199728b290e34726562896df1e5dc8ffd8d8188e8", size = 185002, upload-time = "2026-08-03T21:20:52.173Z" }, + { url = "https://files.pythonhosted.org/packages/e2/31/9e1313b0a6e30e91b3b3d3fff51ae99c857c07738e3afcce1f7334e1b7ab/cffi-2.1.1-cp315-cp315-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:507a24c282e0f42f8ed737cf048572cbf580468da5555764a8331735e9c736b6", size = 222271, upload-time = "2026-08-03T21:20:53.462Z" }, + { url = "https://files.pythonhosted.org/packages/50/e3/f6234a833e6e08c7007003074723c406559eecf9b48dfc97471e5a8eb7a0/cffi-2.1.1-cp315-cp315-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:246fa40ce8645a614ff682e0b70f37134e460eaf93a775e0cbe3cca585a67a80", size = 209919, upload-time = "2026-08-03T21:20:54.783Z" }, + { url = "https://files.pythonhosted.org/packages/0d/fc/5f74e293fced6edb51af3a46c4ccf6c23c9943774ecb375ddbd522c76add/cffi-2.1.1-cp315-cp315-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:471cee653ae88de62096552e6d24ccb4a5adb8c8c9f10b5054d0122c15bf2779", size = 208529, upload-time = "2026-08-03T21:20:56.066Z" }, + { url = "https://files.pythonhosted.org/packages/44/16/29e6d01b388bef055ecd6ca8244b3f4d336bd09e92d5d892187b9601084e/cffi-2.1.1-cp315-cp315-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:aeae0e330c9f6acd681f647d46cefd30c29f93e3392882e792e82080c9691399", size = 221630, upload-time = "2026-08-03T21:20:57.336Z" }, + { url = "https://files.pythonhosted.org/packages/a4/18/fa7f1f6857d5eb88a4ca99ffcbfb7c387a287ccc154c64a73e86314745d7/cffi-2.1.1-cp315-cp315-musllinux_1_2_aarch64.whl", hash = "sha256:42a494cee34437f05546455144f2b5d9ac09b1face62bcfce597d2e521066688", size = 225134, upload-time = "2026-08-03T21:20:58.675Z" }, + { url = "https://files.pythonhosted.org/packages/e0/9f/e8e3dfa04a1b4c241f8c91faacad872b4d4efd051d49764ad4e2fd4b9fea/cffi-2.1.1-cp315-cp315-musllinux_1_2_x86_64.whl", hash = "sha256:cc572dace3f60ef98d7b12ff411d20f5362feb31a0439eab0085bbfd349982d7", size = 223197, upload-time = "2026-08-03T21:20:59.968Z" }, + { url = "https://files.pythonhosted.org/packages/f8/7e/8debeb04f1ab9fe2a6963964cd6f1aaf7192627b83926586a6a4e089c9fa/cffi-2.1.1-cp315-cp315-win32.whl", hash = "sha256:4f42141fc14250de6dde5ee7ea4432be017252d91f19c5ad043c084cea629cac", size = 177683, upload-time = "2026-08-03T21:21:14.901Z" }, + { url = "https://files.pythonhosted.org/packages/e0/31/5158704cc474ab65c1647932e88be78dc0873f47130e253be38bcaf13d01/cffi-2.1.1-cp315-cp315-win_amd64.whl", hash = "sha256:e6e8cff14d6fb0be70a09c0bdc58096f501952d04624ebf867e0e56da2df8960", size = 187897, upload-time = "2026-08-03T21:21:16.108Z" }, + { url = "https://files.pythonhosted.org/packages/cc/4b/b3a2da8570c704ffc0f9762cdc3ec0f02c8573798e0b5cf7f11c82bbb70f/cffi-2.1.1-cp315-cp315-win_arm64.whl", hash = "sha256:27350daa11d4f10c540e6e89dada4c54feb7256ad03e9a4dc075ebad7ba360d1", size = 182935, upload-time = "2026-08-03T21:21:17.271Z" }, + { url = "https://files.pythonhosted.org/packages/d0/ef/5443574510a1207e6f6bc38ba6e1f1de36cb48fef07b2728bb896a21f430/cffi-2.1.1-cp315-cp315t-macosx_10_15_x86_64.whl", hash = "sha256:c26608d2222fb1e94487e4a387d85f13eb55d5ed725cb25a0c589ac4ee60e7bc", size = 188464, upload-time = "2026-08-03T21:21:01.163Z" }, + { url = "https://files.pythonhosted.org/packages/7e/ae/a56fa8c4686ad50e148fcbc8d3ae0d03915ff5c30d795058988c24118cef/cffi-2.1.1-cp315-cp315t-macosx_11_0_arm64.whl", hash = "sha256:4be96343e422f2dfcd12ab5c9f5aebe03f82f737c6bffeca6830b3875cb44aab", size = 188262, upload-time = "2026-08-03T21:21:02.382Z" }, + { url = "https://files.pythonhosted.org/packages/53/b2/6187f46f2912276a3ae284076109cc5c8680482f11f766ccf26db4a86427/cffi-2.1.1-cp315-cp315t-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:937c0052c05a31ca1daf18de3158eed4dbfcb9cc107adbea227728d647be701e", size = 223779, upload-time = "2026-08-03T21:21:03.553Z" }, + { url = "https://files.pythonhosted.org/packages/8a/f6/c3ad28bd19f77047a03084424fbd4cbe997303267c14423737324be0385d/cffi-2.1.1-cp315-cp315t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:df423d40ee8654634421812bc3b196da3f9bd7d32929da813f8394c4348a5358", size = 211520, upload-time = "2026-08-03T21:21:04.863Z" }, + { url = "https://files.pythonhosted.org/packages/a0/cd/ccac9013a5bd9fd764de118674ab9c805b5ca10c19270d90ee273f8b2240/cffi-2.1.1-cp315-cp315t-manylinux2014_s390x.manylinux_2_17_s390x.whl", hash = "sha256:a730a083190634c65cca36ba5f489531576ebd79bcd5c8e172130f6453127231", size = 210673, upload-time = "2026-08-03T21:21:06.223Z" }, + { url = "https://files.pythonhosted.org/packages/52/86/2976131c639aead931c5bee5aba67e4b09fbeb8018b6f282f70803f923a7/cffi-2.1.1-cp315-cp315t-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:363e05fa78e15116c3c32c210ee36884fd6b9afa6d440e47112c3bd511d64cb6", size = 223835, upload-time = "2026-08-03T21:21:07.539Z" }, + { url = "https://files.pythonhosted.org/packages/ac/0c/33a7aeab2f9c76918c52e084beb39c570db3588133412929e8ec06fab90b/cffi-2.1.1-cp315-cp315t-musllinux_1_2_aarch64.whl", hash = "sha256:770de9db11e84213beec501cfcaa013b019820ca881e03344dea5844f7876d94", size = 226705, upload-time = "2026-08-03T21:21:08.774Z" }, + { url = "https://files.pythonhosted.org/packages/e3/26/2cde30fdde421130bfc18f70395731a6e6b2053c6a1978a5258ff04e72fa/cffi-2.1.1-cp315-cp315t-musllinux_1_2_x86_64.whl", hash = "sha256:7da0c5eff80f0197f3b3d1232ec5a682a9325f4ae9016a78f5f5ca35f9ced1f5", size = 225539, upload-time = "2026-08-03T21:21:09.911Z" }, + { url = "https://files.pythonhosted.org/packages/6d/cd/a361394c94b2129d604bb846f624a8e88255a3ee33129c434a00d715e64f/cffi-2.1.1-cp315-cp315t-win32.whl", hash = "sha256:06c72bb76605a4b0cd0aad6930b69d4baf7dd5d806cfc409b824191099700e66", size = 182707, upload-time = "2026-08-03T21:21:11.226Z" }, + { url = "https://files.pythonhosted.org/packages/9b/b5/ba2b299993c26577d529b6ae29841f9e15b9fcf004d65f423f4fcf94ade9/cffi-2.1.1-cp315-cp315t-win_amd64.whl", hash = "sha256:d9c275eaacd24aa73f94ffd6de08fc3f932424d8b6c376f4bed7cde376fe7bc3", size = 193772, upload-time = "2026-08-03T21:21:12.39Z" }, + { url = "https://files.pythonhosted.org/packages/aa/29/35e016098c814cd93de9cd320c66b5bfba14dc6ecedd3cb518fa7c408c69/cffi-2.1.1-cp315-cp315t-win_arm64.whl", hash = "sha256:d18e5ac0f2f03f4f518d3e23db0f0cad7faa1da8620e9c09461d443bbf6e6692", size = 186360, upload-time = "2026-08-03T21:21:13.636Z" }, +] + +[[package]] +name = "click" +version = "8.5.1" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/45/37/edbf1b0707709013c0cf2e8317e03d97ed29bf4cac709fe328904ae92a38/click-8.5.1.tar.gz", hash = "sha256:9bbfada76703fd1d784b83eea012e3e8c6a001a876543ef104fa56aaaeb072b4", size = 399151, upload-time = "2026-11-06T17:37:01.021Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/31/7d/164b7ffc8624fe9efb4221bf9af485d5c1e41b9ae118045d2b6dc5457d8b/click-8.5.1-py3-none-any.whl", hash = "sha256:8bb5376d2006950386f8c6427613334a2acadc5f559cb80e638d00b4df957e37", size = 126163, upload-time = "2026-11-06T17:36:59.287Z" }, +] + +[[package]] +name = "colorama" +version = "0.4.6" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/d8/53/6f443c9a4a8358a93a6792e2acffb9d9d5cb0a5cfd8802644b7b1c9a02e4/colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44", size = 27697, upload-time = "2022-10-25T02:36:22.414Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6", size = 25335, upload-time = "2022-10-25T02:36:20.889Z" }, +] + +[[package]] +name = "iniconfig" +version = "2.3.1" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/01/e1/2069291243c926a2ff1cd706c7f3eeb9b62144bf60f77c9fb9ff2fb26bd3/iniconfig-2.3.1.tar.gz", hash = "sha256:67f4b9c50da0dedf52af349e7749a80a9057a5031199791b906c3bb3ae878960", size = 21209, upload-time = "2026-10-06T22:48:38.076Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/56/43/4ca9e49d27a1fcf6bece6f6aec0ea46bb9112489b93d4b688fb415457bdb/iniconfig-2.3.1-py3-none-any.whl", hash = "sha256:9121e2c1fdb355232495be3194c8dfe87ccc2d5dee45947b78e68f499790d7a7", size = 7552, upload-time = "2026-10-06T22:48:36.959Z" }, +] + +[[package]] +name = "jinja2" +version = "3.1.6" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "markupsafe" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/df/bf/f7da0350254c0ed7c72f3e33cef02e048281fec7ecec5f032d4aac52226b/jinja2-3.1.6.tar.gz", hash = "sha256:0137fb05990d35f1275a587e9aee6d56da821fc83491a0fb838183be43f66d6d", size = 245115, upload-time = "2025-03-05T20:05:02.478Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/62/a1/3d680cbfd5f4b8f15abc1d571870c5fc3e594bb582bc3b64ea099db13e56/jinja2-3.1.6-py3-none-any.whl", hash = "sha256:85ece4451f492d0c13c5dd7c13a64681a86afae63a5f347908daf103ce6d2f67", size = 134899, upload-time = "2025-03-05T20:05:00.369Z" }, +] + +[[package]] +name = "markdown" +version = "3.11.4" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/1c/ff/8644daa33bfdf552c9cfec8d1fc2c690f57a347808f62c406ac6557329c2/markdown-3.11.4.tar.gz", hash = "sha256:c911a757f33d64a2578bed2d20c57e007b2aedd8a67bceabd593b31143d54ead", size = 505340, upload-time = "2026-11-25T16:26:12.029Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/61/54/188fcc228c71a4ae33244008af08c2e7b1945b657390f56d82dfbe4059f0/markdown-3.11.4-py3-none-any.whl", hash = "sha256:2e30b19cead1968f391206e184ca67dfe6805c2eb8f383fb07b4dc90f8288075", size = 119551, upload-time = "2026-11-25T16:26:10.692Z" }, +] + +[[package]] +name = "markupsafe" +version = "3.0.4" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/38/9b/e422a865e1d5d57d0e509b4e0bf1c1a70a7f6382c29a5aa428df994c8bc8/markupsafe-3.0.4.tar.gz", hash = "sha256:2e9ad7dd851bf45fab9f75cbff4cb493fee9979e8d8c7c9c3ee119022518edd6", size = 153777, upload-time = "2026-10-02T23:07:22.29Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/32/55/18dbb4778b30ada5ce071608503cc3edc9e14e13d868c17a6d178fc30f7a/markupsafe-3.0.4-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:9e25feb9e330b63edb0278a0acdf85e50d0cb0fbf49c3084abbe4e24ae195346", size = 11520, upload-time = "2026-10-02T23:04:36.299Z" }, + { url = "https://files.pythonhosted.org/packages/6c/14/0b05f79b4733e264a18d08fe08fa1df7347630ff32a6cb82180d9dccec55/markupsafe-3.0.4-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:7d3391b2188d18737cb2fa147028b1096236eaa7e156446c650a489fa2cadc91", size = 12063, upload-time = "2026-10-02T23:04:37.291Z" }, + { url = "https://files.pythonhosted.org/packages/ca/3a/63ba10b6c1463216b3e4df669a9f0e5a3b0c3071557d2e8229e3968c79fb/markupsafe-3.0.4-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:849dd2bb0e5e4ab2b71c7191726a4a8d5aa8a610daa584728cbee0b710ddc4ef", size = 24321, upload-time = "2026-10-02T23:04:38.262Z" }, + { url = "https://files.pythonhosted.org/packages/1a/2e/5f015261b76ad633d187ef6f388b413aedd64a8773c4df59e530a0be5525/markupsafe-3.0.4-cp311-cp311-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:befb4158af32106b9a93db8d6d1d1cbbd418c0d5aca0cabb7b1780abf0c89169", size = 28845, upload-time = "2026-10-02T23:04:39.295Z" }, + { url = "https://files.pythonhosted.org/packages/33/cf/26e594b26be40c2f1fec63ccf8a8b99d0335a5b2cbe84835c7d82a994375/markupsafe-3.0.4-cp311-cp311-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:71f88e749ea29f67f21f3b36433c1dc54c7729ed2a6d9e2da2e0d9e0d7b224eb", size = 24701, upload-time = "2026-10-02T23:04:40.348Z" }, + { url = "https://files.pythonhosted.org/packages/81/a5/a513b76c139a3915b43404324e55c0b7979ae4f0d39eb6f075b0282e90a8/markupsafe-3.0.4-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:6da83a088f8ef93b2d483a8232a4dbf4d69d3d8496b568a03c56becac43e1808", size = 22961, upload-time = "2026-10-02T23:04:41.372Z" }, + { url = "https://files.pythonhosted.org/packages/46/cf/4c66192c100b4542bcbe392ae06696b670f66927be3ac38a213234778ff9/markupsafe-3.0.4-cp311-cp311-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:8f0fac8b13d14bb06c68195f849371924ae53dd7b1c00fed24650f704383b692", size = 21920, upload-time = "2026-10-02T23:04:42.429Z" }, + { url = "https://files.pythonhosted.org/packages/cb/17/ac3662678bfbad649893117ada2ba44dc30bf56884e84f13154a792b10f1/markupsafe-3.0.4-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:4a7cdc2a420ca01058182da4253329764d4bfa055564d1eced90e6ba1e8b1d3d", size = 23726, upload-time = "2026-10-02T23:04:43.531Z" }, + { url = "https://files.pythonhosted.org/packages/f7/af/fe47cee339180a69ebca3c57fb3483d0f5cbd1e8337d1871fb1d9c1aebee/markupsafe-3.0.4-cp311-cp311-musllinux_1_2_armv7l.whl", hash = "sha256:83b3944fea42a8400edf92fd1770fb8d0d4f7de651353bd2d8525a92dba69a21", size = 22539, upload-time = "2026-10-02T23:04:44.618Z" }, + { url = "https://files.pythonhosted.org/packages/12/32/d55440ba140442800e02d799c9cb5ab597bf6ebdb1177b5ea39a11f797bd/markupsafe-3.0.4-cp311-cp311-musllinux_1_2_ppc64le.whl", hash = "sha256:8138eb83940ec7299024d92d4dee45f601b9e6c5ffde9d25f4e35e326203c707", size = 23963, upload-time = "2026-10-02T23:04:45.656Z" }, + { url = "https://files.pythonhosted.org/packages/50/9d/9c86042cb364c2ad4c971e6d1247929effd25f714cd7ee11b05e6316445b/markupsafe-3.0.4-cp311-cp311-musllinux_1_2_riscv64.whl", hash = "sha256:811d02d5122171c1941357efd8f9bf4ffe907b7f0a1a4e729a880e4be3f46e3e", size = 21506, upload-time = "2026-10-02T23:04:46.671Z" }, + { url = "https://files.pythonhosted.org/packages/75/ef/5b824f03ba40c3b3652b6272d083d2fc4fcdd440de519a3a39ba2c3e7262/markupsafe-3.0.4-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:50b5bedc9ed8a94fc8857a42ef4f84a81ea88f8d4f05dc8705fb23ee6d8dcca7", size = 22955, upload-time = "2026-10-02T23:04:47.698Z" }, + { url = "https://files.pythonhosted.org/packages/1e/e8/44cfcb5ea40e5e43cec7793ef90704ed0c475280839076c4345757eb8e59/markupsafe-3.0.4-cp311-cp311-win32.whl", hash = "sha256:2e5a7cd7fdd14fcb1ae5d7d8bf23d24fbd1daefd1fbca2580132e1ea75f098b5", size = 14094, upload-time = "2026-10-02T23:04:48.788Z" }, + { url = "https://files.pythonhosted.org/packages/91/89/f2b509f7bf79352e40117824c1070dbeafd4df67031d3fa98165a3134228/markupsafe-3.0.4-cp311-cp311-win_amd64.whl", hash = "sha256:fdb4ca07ab75ffadab4a8b135ad59cdbb3156b99310f3d565370da74a15d6bd3", size = 14328, upload-time = "2026-10-02T23:04:49.801Z" }, + { url = "https://files.pythonhosted.org/packages/2b/5a/ccf22672a0f64dc682306e288f0dabcb06c7a201f3bb6e6cbf86d9e8ad03/markupsafe-3.0.4-cp311-cp311-win_arm64.whl", hash = "sha256:569d65055d367e3dcdf30c3f41119467b73d9ee9faf332bdf40402644f5ac08e", size = 14188, upload-time = "2026-10-02T23:04:50.847Z" }, + { url = "https://files.pythonhosted.org/packages/81/09/4c59d56b8461ae8eb0d8ba34bb25b7e618547044679d58a82ef9b2479fc1/markupsafe-3.0.4-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:61631e08084be9e21a8967ec3139c7616ed7c5e9368e05c86d1b39562c8a57b6", size = 11658, upload-time = "2026-10-02T23:04:51.876Z" }, + { url = "https://files.pythonhosted.org/packages/a2/f0/d6613774d86fbf6d145751d43c59875e47a6f9f17daee0aef173bd36d90e/markupsafe-3.0.4-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:0930db9bdc62d22944e10b066448bb65dc9abe9112880c7cab8da54db4284d5f", size = 12050, upload-time = "2026-10-02T23:04:52.931Z" }, + { url = "https://files.pythonhosted.org/packages/0d/f2/8f18e0b806eb13c1f8d07d917a720831ead54253a6dec011fbc78098a6f8/markupsafe-3.0.4-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:6a45c3d514f2436064db00d7fc8778d888f0236ebfed649b53d13a59e69ad51b", size = 24363, upload-time = "2026-10-02T23:04:53.895Z" }, + { url = "https://files.pythonhosted.org/packages/60/ce/fa07dbe8a5675558fa36dea033e19995bc783de2dec5f540ccb9030b06aa/markupsafe-3.0.4-cp312-cp312-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:1e1451fab512d1bcc3dc26988ec1edb0b82c2db909132872cd9356070a6b63df", size = 28525, upload-time = "2026-10-02T23:04:54.905Z" }, + { url = "https://files.pythonhosted.org/packages/85/40/be87c01f3868ec217f8a2015089d71c22c8c5a75324822e5ed1cdd87210d/markupsafe-3.0.4-cp312-cp312-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:bd3ce56ae2cbae3ba82b683bc425cd7e48d2ed8b10f3e818186b6f5646d9271c", size = 24733, upload-time = "2026-10-02T23:04:56.229Z" }, + { url = "https://files.pythonhosted.org/packages/4f/a7/aeedb5140afa41fc74c225e9184ab96723a6e873b6ee1c9fede7283456d8/markupsafe-3.0.4-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:8e124f974786f831d6043728e38296969d3579db8896fe004682f5758e613581", size = 22985, upload-time = "2026-10-02T23:04:57.521Z" }, + { url = "https://files.pythonhosted.org/packages/c3/fc/e91352bb08c6a59da3ef0909d457bf95a5f5908fbf151b30a06d9dbcfbb4/markupsafe-3.0.4-cp312-cp312-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:c02e8f18bdedba082cef725942ac823b9b60656db07f7e265cb31618dfd00d77", size = 22001, upload-time = "2026-10-02T23:04:58.597Z" }, + { url = "https://files.pythonhosted.org/packages/5d/f8/bffee5e7d2a3deb59748a797650a48af7e672025cf641a79344a771ad106/markupsafe-3.0.4-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:9f098115c247e11d138ab83a28fa0323c77015007ea2df73ba5fd714dfefd67c", size = 23793, upload-time = "2026-10-02T23:04:59.686Z" }, + { url = "https://files.pythonhosted.org/packages/ed/59/b853d6628ecb4d658e1d637224846d5e9bb4adf4f8df97f3be9f29dce2ec/markupsafe-3.0.4-cp312-cp312-musllinux_1_2_armv7l.whl", hash = "sha256:d5f93ebbeb8032d47e349328ec8662d973d9b05a70b3c35df1f91fe419b84749", size = 22640, upload-time = "2026-10-02T23:05:00.768Z" }, + { url = "https://files.pythonhosted.org/packages/09/b2/1506df394f0f075797c418d0301498f49e43be194e3ffcb49e6fe6ccf022/markupsafe-3.0.4-cp312-cp312-musllinux_1_2_ppc64le.whl", hash = "sha256:64511c54db4e4987aef4c41923235927428729e8174c5dba488429be70a998ed", size = 24074, upload-time = "2026-10-02T23:05:01.813Z" }, + { url = "https://files.pythonhosted.org/packages/c7/81/5ed69cda630ac69ef60d06c09ba5a7f84ff66a2e28cf986fd5614ab3c6e6/markupsafe-3.0.4-cp312-cp312-musllinux_1_2_riscv64.whl", hash = "sha256:e1a622f13970d81f95d0c72f9dc090dce9085fccfa4c9f2174377ee32bd15786", size = 21563, upload-time = "2026-10-02T23:05:03.239Z" }, + { url = "https://files.pythonhosted.org/packages/0c/fe/fb1e79be0fea60aa32602ebefc9c35a82bb42b4df157285ab7dfec12341a/markupsafe-3.0.4-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:c9a7f43c0b202b334cc9184af09bb8f21d3a209e038efaf106936fb69e6b026e", size = 23048, upload-time = "2026-10-02T23:05:04.479Z" }, + { url = "https://files.pythonhosted.org/packages/c8/52/7632a53360671a9b750cdbabaf9cdd89f18b42248b8e4cb42c0b0296e459/markupsafe-3.0.4-cp312-cp312-win32.whl", hash = "sha256:f0ec3b750b59375eab5b0fb2b9254810c00a3375be6d789899f1055a1d556237", size = 14108, upload-time = "2026-10-02T23:05:05.513Z" }, + { url = "https://files.pythonhosted.org/packages/3f/bf/62495e180b7000aaf30000fff849e933f74264638057176cf46852500adc/markupsafe-3.0.4-cp312-cp312-win_amd64.whl", hash = "sha256:11935df9bf455ed0c04eb87bcd720f02b1fe5e02128a9430f23aed6f93336fc7", size = 14303, upload-time = "2026-10-02T23:05:06.538Z" }, + { url = "https://files.pythonhosted.org/packages/c5/8e/4c24208776a65878d656996945aacfbfe010d3720d1a98fc0eb8491fc03b/markupsafe-3.0.4-cp312-cp312-win_arm64.whl", hash = "sha256:a4bbd2d87dd233b9fc5812160c3d0ffbe42edc22a26ce0469f58479ede633fe9", size = 14174, upload-time = "2026-10-02T23:05:07.617Z" }, + { url = "https://files.pythonhosted.org/packages/6d/18/4bc5ba32499e87bb2b0ef5b3a9bb9c00a131fa961ddf0be548cb550f548b/markupsafe-3.0.4-cp313-cp313-android_24_arm64_v8a.whl", hash = "sha256:de8b364c423ef0a4bad9069657d617f9a5d2b2062457a89b1fa16ee199c399c1", size = 12786, upload-time = "2026-10-02T23:05:08.709Z" }, + { url = "https://files.pythonhosted.org/packages/4e/6f/17f0c099bf25f3e31e63cc19244d9f6af861a9a4ab778c203997903cfdd0/markupsafe-3.0.4-cp313-cp313-android_24_x86_64.whl", hash = "sha256:34bdde374c5932765d7dc685c4a1d191a3207852d67e8e0a9eb6ea85156181f1", size = 12510, upload-time = "2026-10-02T23:05:09.93Z" }, + { url = "https://files.pythonhosted.org/packages/11/af/1a141081b905036ee904ec4bd945e1f70b4e1b32d33c4e59e8cf1d58b247/markupsafe-3.0.4-cp313-cp313-ios_13_0_arm64_iphoneos.whl", hash = "sha256:6bd9e1788e15bfcf6a9082de42e30387e7b85d211ab21e57a939bb8cfaaf8d96", size = 11583, upload-time = "2026-10-02T23:05:10.884Z" }, + { url = "https://files.pythonhosted.org/packages/e7/0a/a89385ae590232622a03e091805cff12f24fabe6c11e0e8bae096cece81c/markupsafe-3.0.4-cp313-cp313-ios_13_0_arm64_iphonesimulator.whl", hash = "sha256:5066b244f576f91afc8ee3ba029a89f99d39c79b1853fe9d39bea9f0afbec148", size = 11801, upload-time = "2026-10-02T23:05:11.913Z" }, + { url = "https://files.pythonhosted.org/packages/ed/85/ea548dc013962eb73653124bc595635fbf9e0fa41d1f181a967ccb784dfb/markupsafe-3.0.4-cp313-cp313-ios_13_0_x86_64_iphonesimulator.whl", hash = "sha256:7a83aa6e4805df46fed18e989d3d16f86ef60cb50bbc8d9ce3a6be89165fbf6e", size = 11443, upload-time = "2026-10-02T23:05:12.887Z" }, + { url = "https://files.pythonhosted.org/packages/cc/72/15f2e5ec9cf2eb00d5cdfe968d94e4156a7bd7303832c3f3b2c403a36839/markupsafe-3.0.4-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:2d1b7d9308288661f56672b1b157d75fc536714d3638487bbea17b6318a78248", size = 11665, upload-time = "2026-10-02T23:05:13.829Z" }, + { url = "https://files.pythonhosted.org/packages/ca/e0/4030bea613677e333c8a2c901fd405055f657f9d06acba5b7357984b6ef7/markupsafe-3.0.4-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:73e77980c7207854f00fc4e71fb1626868d5740ab4012623d55c7a99ad122a72", size = 12061, upload-time = "2026-10-02T23:05:14.807Z" }, + { url = "https://files.pythonhosted.org/packages/f3/a5/28b76a7449eb702966b88bef599e2360b411fbb3afeee8fe560939be06ec/markupsafe-3.0.4-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:7018d4af1cd272e847aa5917983ab5e83e4f6579f9dbfecd4a79c0ca80b144c2", size = 24395, upload-time = "2026-10-02T23:05:15.909Z" }, + { url = "https://files.pythonhosted.org/packages/07/6c/21232811afc3a063b5e934b1ae2efda52f46154ec382f585149c020e61fe/markupsafe-3.0.4-cp313-cp313-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:c90d5b3d4e944e065a301d741b3c1d784f6bd1f503aa68b4967e32b2ba313d85", size = 27183, upload-time = "2026-10-02T23:05:16.976Z" }, + { url = "https://files.pythonhosted.org/packages/14/38/6ccdfa5b59049cb36fb80cbc80aee9cf1fc9bb77d1335ad435f2070b08cf/markupsafe-3.0.4-cp313-cp313-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:18a801868a884f216e784d7d14db2a4077143ce7610440aee2ce8f734e7cfcde", size = 24772, upload-time = "2026-10-02T23:05:18.209Z" }, + { url = "https://files.pythonhosted.org/packages/63/e0/cec6865dfe88cb48fedd4b20aed6af5158e41092adcbf3e028bcc6ec2108/markupsafe-3.0.4-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:434139499bb20b502ed3baa1f169e618f924a97e7a777fea1a49446d80106cf6", size = 23017, upload-time = "2026-10-02T23:05:19.286Z" }, + { url = "https://files.pythonhosted.org/packages/ee/76/6ed4940bb7648a9aac457c14f870cfdd5105f139a0fb1f29cd61fafa47d1/markupsafe-3.0.4-cp313-cp313-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:9e227f3dbe6bde7491cf0a9965d00b88c6b1a4a95d11480ddf88bb96d397c19f", size = 22036, upload-time = "2026-10-02T23:05:20.352Z" }, + { url = "https://files.pythonhosted.org/packages/a1/4f/ed476226d4fe46a09090a36025bf319296810028df55eb12f1253b540f3a/markupsafe-3.0.4-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:b8cd1f918b26fd7b1832ece557cc18f2d8747309ff8b3f0ef9d4250c5ad67a39", size = 23786, upload-time = "2026-10-02T23:05:21.576Z" }, + { url = "https://files.pythonhosted.org/packages/9a/35/66ff30450e35ef5fba9ebc930c9411747e537fd9447b65e44f5007e2b84d/markupsafe-3.0.4-cp313-cp313-musllinux_1_2_armv7l.whl", hash = "sha256:a5fcffb37e602b0b3c1638a97746b9b96125caa9bcf6fa41d337a9261de231ee", size = 22672, upload-time = "2026-10-02T23:05:22.922Z" }, + { url = "https://files.pythonhosted.org/packages/32/0b/72f45ce4b4efcbca4b80cf1b06703eff0be8d37e82abb78f66c85a7ead1e/markupsafe-3.0.4-cp313-cp313-musllinux_1_2_ppc64le.whl", hash = "sha256:5989cb26b2e1efc6a42216a9f6b5ee495ce5ace2e5b352a9af489976b32d1ee2", size = 24107, upload-time = "2026-10-02T23:05:24.175Z" }, + { url = "https://files.pythonhosted.org/packages/d2/03/71776e5fdcba04614b384cc102e8a4198208579d896fd1394cb7cb9aa900/markupsafe-3.0.4-cp313-cp313-musllinux_1_2_riscv64.whl", hash = "sha256:add96447a86d205ab616665d53b2950ee81083757f56e6ea833c8b2917646b46", size = 21615, upload-time = "2026-10-02T23:05:25.215Z" }, + { url = "https://files.pythonhosted.org/packages/ab/5f/801ce02a02e7aee0f784b1ec7843026178f6adeb9c93ac67eb1992a9a84d/markupsafe-3.0.4-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:2628d3a8cb648ecebb3c5d6b0a1052d400e4d8b7ac0fb786be8d285b50040d17", size = 23076, upload-time = "2026-10-02T23:05:26.423Z" }, + { url = "https://files.pythonhosted.org/packages/4a/85/c43776625428f3bb4a61e8633940400e3efe6409e3c6f5bff26de5e45618/markupsafe-3.0.4-cp313-cp313-win32.whl", hash = "sha256:672d207103e6b16ca098611b0f9efad6bc00afd47c03d6ef62186495ca677dc0", size = 14118, upload-time = "2026-10-02T23:05:27.716Z" }, + { url = "https://files.pythonhosted.org/packages/6f/36/163da64de88a13db79214ef75fa041be7fa13bdb42261cf5b7484de14bfb/markupsafe-3.0.4-cp313-cp313-win_amd64.whl", hash = "sha256:1f1f9477e174582b0a1b583d60b66e1f2cf5d3fe12cee985e4aedf44766600e5", size = 14313, upload-time = "2026-10-02T23:05:28.749Z" }, + { url = "https://files.pythonhosted.org/packages/9f/a8/9b662783ffaa1149221432a923cee562f78b9cbbb8baa3df9b3753e63e1e/markupsafe-3.0.4-cp313-cp313-win_arm64.whl", hash = "sha256:06de8ef6331f6e822c28d577dc8bf43fe398800477c49498f38fc38b67ff33fc", size = 14189, upload-time = "2026-10-02T23:05:29.917Z" }, + { url = "https://files.pythonhosted.org/packages/5c/c3/a944f3b0df22bd129e96915b9f4e98d2eeca6516687d7618304a966c3c74/markupsafe-3.0.4-cp314-cp314-android_24_arm64_v8a.whl", hash = "sha256:4ed644d75aa94a2baf7ec3a96eaa160ea58c742eb9d27c6506053c5c40fc84ed", size = 12787, upload-time = "2026-10-02T23:05:30.971Z" }, + { url = "https://files.pythonhosted.org/packages/d4/d6/a44863f69d88b6c7e27889108f70d47aed259edf89d5df3c5fca1eac87d6/markupsafe-3.0.4-cp314-cp314-android_24_x86_64.whl", hash = "sha256:6d2a9efe686f9de00d0d1ea32a4a5a86d558a2277501bd78d964214eab625e59", size = 12525, upload-time = "2026-10-02T23:05:32.263Z" }, + { url = "https://files.pythonhosted.org/packages/17/8f/168ba80e532dd6a93f96f8f706f1ad41d7990b6e1aeedc1cc0d211a33497/markupsafe-3.0.4-cp314-cp314-ios_13_0_arm64_iphoneos.whl", hash = "sha256:8781a792a070cf2bd1b86d3aa943894115faaba6e88122a7bf32d62072742453", size = 11589, upload-time = "2026-10-02T23:05:33.251Z" }, + { url = "https://files.pythonhosted.org/packages/32/b3/aa2c95a574d3af39403a469b295886eb9b6d448da568cbebb5a2cbfdc2e5/markupsafe-3.0.4-cp314-cp314-ios_13_0_arm64_iphonesimulator.whl", hash = "sha256:971a3bbb75d97ae4e2e8f7d4834236f86f85f0c85e04ab2e191db1123b04f80b", size = 11801, upload-time = "2026-10-02T23:05:34.315Z" }, + { url = "https://files.pythonhosted.org/packages/60/d0/34b810107d83840e768bf485de795893ebbae35b26ab061b487adfa0a692/markupsafe-3.0.4-cp314-cp314-ios_13_0_x86_64_iphonesimulator.whl", hash = "sha256:8909c2f1c6dd65e054ac4b573a91c8384d1492281e55d82d159d653f7a13adf6", size = 11447, upload-time = "2026-10-02T23:05:35.302Z" }, + { url = "https://files.pythonhosted.org/packages/6c/ab/2f8488f0f817a39fca068d2b17daf446bf5cdb3eae28c3720af534d873b4/markupsafe-3.0.4-cp314-cp314-macosx_10_15_x86_64.whl", hash = "sha256:4cf3468d5ec187ffffcaca8e61929a37448f215dafc1386a12c750a72fe53634", size = 11722, upload-time = "2026-10-02T23:05:36.363Z" }, + { url = "https://files.pythonhosted.org/packages/ad/40/e2d117b048d47282ade906fbfd92814cbee5647afc13fda88a3406039372/markupsafe-3.0.4-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:52704c5d36eb6dda8866493decd61111fff86244c9b1ad225ca01b9e91e5970f", size = 12061, upload-time = "2026-10-02T23:05:37.397Z" }, + { url = "https://files.pythonhosted.org/packages/9a/a8/73a81135e85ba66217f5af7facb03bbb386807e1a729ab64532e4c802652/markupsafe-3.0.4-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:1caa2fa5a6184fb233153b35f654e6687bd555476f6170f29d8ee9be1a8b0af9", size = 24434, upload-time = "2026-10-02T23:05:38.407Z" }, + { url = "https://files.pythonhosted.org/packages/ac/ca/fa9216dd01efee2dfdacafe7df32b4d0170fbac694b0c258a193d6e53999/markupsafe-3.0.4-cp314-cp314-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:387d8cd30e69b3f0a72877b9ae717033396404e19095b17fe89753a981fda44f", size = 27183, upload-time = "2026-10-02T23:05:39.581Z" }, + { url = "https://files.pythonhosted.org/packages/fa/4e/a469509e538d37af51103b17b073126973f2b1cbf197ff32c7ddf025cfe5/markupsafe-3.0.4-cp314-cp314-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:051417f74bcaaefa316276e0ff723f541616ca51043d070da00249d9bddd3e3c", size = 24813, upload-time = "2026-10-02T23:05:40.671Z" }, + { url = "https://files.pythonhosted.org/packages/8f/db/d7282caf7ab03af44d5d6fdbaa019b35c7d7f1c90588b839c07cba640d6a/markupsafe-3.0.4-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:a8e9f292fcda89b324f2f5c91d13f1424a153e40fc2756f38ee23b15835ff300", size = 23049, upload-time = "2026-10-02T23:05:41.864Z" }, + { url = "https://files.pythonhosted.org/packages/30/f3/b6a425206e6964efda6acee544d0eb01d1501784d0b8e2dcc74986f33b17/markupsafe-3.0.4-cp314-cp314-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:df1ae86ff54725a01fa1a0510b914ca53a161b7050be74f6204e24aded5971d0", size = 22088, upload-time = "2026-10-02T23:05:43.014Z" }, + { url = "https://files.pythonhosted.org/packages/ea/8a/84d3582fc1f0d5bd466cdf2eebf175e172158a6e70701aacec1de1b35430/markupsafe-3.0.4-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:8965520ac587c94a4ac48b729be3d8b8de00af39699b17585dfb599babe77977", size = 23846, upload-time = "2026-10-02T23:05:44.098Z" }, + { url = "https://files.pythonhosted.org/packages/1c/65/db101cce51b7ba4864ac491a9859d297dd1adf0e55b103fee9db9c47c527/markupsafe-3.0.4-cp314-cp314-musllinux_1_2_armv7l.whl", hash = "sha256:340cbb1957ba99929cbf19a75626d36ba1ae21d1730b287d1cf7f824a20c4fc7", size = 22674, upload-time = "2026-10-02T23:05:45.23Z" }, + { url = "https://files.pythonhosted.org/packages/e0/49/ddee9813d71db0c7a5c9d97c832125e6758a0c844777f1cf076569bb0e22/markupsafe-3.0.4-cp314-cp314-musllinux_1_2_ppc64le.whl", hash = "sha256:3a93d9616ddecfb393727a0041a562cf0b15a244e20f2bd25efc7949be4c4f17", size = 24104, upload-time = "2026-10-02T23:05:46.398Z" }, + { url = "https://files.pythonhosted.org/packages/aa/0e/7d8518d726726870a2399d69fd30d0fa36c5e57a2132c336b58d7c491073/markupsafe-3.0.4-cp314-cp314-musllinux_1_2_riscv64.whl", hash = "sha256:d2e56fd3b00222722abfb3f5f0759ddbae4b90811b5ad4343c64030ad1bde70c", size = 21637, upload-time = "2026-10-02T23:05:47.48Z" }, + { url = "https://files.pythonhosted.org/packages/b4/b0/b505e8a361ba557dbf3b3aa7331ea39b00d2022a26e925ff8463b9714bb3/markupsafe-3.0.4-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:0d9c47709875fdb321452056622e930c52afbc07a7d780762fbb8b4d91ce6fa4", size = 23081, upload-time = "2026-10-02T23:05:48.611Z" }, + { url = "https://files.pythonhosted.org/packages/1c/ea/9cc3cea873f980c75cbdb6f4277ce30ee955de38be0b3d02f14c108e0698/markupsafe-3.0.4-cp314-cp314-win32.whl", hash = "sha256:38fc55594dab834470b6733dead2ee9e3f657fb0608c769dcafa0ba5ab52f45c", size = 14272, upload-time = "2026-10-02T23:05:49.707Z" }, + { url = "https://files.pythonhosted.org/packages/80/f0/5792ff768a410f93ee3f84fc19345295ffc352d2c936b424cb37e514714c/markupsafe-3.0.4-cp314-cp314-win_amd64.whl", hash = "sha256:c1bc67752d5f21013cfe430df4062441714eab79f65a6a05e01505957e9c35fe", size = 14501, upload-time = "2026-10-02T23:05:50.788Z" }, + { url = "https://files.pythonhosted.org/packages/5f/cf/3d074a8edffcc6899355232ff2543ae8d929733239596423b7db79698bc9/markupsafe-3.0.4-cp314-cp314-win_arm64.whl", hash = "sha256:7e1636da3d8dfc220b6dd10264db5f2b165e4888c4518594898fbe381049af8a", size = 14364, upload-time = "2026-10-02T23:05:51.857Z" }, + { url = "https://files.pythonhosted.org/packages/d9/31/87ce42159aae2163cf3bbbd0c44bc87780510eecab1ea3859099aed95dcb/markupsafe-3.0.4-cp314-cp314t-macosx_10_15_x86_64.whl", hash = "sha256:805c8b84534fa10891890f0e4be39f3a99e94615d93e8836bf9fa1fdca2feeb2", size = 11759, upload-time = "2026-10-02T23:05:52.951Z" }, + { url = "https://files.pythonhosted.org/packages/5f/53/b047207eeb7752e960aca3eb1df5fb7eefa7dd4c62ac49bb156456c8a702/markupsafe-3.0.4-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:fa95848c929b6a75f6848d3c9793e59db365ee436776e57db835cdbfa79ba977", size = 12096, upload-time = "2026-10-02T23:05:54.066Z" }, + { url = "https://files.pythonhosted.org/packages/ee/51/4326c88a13c7b755657d44b4bb986f8c3d9843ecba7e22d98661d87f9a57/markupsafe-3.0.4-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:e916035e3e9930cbdfdd10abf48861340221857f45509565898e012263f7b289", size = 25699, upload-time = "2026-10-02T23:05:55.15Z" }, + { url = "https://files.pythonhosted.org/packages/f2/bb/990581b7474bfcf2cf34bed6ba5ea23bd87adb9d671213d68e88620e7a6b/markupsafe-3.0.4-cp314-cp314t-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:b4d12837e0203bbace818ff4a7461afdcd78bcd782351cea148139180d7bcffe", size = 27804, upload-time = "2026-10-02T23:05:56.29Z" }, + { url = "https://files.pythonhosted.org/packages/6b/89/89491878c28e8291f5aa2fffe2c2d57230d10ae366d55dd810b840513d78/markupsafe-3.0.4-cp314-cp314t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:5086f9975abb1ab531ee6afca1761e4b59a19b446f3f6522ed776963228cfe5a", size = 25912, upload-time = "2026-10-02T23:05:57.416Z" }, + { url = "https://files.pythonhosted.org/packages/30/77/680998b54efdea06fc114565cd739b6d059f826a0279219b218dfa750d29/markupsafe-3.0.4-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:b4a635a0487774f841cb1fb62e907e7195cc95bc761e053184b8acc3ceb20733", size = 23623, upload-time = "2026-10-02T23:05:58.557Z" }, + { url = "https://files.pythonhosted.org/packages/ae/75/2709f5ac5de9467b40b10e2bb8f89cc63dfb74582e09aa734b1124a217de/markupsafe-3.0.4-cp314-cp314t-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:cb96e6e088d6cf71c1ea977510948320234824cf226e32f6f6e044f7a9c82b34", size = 23301, upload-time = "2026-10-02T23:05:59.94Z" }, + { url = "https://files.pythonhosted.org/packages/a0/c8/39eadc6c5b14c9c7679bfb98f4d4c6a97863b5beb91839aca4d2d6e16e55/markupsafe-3.0.4-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:8b5d563170ff8ba3181caa967c99a3c804d1dedb702c7cb93a6a7c32247da978", size = 24950, upload-time = "2026-10-02T23:06:01.289Z" }, + { url = "https://files.pythonhosted.org/packages/1a/5e/01037f8a43e8ccb0bffb4fbdc5212db05bf080fdd7286cd392332d58128a/markupsafe-3.0.4-cp314-cp314t-musllinux_1_2_armv7l.whl", hash = "sha256:396ec4e65cc889f69786b3b89478b471cee5a3bcf468b9d9bb03e1a30fb291fc", size = 23330, upload-time = "2026-10-02T23:06:02.441Z" }, + { url = "https://files.pythonhosted.org/packages/d4/f4/23e83ce0596bb0cbe670502d31df8f757bbd01a392aa486fa3b40d1ed399/markupsafe-3.0.4-cp314-cp314t-musllinux_1_2_ppc64le.whl", hash = "sha256:15ba9e28640feef770374b116a6f019c21f52404aeabe516aa7f800587b98cfc", size = 25239, upload-time = "2026-10-02T23:06:03.579Z" }, + { url = "https://files.pythonhosted.org/packages/88/5b/3708897368073cc683d524750474f41a77d2986152c380dcc55b20fdf340/markupsafe-3.0.4-cp314-cp314t-musllinux_1_2_riscv64.whl", hash = "sha256:d920abdfa61279ba1a2ef9484aab07bf03331f8c08a10120fa332353d06e6932", size = 22767, upload-time = "2026-10-02T23:06:04.699Z" }, + { url = "https://files.pythonhosted.org/packages/c6/61/ebda1307864b409e6b3115757a3d4a09cca46cfb6cc65191b5de226b424b/markupsafe-3.0.4-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:a9f54054101545a9a9cccefddf54316aa6e4491611fcbef9e91b3b6bebec04f6", size = 23668, upload-time = "2026-10-02T23:06:05.9Z" }, + { url = "https://files.pythonhosted.org/packages/09/15/98075cceac3b5ba0dbb8e4762a847be967d2befc349a2cf2d0ac77f62c9d/markupsafe-3.0.4-cp314-cp314t-win32.whl", hash = "sha256:12a606a492de952afcb43b59a14aaaaad120e708d3663dd0fdf2d738d427a691", size = 14301, upload-time = "2026-10-02T23:06:07.109Z" }, + { url = "https://files.pythonhosted.org/packages/0b/a3/768b560fcc4156685cb563d922b217810cfa7bc135773367f62f1f9d2078/markupsafe-3.0.4-cp314-cp314t-win_amd64.whl", hash = "sha256:a18f38cafc329bac5e3c2b96c765b4c96d3d103421ed22ab7988c1e3fce27464", size = 14526, upload-time = "2026-10-02T23:06:08.276Z" }, + { url = "https://files.pythonhosted.org/packages/93/63/da554b4c97a6b0ea3229ca7fe8cbfb620be81613d517f482e85958550537/markupsafe-3.0.4-cp314-cp314t-win_arm64.whl", hash = "sha256:eba154571c16e032112afac0dc2dfe9e63c2ceb7aedd07bb7eecf2ce26d4dd4c", size = 14421, upload-time = "2026-10-02T23:06:09.402Z" }, + { url = "https://files.pythonhosted.org/packages/a9/30/54d11c8ca027114898cab97421fb39e4ffd9ddf47cdbc44df2ec76722da9/markupsafe-3.0.4-cp315-cp315-android_24_arm64_v8a.whl", hash = "sha256:737c9c3981998eba27f11786f84fddcbabc74068b72a4a1f454ea02094b57b65", size = 12791, upload-time = "2026-10-02T23:06:10.485Z" }, + { url = "https://files.pythonhosted.org/packages/10/6d/97c913e253a14bd3cd0e15a5c56d13203b823fa7ee32498342896a072dc4/markupsafe-3.0.4-cp315-cp315-android_24_x86_64.whl", hash = "sha256:489505b03f692c3f376394e49194fa7a7f9e8558d6e293a7056a0032b0c38163", size = 12527, upload-time = "2026-10-02T23:06:11.834Z" }, + { url = "https://files.pythonhosted.org/packages/26/f9/b86d032042a4d597d9e1997f0e5f63a3eedaf11258e0a05760b0a0a826ea/markupsafe-3.0.4-cp315-cp315-ios_13_0_arm64_iphoneos.whl", hash = "sha256:077293e425f28ec737dbcad442a71752e28f8ae27cde3d68acd1fb212091cd92", size = 11602, upload-time = "2026-10-02T23:06:13.122Z" }, + { url = "https://files.pythonhosted.org/packages/f2/dc/73c14c1eedf0ac5fa3292ba43435e6c49d2c2050f33cebde541f8f4807f1/markupsafe-3.0.4-cp315-cp315-ios_13_0_arm64_iphonesimulator.whl", hash = "sha256:9348cbb300d224fe3b89793262cb093504d4ae927004468463f745188a193e4a", size = 11817, upload-time = "2026-10-02T23:06:14.227Z" }, + { url = "https://files.pythonhosted.org/packages/8f/69/2c2fcaa5fcee22d72c7819c0d536fd181c74a688e6143845419579cd2863/markupsafe-3.0.4-cp315-cp315-ios_13_0_x86_64_iphonesimulator.whl", hash = "sha256:b807e598953730f82e4eae3bd30f6a122cf6b31c398c6b504c0e04c13c170429", size = 11446, upload-time = "2026-10-02T23:06:15.574Z" }, + { url = "https://files.pythonhosted.org/packages/88/54/9e5ec76c62e6e2834d5a93623018c943e8b3bb41d663e3fd4c03303b9b85/markupsafe-3.0.4-cp315-cp315-macosx_10_15_x86_64.whl", hash = "sha256:799c39bdf5e2f1292fedd3009f7b3c9e760f10b2420cb9638d56920840ff6db8", size = 11719, upload-time = "2026-10-02T23:06:16.701Z" }, + { url = "https://files.pythonhosted.org/packages/96/24/3ec292b44064c16229e064d770b2625bd8ea941aa61f44905a9fa44942c0/markupsafe-3.0.4-cp315-cp315-macosx_11_0_arm64.whl", hash = "sha256:ae9dcb8fbe244cb82f8a6458b455b927a03685e383d9bacf1ea5ce180b96dc97", size = 12075, upload-time = "2026-10-02T23:06:17.855Z" }, + { url = "https://files.pythonhosted.org/packages/aa/85/b64fdb1f304848518742136983c24e96d967bfb59a0ea160e92736901ab0/markupsafe-3.0.4-cp315-cp315-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:4bced6e2a6dba6a28f7dd3c6ce14df1b2dd495923f16ea484cad03decd463b2b", size = 24656, upload-time = "2026-10-02T23:06:18.963Z" }, + { url = "https://files.pythonhosted.org/packages/9c/18/23997d4c65b355da6390d61cd56e0ab3befd6ba8dda25cb40c602bd0fa6b/markupsafe-3.0.4-cp315-cp315-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:3882fb412298575bae3b9c46868251f15cc69307359f87bb1b382e53d6e5a2c9", size = 27737, upload-time = "2026-10-02T23:06:20.117Z" }, + { url = "https://files.pythonhosted.org/packages/d4/36/35998dead3c6af88c38265a56e58100211f036234ab88eb2283fd4cbce44/markupsafe-3.0.4-cp315-cp315-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:04e7902ba80ee4bac1d50a549606527a1dcf0476cd81403db41099d3b60ec653", size = 25003, upload-time = "2026-10-02T23:06:21.284Z" }, + { url = "https://files.pythonhosted.org/packages/82/96/ef49135ce260db4ca4a12b119ed468449cd248db6b1468e2112b546d7a2e/markupsafe-3.0.4-cp315-cp315-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:925f929d6b59a8b3f8b8c6ac363cd0af7eecc81efb3071770b3c6717c450a369", size = 23111, upload-time = "2026-10-02T23:06:22.524Z" }, + { url = "https://files.pythonhosted.org/packages/50/7d/83126e338bd88c17a220668235368ad719fd4638e426739858cbb8508f77/markupsafe-3.0.4-cp315-cp315-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:f68edfc67aabac33708941f26f22a7b8e9f81429bc0cf249fcf7d66b23af8d19", size = 22403, upload-time = "2026-10-02T23:06:23.785Z" }, + { url = "https://files.pythonhosted.org/packages/83/dd/daf7e420de23c8206c365204e7b85e1251d8e19d34196a56336f316e5ed2/markupsafe-3.0.4-cp315-cp315-musllinux_1_2_aarch64.whl", hash = "sha256:e5c802729725bd07e2bc3ab7b76dc7e0bbfc53129d8f1eb1c002c24cf774717e", size = 24083, upload-time = "2026-10-02T23:06:25.037Z" }, + { url = "https://files.pythonhosted.org/packages/19/3c/11eecdc06bc44ad5570350085b572ebf049e8f9a38d1ece6d76640b739cd/markupsafe-3.0.4-cp315-cp315-musllinux_1_2_armv7l.whl", hash = "sha256:55ffd6ce583d97dc71dc92e930324c8c0d25aea7e3ade6ae54ef77cedb096811", size = 22931, upload-time = "2026-10-02T23:06:26.328Z" }, + { url = "https://files.pythonhosted.org/packages/0d/9e/ac0fd77f2a726e56ecc3ca0235d095feace1358d1b822406c2a2ef26a4dc/markupsafe-3.0.4-cp315-cp315-musllinux_1_2_ppc64le.whl", hash = "sha256:2cb3dd71fc6be918ad4264346a8ed69485f9b7ed7bf35495d8e22807cd6b8bea", size = 24299, upload-time = "2026-10-02T23:06:27.742Z" }, + { url = "https://files.pythonhosted.org/packages/d7/09/c6bd842ad58ff5b3bc76eeed7e9a42a6f11adc5d090ec697b72c9672731e/markupsafe-3.0.4-cp315-cp315-musllinux_1_2_riscv64.whl", hash = "sha256:94f5407f7bc64fa6463906b896f9904beeeb7dd8dc116ee8e9056c8714ff9916", size = 21948, upload-time = "2026-10-02T23:06:29.274Z" }, + { url = "https://files.pythonhosted.org/packages/a3/46/82f586711fed61e86faa1ee1bc317d68cd45a10c8bdbe3f7d1fdf9026ad8/markupsafe-3.0.4-cp315-cp315-musllinux_1_2_x86_64.whl", hash = "sha256:2dad610540cb2e6272855c178f08ae9a1c7ac258a7fb71660553a5f104b42741", size = 23150, upload-time = "2026-10-02T23:06:30.583Z" }, + { url = "https://files.pythonhosted.org/packages/19/2d/2dfdce99318abbfa26925195fbc17db188c46a1ec6457be121b6f9cfeb42/markupsafe-3.0.4-cp315-cp315-win32.whl", hash = "sha256:03470d1a8268e692ecf79ecd565593e59d44219377a7ead61f1f1b94c1f7ff6b", size = 14269, upload-time = "2026-10-02T23:06:31.949Z" }, + { url = "https://files.pythonhosted.org/packages/5b/ec/6000fd82e8791e58fcd0456ec20f098957e2b03d5ed02eb73241a577c0ba/markupsafe-3.0.4-cp315-cp315-win_amd64.whl", hash = "sha256:d882a373d8093c2941e01291b7ced96e9cbe4781da9a7751ca7e6c70385e5214", size = 14496, upload-time = "2026-10-02T23:06:33.258Z" }, + { url = "https://files.pythonhosted.org/packages/bc/66/e73bd5016421d5d6e2fb6de7dd609f9de020942ac8c626526bd8c6eeaf82/markupsafe-3.0.4-cp315-cp315-win_arm64.whl", hash = "sha256:353bd63081912ab8cfa6a0c7d185934cdf8426f04c618bba6bc4b394f2069b67", size = 14361, upload-time = "2026-10-02T23:06:34.539Z" }, + { url = "https://files.pythonhosted.org/packages/90/df/cb8c3dc98d313a951df2f8968f44e4cb5643df6d3cab749a530ce2f7d972/markupsafe-3.0.4-cp315-cp315t-macosx_10_15_x86_64.whl", hash = "sha256:c61750fadcd119d0825bcb7d7d675dd264dcc89cc05292aab5be68ebdbb374ad", size = 11760, upload-time = "2026-10-02T23:06:35.807Z" }, + { url = "https://files.pythonhosted.org/packages/d6/bb/4af9b3ca0753d654ac75f9531d5bd741bb77ca6e696f36807c475ffc099a/markupsafe-3.0.4-cp315-cp315t-macosx_11_0_arm64.whl", hash = "sha256:1c0df495a977d10460a94941799c72d5b5ab03d3858d949b55b5a66c8f371c99", size = 12108, upload-time = "2026-10-02T23:06:37.089Z" }, + { url = "https://files.pythonhosted.org/packages/3f/d4/b56429313aee5fd59b079c3df5615299959e25e7113eb6d8caadbdd7d38a/markupsafe-3.0.4-cp315-cp315t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:02fa4acbc6a3fc5c693c34d4dd8c1130b7fe99cc915181b0ddd6f72aeb296002", size = 25762, upload-time = "2026-10-02T23:06:38.419Z" }, + { url = "https://files.pythonhosted.org/packages/65/f5/34c181e891aa4f7d59c918584672e0c5eb7fffe76c1387d1246008bf4081/markupsafe-3.0.4-cp315-cp315t-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:05295589e619b9bed252a86b532b8e27350abc372d18ba89b59375325e91ec1e", size = 28400, upload-time = "2026-10-02T23:06:39.819Z" }, + { url = "https://files.pythonhosted.org/packages/ce/b5/ad14694fd0ac9a5ce30bc6498f2999378f418583dd1679cca5a1b512957e/markupsafe-3.0.4-cp315-cp315t-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:be6cb0c799abb0e2ba3e618e6d28ddddf7e485f6c2ce938dfa237daf3905072c", size = 25946, upload-time = "2026-10-02T23:06:41.381Z" }, + { url = "https://files.pythonhosted.org/packages/d6/a8/26b606445387d0ceb1eb1f21840094b84e4e3c3c3983d80d10b89823b490/markupsafe-3.0.4-cp315-cp315t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:26e9867520db70d37f7fb421a7f0d8adb40171011fb84ce869afa1a83370dfa8", size = 23634, upload-time = "2026-10-02T23:06:42.748Z" }, + { url = "https://files.pythonhosted.org/packages/39/a2/b8814de672f1f0094d498bf646f2fec9d6356b503d28ef500b71c5095377/markupsafe-3.0.4-cp315-cp315t-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:f03460ff076f70ab595bb45a0205ccea1971443575b6920c52e755dec2b3fbfe", size = 23488, upload-time = "2026-10-02T23:06:44.176Z" }, + { url = "https://files.pythonhosted.org/packages/db/c7/287223376fb73335a3cc5d6eb22c6ab01358cf33945a9c39c06b9dac3f4b/markupsafe-3.0.4-cp315-cp315t-musllinux_1_2_aarch64.whl", hash = "sha256:436e3ffc6310d3c41878c601db29098102fe5d8a467c49da4a4125254e0980f2", size = 25037, upload-time = "2026-10-02T23:06:45.646Z" }, + { url = "https://files.pythonhosted.org/packages/f9/29/4df8355e313426d19e62ba33e0253c009ca12a0894ee77d67fa67255361c/markupsafe-3.0.4-cp315-cp315t-musllinux_1_2_armv7l.whl", hash = "sha256:4e2c4809c14559aa7ef426f27fb35afbb38104c349a903bf8f3600456764bb38", size = 23543, upload-time = "2026-10-02T23:06:47.264Z" }, + { url = "https://files.pythonhosted.org/packages/71/e5/8377731e8495668dcc768f645e717df18318c841edaf023a99395f6da9b4/markupsafe-3.0.4-cp315-cp315t-musllinux_1_2_ppc64le.whl", hash = "sha256:da2af0d7aebfc2074080d72efa6ab8317c62481ef1f896f65d9999c1c01f4494", size = 25282, upload-time = "2026-10-02T23:06:48.795Z" }, + { url = "https://files.pythonhosted.org/packages/ed/5f/373456e37ceb1478d657d6fe769cbe0a39f0a8dfc1548eeb19c471eefdd9/markupsafe-3.0.4-cp315-cp315t-musllinux_1_2_riscv64.whl", hash = "sha256:aa2c838cc024642cc04c6854232f32b43e5e22833dd11119c1766c7873b8370d", size = 22993, upload-time = "2026-10-02T23:06:50.31Z" }, + { url = "https://files.pythonhosted.org/packages/d7/93/2cbd5628435afb6f541bbaced4bce0c2edac4b09a142e6e928b8b0da9858/markupsafe-3.0.4-cp315-cp315t-musllinux_1_2_x86_64.whl", hash = "sha256:b91cc9d336957239ff200f30097e6fea2dc6d6fb3c81e853eaa09eac904fd894", size = 23712, upload-time = "2026-10-02T23:06:51.759Z" }, + { url = "https://files.pythonhosted.org/packages/81/99/157e10966b033b363aeda5263e82596ee232a0b1d082fdbf90aa417ff083/markupsafe-3.0.4-cp315-cp315t-win32.whl", hash = "sha256:e49fb0d1ce92cfa0cb198cc5b1b11cdf9d0638658e2a2db2687e39db7c87fc78", size = 14300, upload-time = "2026-10-02T23:06:53.241Z" }, + { url = "https://files.pythonhosted.org/packages/33/05/55884815414c9706a23deca150b72c25a62109e65b0b6ce232077802c719/markupsafe-3.0.4-cp315-cp315t-win_amd64.whl", hash = "sha256:4f6e0852a0283b1b1fd776eeb7b766a5f440b3e2bd31ab51af3b400585f3965c", size = 14522, upload-time = "2026-10-02T23:06:54.729Z" }, + { url = "https://files.pythonhosted.org/packages/92/f9/ecbde7149e95b8a0f18e16d5d747f7dc06049d5da2e4f77f6f5e4a1f46a8/markupsafe-3.0.4-cp315-cp315t-win_arm64.whl", hash = "sha256:39dbacefc411633db5b4378b066a9aca70a3d7e2922c9e578d825f844026eeba", size = 14417, upload-time = "2026-10-02T23:06:56.246Z" }, +] + +[[package]] +name = "native-examples" +version = "0.1.0" +source = { editable = "native" } +dependencies = [ + { name = "cffi" }, +] + +[package.metadata] +requires-dist = [{ name = "cffi", specifier = "==2.1.1" }] + +[[package]] +name = "packaging" +version = "26.4" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/c3/75/ffb1dc0ed12352139fb4ca0e3fde4325a23e3d0f3f40efe89717bc4f557b/packaging-26.4.tar.gz", hash = "sha256:c4b671c41ddb9bf26e543c37723610d28fb6bf7affc4da17cf048d419d2c062a", size = 355877, upload-time = "2026-11-23T21:44:11.152Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/ba/7b/5504f91c9c2733f693d7759e50ede5d27119d4da7e5836c46d3b5ff81d56/packaging-26.4-py3-none-any.whl", hash = "sha256:81383611a09c1bc0b08b76e0fd5829d7c6824c65b27a6aee339da133f4233ea2", size = 140049, upload-time = "2026-11-23T21:44:09.531Z" }, +] + +[[package]] +name = "pathspec" +version = "1.1.1" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/5a/82/42f767fc1c1143d6fd36efb827202a2d997a375e160a71eb2888a925aac1/pathspec-1.1.1.tar.gz", hash = "sha256:17db5ecd524104a120e173814c90367a96a98d07c45b2e10c2f3919fff91bf5a", size = 135180, upload-time = "2026-04-27T01:46:08.907Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/f1/d9/7fb5aa316bc299258e68c73ba3bddbc499654a07f151cba08f6153988714/pathspec-1.1.1-py3-none-any.whl", hash = "sha256:a00ce642f577bf7f473932318056212bc4f8bfdf53128c78bbd5af0b9b20b189", size = 57328, upload-time = "2026-04-27T01:46:07.06Z" }, +] + +[[package]] +name = "pluggy" +version = "1.7.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/bf/db/7fc19e6f2dc92a966727031389fc2e08b558f0f25eb7403c1119ad4713cd/pluggy-1.7.0.tar.gz", hash = "sha256:d1eaa46ebb595891b860ab086b4d09c8588af65ebd4361b8e8f4bb8920b90ba8", size = 123304, upload-time = "2026-10-15T09:50:58.343Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/40/9e/2b38731e0fc536806f16490e1a12d7f0dc2a1235aa8cc07bcc75416a7daa/pluggy-1.7.0-py3-none-any.whl", hash = "sha256:7dd7b0d8832ba3cb632c306926ded123429211b83641b35dc5c41ad2d34f9bec", size = 27082, upload-time = "2026-10-15T09:50:56.808Z" }, +] + +[[package]] +name = "prek" +version = "0.6.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/05/61/7741de843f618abf4804f0d58147647f94adea640b1ad4046f3dab6492fc/prek-0.6.0.tar.gz", hash = "sha256:246a582b750d3fd0a7137e28c362585f70940cdcf120b5883186f454090a04cb", size = 641996, upload-time = "2026-12-01T12:09:32.858Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/04/0a/e788dd6623444b9dc233901c9b284037dc1c18ad8940374de191663762a5/prek-0.6.0-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:1f7b5acc4178bc7b1c2dbade630700dad1fc991adbf442ba647a9be4811848d7", size = 6063007, upload-time = "2026-12-01T12:09:16.663Z" }, + { url = "https://files.pythonhosted.org/packages/c6/44/dfd4e1774f40c31e50e103548719adc3ed5a8a30b675d66930cda778255e/prek-0.6.0-py3-none-macosx_11_0_arm64.whl", hash = "sha256:2317331597a7de56fb9ed558dcd29cf013f8b71c2260154256c6a4296c5171fa", size = 5703565, upload-time = "2026-12-01T12:09:18.663Z" }, + { url = "https://files.pythonhosted.org/packages/96/67/8386d665cbb7c6eaf7146d140ab2791d6706ea06ab4ee82a908a7a75a1a0/prek-0.6.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.musllinux_1_1_aarch64.whl", hash = "sha256:376ea7edaa615ffd2793028dee2fa61e780e58779e332552694c145b8d5f4839", size = 5813003, upload-time = "2026-12-01T12:09:20.454Z" }, + { url = "https://files.pythonhosted.org/packages/4d/de/681a7bf74ac1b7af157fd8017ee81053d8e66611b958aa6802e7e1ec6079/prek-0.6.0-py3-none-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl", hash = "sha256:98a2bd9621ec15ce5229ae8cfcae600ce24a8a0b85267f8241f090ce54c55494", size = 6326445, upload-time = "2026-12-01T12:09:22.376Z" }, + { url = "https://files.pythonhosted.org/packages/79/64/aeabfabb891ddb7e0a61681c0a6d67f061192f4ee095459d51572e23ecc6/prek-0.6.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:71c2891a16b5d775c6e0a6e7f13b7b2508e1e1ea1e22f5a06edbcd3a52b0dae4", size = 6140293, upload-time = "2026-12-01T12:09:23.914Z" }, + { url = "https://files.pythonhosted.org/packages/e4/d0/6d603dba35f9d2c5c82c77181b3c3c91bec656f45d29011592a65830ca16/prek-0.6.0-py3-none-manylinux_2_28_aarch64.whl", hash = "sha256:77d5dd9714ce417d8ac0cb114fa61b3710f14697ac10a49dfdd01024cf417ae1", size = 5821759, upload-time = "2026-12-01T12:09:25.553Z" }, + { url = "https://files.pythonhosted.org/packages/c5/77/2aff6173cde9e9313c9b28e85c4a47e22b5d358255f0a9e0a2f56a3e6219/prek-0.6.0-py3-none-manylinux_2_31_riscv64.whl", hash = "sha256:c04eed68ac48cb8456890adb5e647a86ef36124ed8fd924a2904206cfbee0649", size = 5601427, upload-time = "2026-12-01T12:09:27.059Z" }, + { url = "https://files.pythonhosted.org/packages/74/63/7cc8a8d564a946f10c69d6b09cd0a7f3e17edf2bf3b06efc0864911fff15/prek-0.6.0-py3-none-musllinux_1_1_x86_64.whl", hash = "sha256:c9d513f02c4a16000f13fbf9a1277dd9849498bd3955413392a1987b7fc70633", size = 6267684, upload-time = "2026-12-01T12:09:28.608Z" }, + { url = "https://files.pythonhosted.org/packages/d3/b9/f68347dcd54893580241c63c3c3b645f6b9484fbe57203ca8d73b7ebbc99/prek-0.6.0-py3-none-win_amd64.whl", hash = "sha256:f521f6394d0230ebda0ccb38c5b0aeddce343b6ada376ac3475c32eefc4c4b33", size = 5713124, upload-time = "2026-12-01T12:09:30.072Z" }, + { url = "https://files.pythonhosted.org/packages/8d/15/83485ec3877adb1a53f38fcb898788eb4a664ba98177cb05c9ea276a9ba3/prek-0.6.0-py3-none-win_arm64.whl", hash = "sha256:9c9aebbcae8255634bd3b1089741fc373c7f2c0830615877c3b477a971d5dbd8", size = 5667480, upload-time = "2026-12-01T12:09:31.423Z" }, +] + +[[package]] +name = "pycparser" +version = "3.12" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/cb/27/eeb9f307bf07060f3d9f9aa0fb8c15b01bdfded0a941e4b2719c7f94cacd/pycparser-3.12.tar.gz", hash = "sha256:f03387877eab82ce01bbdfd0ba7252ee55a90b1c708d5129e2ce915475cf1db6", size = 158785, upload-time = "2026-10-22T13:40:03.56Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/b6/ae/315bbeee126a769cbde43cf4908acb4b40408d8bf8bbf334dd7368d8dadf/pycparser-3.12-py3-none-any.whl", hash = "sha256:a076f3f489b39b43ed13563a1dafe42447445bec2e294154ec5c57fcdda4c85e", size = 62600, upload-time = "2026-10-22T13:40:02.021Z" }, +] + +[[package]] +name = "pygments" +version = "2.21.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/49/2e/ced460408999b33da6b31b0021b0f37d329e202d4169aeb164493778f25b/pygments-2.21.0.tar.gz", hash = "sha256:610ca751c9bc2492b38eb9a38a7fbc93edbbb2d7182edaf34e66ae493dee5c8c", size = 5005329, upload-time = "2026-08-17T08:02:48.824Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/71/46/17f022dd3e953bf20a04a028a21ec746d942f8d2af30fa0f124fa0e6a684/pygments-2.21.0-py3-none-any.whl", hash = "sha256:2363c69b61c4a97c838da3b130dcd6468f4848992b21a82f2a63ec34377137d9", size = 1250147, upload-time = "2026-08-17T08:02:44.912Z" }, +] + +[[package]] +name = "pymdown-extensions" +version = "12.3" +source = { registry = "https://pypi.org/simple" } +resolution-markers = [ + "python_full_version < '3.11.5'", +] +dependencies = [ + { name = "markdown" }, + { name = "pyyaml" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/f3/fe/ac50ee24a80a1b344e643f6fb626063cc7041b978cd1dd9a7f9963ae1cd1/pymdown_extensions-12.3.tar.gz", hash = "sha256:a7f2a4e0bc60c6e6babfa7922cfb3b01cd640eb00fb208f3c582e12bae00ea67", size = 870532, upload-time = "2026-10-14T22:40:43.252Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/8a/d0/758afe732c2da502c051b4d03ff88daa3c0fc1a1e671e6c5a6318177bab4/pymdown_extensions-12.3-py3-none-any.whl", hash = "sha256:345493a8e3497e24382902903a1c43a28e34a52f2b7571a1c9641429b820ca74", size = 277597, upload-time = "2026-10-14T22:40:41.543Z" }, +] + +[[package]] +name = "pymdown-extensions" +version = "13.1.2" +source = { registry = "https://pypi.org/simple" } +resolution-markers = [ + "python_full_version >= '3.11.5'", +] +dependencies = [ + { name = "markdown" }, + { name = "pyyaml" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/fc/68/6da10ec6620ea74b621437f2d20df2e96f1c44dc3976c7136de4ebd0cc68/pymdown_extensions-13.1.2.tar.gz", hash = "sha256:724701395585d027fb18a6ad3377636570bac4f2917ed809f06cbc811d7e60bb", size = 902399, upload-time = "2026-11-20T18:44:39.775Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/d4/4d/bef5fe206736149372215c13663d95eb13a377dca8bf95d4043afe088322/pymdown_extensions-13.1.2-py3-none-any.whl", hash = "sha256:20eec6babdadcdb47b5a91b3e69ff9f846d506e887125dcb027518c47d412693", size = 286286, upload-time = "2026-11-20T18:44:38.081Z" }, +] + +[[package]] +name = "pytest" +version = "9.2.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "colorama", marker = "sys_platform == 'win32'" }, + { name = "iniconfig" }, + { name = "packaging" }, + { name = "pluggy" }, + { name = "pygments" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/79/42/bb4641652e58dedeac2ec51abc1f8cae4fee4ec63899a0999016229a0f2a/pytest-9.2.0.tar.gz", hash = "sha256:97c4f3b1f3c7414aa36465e09b8220f1d03627993bd51b1282e193753c80557b", size = 1797555, upload-time = "2026-10-27T21:30:20.728Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/51/39/1f5d8c8877a0fa327db959c19341d4be61660de1ab6b7391f9eb805bcd67/pytest-9.2.0-py3-none-any.whl", hash = "sha256:07acdcf88ec174f907dc01af70bf52d49b014bbab03faeeade31c96b18c2e588", size = 411776, upload-time = "2026-10-27T21:30:19.131Z" }, +] + +[[package]] +name = "python-native-workshop" +version = "0.1.0" +source = { virtual = "." } +default-groups = ["docs", "quality", "test"] +dependencies = [ + { name = "native-examples" }, + { name = "rust-fibonacci" }, +] + +[package.dev-dependencies] +docs = [ + { name = "zensical" }, +] +quality = [ + { name = "prek" }, + { name = "ruff" }, +] +test = [ + { name = "pytest" }, +] + +[package.metadata] +requires-dist = [ + { name = "native-examples", editable = "native" }, + { name = "rust-fibonacci", editable = "rust" }, +] + +[package.metadata.requires-dev] +docs = [{ name = "zensical", specifier = ">=0.1.5,<1" }] +quality = [ + { name = "prek", specifier = ">=0.6,<1" }, + { name = "ruff", specifier = ">=0.17.6,<1" }, +] +test = [{ name = "pytest", specifier = ">=9.2,<10" }] + +[[package]] +name = "pyyaml" +version = "6.0.4" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/76/b8/c0b780928e2fb1c87e9e375818c6f121da2398b071012d1747be300b83f4/pyyaml-6.0.4.tar.gz", hash = "sha256:e24bf71af8a432d7808fabff134d38dfe16d3cbb41f2873bb4b1e42422de0a1a", size = 136336, upload-time = "2026-11-20T23:37:05.977Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/e1/ba/fb2aad330bc4f31041f989630ceae5f32e307d3ba9819573d35b71e078fa/pyyaml-6.0.4-cp311-cp311-macosx_10_15_x86_64.whl", hash = "sha256:180ac792c958c2173f6e4467c55ae5f73ab1a9a624ee29fc7095c56d5e3a4055", size = 190856, upload-time = "2026-11-20T23:34:50.753Z" }, + { url = "https://files.pythonhosted.org/packages/16/da/1b8397614250ec63bb7ef1cbb0aa5878367ff729ef35a4abf2accbf48a18/pyyaml-6.0.4-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:730788375056c43d3ac15bd894c9cd2fb7a931a38b302f408620c64b3ef176ed", size = 180950, upload-time = "2026-11-20T23:34:51.629Z" }, + { url = "https://files.pythonhosted.org/packages/fa/88/d99fc8f2cfb33ab7786fb3f6da90eddc1ed9709196bffcb4a487d7f53844/pyyaml-6.0.4-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:71bb5b87465d88d1dfc577115af6d435bff9b26f2512936f610c26aa55966028", size = 810905, upload-time = "2026-11-20T23:34:52.77Z" }, + { url = "https://files.pythonhosted.org/packages/d7/7f/500e5ec119990d1784c72b64197cee8a4f2982f6bc76c572af7f8df02385/pyyaml-6.0.4-cp311-cp311-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:b9fe0b8c65a1611053eb7fcaa7c022f655b7eebeb0ea034572615453cae6b843", size = 914779, upload-time = "2026-11-20T23:34:54.086Z" }, + { url = "https://files.pythonhosted.org/packages/9d/3e/c1c307b6c03e4ea7d86f166f14920ead07aecc35e88d873814d12aa2da66/pyyaml-6.0.4-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:622aa875fa6533f25fedcffe23079357d65a690d462200afed5d8e9d0e01ebee", size = 828016, upload-time = "2026-11-20T23:34:55.213Z" }, + { url = "https://files.pythonhosted.org/packages/03/49/dc931722d7de757596c1c3b944287e4f7d3f419655cd8f5fae382c6179e6/pyyaml-6.0.4-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:49e38a95e24738908ea852e61df0abc58d1e4d4f974ccdb2386eaee412bedc67", size = 799807, upload-time = "2026-11-20T23:34:56.589Z" }, + { url = "https://files.pythonhosted.org/packages/bf/8b/2b7ad9af1c6c5b147c3c860a31586737034a83693d7ae86f854036c6aeb4/pyyaml-6.0.4-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:4d3bbc5e8a84a5a6775adecac786f489510a7159b1c343d6f31426d888cfdd6e", size = 836213, upload-time = "2026-11-20T23:34:57.655Z" }, + { url = "https://files.pythonhosted.org/packages/8c/d8/ebdc04bbf7c00a3c78ea577322239534556418a958d2242af8c0c6ef9093/pyyaml-6.0.4-cp311-cp311-win32.whl", hash = "sha256:c0d68d972f6f6417b4e85e9522f3d57bb4fbc924379766ccd87254a31009c1cd", size = 146012, upload-time = "2026-11-20T23:34:58.75Z" }, + { url = "https://files.pythonhosted.org/packages/7f/c6/ffe94f3159f3543b1ea1702519e1e0a74a67f3a255c286c1f00d51780b82/pyyaml-6.0.4-cp311-cp311-win_amd64.whl", hash = "sha256:0db75f402e99c25239003a499c214a61947b4ef5312af34711d4c63e5c179318", size = 161819, upload-time = "2026-11-20T23:34:59.853Z" }, + { url = "https://files.pythonhosted.org/packages/86/df/5aec8a8c65e4c11fab31b55d53029d8013e5ccfcf409c20f8175e3e267c7/pyyaml-6.0.4-cp312-cp312-macosx_10_15_x86_64.whl", hash = "sha256:1088ad740f50c13178dad16fbc2fa1f634c791d42c7009fdb390e38e5b90b788", size = 187835, upload-time = "2026-11-20T23:35:00.829Z" }, + { url = "https://files.pythonhosted.org/packages/c7/30/efaabf2d135d11f32cbd4752f3b7df0d592894ee3ca252bbba013a7d5891/pyyaml-6.0.4-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:4d30c2f186612bd2f9f07c08a4c96721af59cfc8da3ec7cb27dfa2834e8bb019", size = 179510, upload-time = "2026-11-20T23:35:01.826Z" }, + { url = "https://files.pythonhosted.org/packages/af/fb/d5ff6957db5c843151ff13196277bb8e20b2d5db2e2db3e8d051038d888b/pyyaml-6.0.4-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:45e37dd647db9d67b757444c74060c064ace5fdaa08f42bf4fda3812275d423e", size = 814700, upload-time = "2026-11-20T23:35:02.923Z" }, + { url = "https://files.pythonhosted.org/packages/c4/de/569b907a281bbc49b934bcdad881486b7a476b011cf733f936ca85a8b37d/pyyaml-6.0.4-cp312-cp312-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:9e7ec9dc75cadd392fd687cc9b8ccf7dd59ada0a991e0d14ae0fad9ecdba00c3", size = 879806, upload-time = "2026-11-20T23:35:04.34Z" }, + { url = "https://files.pythonhosted.org/packages/94/80/1d27f7084b983b7cfd1fb35e65a38276d9eddfdcdabc0922bb26cf9521bc/pyyaml-6.0.4-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:93bfb2459195406a518e2f487a9bbf01df240175f31e06f5a252ac6734c7bbf0", size = 849249, upload-time = "2026-11-20T23:35:05.457Z" }, + { url = "https://files.pythonhosted.org/packages/53/37/9b49dff68570bedf27a05ff447e9a281d75bbdfa4d08dc1ee100a844c612/pyyaml-6.0.4-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:84e97378010f3da8daf673b82d39ed638098d236a1b760d61c0c1348a642bd70", size = 799796, upload-time = "2026-11-20T23:35:06.566Z" }, + { url = "https://files.pythonhosted.org/packages/05/bb/f7df529541b98113bea84129a78f93c3889acb08385ca25f9786823dce67/pyyaml-6.0.4-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:f5c410f9e2ffc9286279a46f2e8c107edaf3b1123510af59c828a9c15b23c9db", size = 825424, upload-time = "2026-11-20T23:35:07.783Z" }, + { url = "https://files.pythonhosted.org/packages/44/00/fc5d40087cc55bf3d7bb5ef55cc3e6513e6946afe33a188680fe1d846eb0/pyyaml-6.0.4-cp312-cp312-win32.whl", hash = "sha256:60e9da2772e259307650e03c24f50e3bc2d9fa5ed1ba44c47582e13b0e7708d1", size = 140667, upload-time = "2026-11-20T23:35:08.846Z" }, + { url = "https://files.pythonhosted.org/packages/a3/95/307a6ceafbad9a08300743d19329c31726224e583e05c4fe5358522ba283/pyyaml-6.0.4-cp312-cp312-win_amd64.whl", hash = "sha256:131d11bd9b60d705a6388366d77ed67850995a4d2be85fe149785a257c17e531", size = 154452, upload-time = "2026-11-20T23:35:09.792Z" }, + { url = "https://files.pythonhosted.org/packages/62/81/15c300b14cca818cb9ee27d8cb61cc124229d04f4f7f7bc4e3fca8e2e8d8/pyyaml-6.0.4-cp312-cp312-win_arm64.whl", hash = "sha256:69380d4bae12aab2a2c9532deff6a2841bc9fda47c333691bd2368b696301768", size = 147167, upload-time = "2026-11-20T23:35:10.763Z" }, + { url = "https://files.pythonhosted.org/packages/95/22/b445c43210fe7f466fcf5a38bcbe850fd3db31b85594db22b5a43e63c482/pyyaml-6.0.4-cp313-cp313-macosx_10_15_x86_64.whl", hash = "sha256:61eef2f08e977b725f37a8d1663f5a222c6f09207ac0794030d5fca062e7c96e", size = 188392, upload-time = "2026-11-20T23:35:11.776Z" }, + { url = "https://files.pythonhosted.org/packages/1f/c3/1536ad41fd962d3915f3f8252ecc7f91192ab15c3120ba72ff45e76b7077/pyyaml-6.0.4-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:9d4211f080920629a90c9e31c51e326fb70cfae38f18d4128b9913c23642bace", size = 179961, upload-time = "2026-11-20T23:35:12.722Z" }, + { url = "https://files.pythonhosted.org/packages/40/fd/c5297cc6370e4ab63d0c44d2e63510cc53354f5e8e74bcff047e2a384698/pyyaml-6.0.4-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:41b4669c3a8fd5750e594dff59d3e62d40e321fec467b50449603710ed0a68f3", size = 804464, upload-time = "2026-11-20T23:35:14.066Z" }, + { url = "https://files.pythonhosted.org/packages/0c/2e/20385f63727a6c08df1adad34a88bde90e2bcc1146d1c8588a83190d53b8/pyyaml-6.0.4-cp313-cp313-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:efe68ed09903cca9ab4117c2b9ea6ee8d369818808945bb5a7fa8009b5630b45", size = 875357, upload-time = "2026-11-20T23:35:15.537Z" }, + { url = "https://files.pythonhosted.org/packages/70/f2/f280d52f22f6d9853517d02495c02fbf4c80214fae8ca498efa8605013da/pyyaml-6.0.4-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:50588147ab2c6a59b5f990a4905db80899a6c2bd197e046a6201f1e67587e794", size = 838459, upload-time = "2026-11-20T23:35:16.681Z" }, + { url = "https://files.pythonhosted.org/packages/2a/ee/5f7142110583686e94ab4492e3724ed0869cd9fe26ba8293ec25a47ee223/pyyaml-6.0.4-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:4d1e8d6e345b4b4424a05a11e699e999e65a88f422f73636f8a0b354bf219ffa", size = 789384, upload-time = "2026-11-20T23:35:17.734Z" }, + { url = "https://files.pythonhosted.org/packages/4f/ab/1fd22df5305561cbefb85363182a0af5e81d219e8b8b8dfd73f20eb70859/pyyaml-6.0.4-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:a56491babf0d976625807953bd192dd9de973fccb3270e77b1a795b152a26175", size = 814502, upload-time = "2026-11-20T23:35:19.171Z" }, + { url = "https://files.pythonhosted.org/packages/c1/5a/6b53e1711a78fcc14619a341618c36b862ad8c634e7bc43ae18e6a7376b2/pyyaml-6.0.4-cp313-cp313-win32.whl", hash = "sha256:1631d566655f3af7d6c4a4485267830f6b680d3dc9704b659b3c3f4541b5a3fe", size = 140447, upload-time = "2026-11-20T23:35:20.134Z" }, + { url = "https://files.pythonhosted.org/packages/bd/09/e785d2a9d64de2449cc3aecaa03f1c34670d7a688dc00da7246a858b7e8f/pyyaml-6.0.4-cp313-cp313-win_amd64.whl", hash = "sha256:0a3a351f04dc124f9357512bdb80ac37cd1750cf1371da33e7cbb96d80ac865f", size = 154298, upload-time = "2026-11-20T23:36:22.105Z" }, + { url = "https://files.pythonhosted.org/packages/94/44/0ed649c2c1cc37b342042c3a4609247b74201c23a6f7f01f5dd222eae2bd/pyyaml-6.0.4-cp313-cp313-win_arm64.whl", hash = "sha256:f617e4e5c619fef5284335b24e3af3a77ce08dc5c389ff4b25033bb2749032b7", size = 146938, upload-time = "2026-11-20T23:36:23.305Z" }, + { url = "https://files.pythonhosted.org/packages/70/90/a2d37db959cb771389bb6171eff83905776e5aead12a985a5118a587d6eb/pyyaml-6.0.4-cp314-cp314-macosx_10_15_x86_64.whl", hash = "sha256:4a329472db6c8858ebd94f2214a54c8bff8f035a6cc7af1ab39cc1b33a5f0e56", size = 189727, upload-time = "2026-11-20T23:36:24.518Z" }, + { url = "https://files.pythonhosted.org/packages/71/40/de4380acb2bcc733f502a7c8562b08f741890741dcaa8a7f018c87acc060/pyyaml-6.0.4-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:7335809813ec838d9cd334b1744cda33deb141c9ef23a9c0df371c37980d3851", size = 181969, upload-time = "2026-11-20T23:36:25.675Z" }, + { url = "https://files.pythonhosted.org/packages/7f/a1/88baf9d84981ea723fc1dd5cb534548caebff3071939f899509ab7c62d2f/pyyaml-6.0.4-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:ed9b957abb12f6ffcd92d5db32fa3ffd4e4a8423d80ddd51b4efa63b42f6a76b", size = 804091, upload-time = "2026-11-20T23:36:26.979Z" }, + { url = "https://files.pythonhosted.org/packages/b8/d4/ce94fe5b0e3cc04834d4a30237c1b5388a13ff5a383b919e857898834857/pyyaml-6.0.4-cp314-cp314-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:b525488d5addf5d59ff4610cd8b1deab9dc97fe0fb3fb74533d7f65e9792bd92", size = 869794, upload-time = "2026-11-20T23:36:28.069Z" }, + { url = "https://files.pythonhosted.org/packages/ef/1b/54ce11b40c8fa1883f14eef46525c3c329509dcc268164074fbe60add8ed/pyyaml-6.0.4-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:c604dc2613c417130479cdd6e55c2faa691b6365aa82b3dafddfcecc2eaf1ac7", size = 819491, upload-time = "2026-11-20T23:36:29.189Z" }, + { url = "https://files.pythonhosted.org/packages/8a/d2/6202ffb5d61667c993211a9231836b5d9be5e34165efd1714ac68ea76029/pyyaml-6.0.4-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:f1a4a85b419f5cb6470dd4be5f766bc59532f11b9c22c076b58a0348f05dca5f", size = 790345, upload-time = "2026-11-20T23:36:30.597Z" }, + { url = "https://files.pythonhosted.org/packages/d4/39/d62587fae4a9a32197ea43182c38f221f3f173a09c6f4380254533bdd89e/pyyaml-6.0.4-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:132c3c7c37a8e6f334921b05cfea5d26e241d792dcbb4db0462129d25ca53b43", size = 824626, upload-time = "2026-11-20T23:36:31.9Z" }, + { url = "https://files.pythonhosted.org/packages/b4/b5/e5cf6ca786f8a5b9bd91e01fe8f2113300bc5628fcfdd3ca02d271970824/pyyaml-6.0.4-cp314-cp314-win_amd64.whl", hash = "sha256:1d2f08c122727c86f8303bb1dd45159ca1de1f2d68798e671ec46974e321008e", size = 157525, upload-time = "2026-11-20T23:36:44.254Z" }, + { url = "https://files.pythonhosted.org/packages/75/9c/d78ce9adda3f7db933f73bb2b17ede76f5786fff747a2b73f6e8a6b7bab5/pyyaml-6.0.4-cp314-cp314-win_arm64.whl", hash = "sha256:33506a2620f0e7c49858f09cb44e99f144878d03af3d9c10aa136e9a1d103bcd", size = 151175, upload-time = "2026-11-20T23:36:45.191Z" }, + { url = "https://files.pythonhosted.org/packages/83/f0/e48b8e9736380a039a17506200c4c3080ef181ee86b0e8e2cd6c345ae78a/pyyaml-6.0.4-cp314-cp314t-macosx_10_15_x86_64.whl", hash = "sha256:1db4d51d3c2c9545dd44c614febc4594240754f74b30d8e501415b118347f0d1", size = 193903, upload-time = "2026-11-20T23:36:33.086Z" }, + { url = "https://files.pythonhosted.org/packages/98/ba/682030d1e08f2e4bbd57f164b9085d37560386cf54f6299825e754b32d1a/pyyaml-6.0.4-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:93da48af92c84c4236578e330a514ca324362c0bb62894d8d2343363ed57ff03", size = 188971, upload-time = "2026-11-20T23:36:34.034Z" }, + { url = "https://files.pythonhosted.org/packages/e9/2b/4b29107aae981b4d4575945a73d6c73ebd407d27934dcf35a7daa8fbeb43/pyyaml-6.0.4-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:3c7129bcee5c88c1450802cc6a95b690ee7c51bfcc7a9b60bbd9549a7a4fcbe6", size = 851356, upload-time = "2026-11-20T23:36:35.21Z" }, + { url = "https://files.pythonhosted.org/packages/12/d4/2b05dddc8f59c3762e67c8d5ac01c1759767ee6ea4aba183a01950644668/pyyaml-6.0.4-cp314-cp314t-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:2018fda285d1289527a389e1b4ace1e2d3af410930f949136b55ecb0747744d1", size = 887294, upload-time = "2026-11-20T23:36:36.484Z" }, + { url = "https://files.pythonhosted.org/packages/3e/2a/ce3e0ff674c67b9e1706912aae61063581b3dba22142e60ccdaa64b25c75/pyyaml-6.0.4-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:15c52bb238a15bb4fd7e6342a5ac71d594507667c7fe0e5a5abbc0f6875d1e91", size = 850982, upload-time = "2026-11-20T23:36:38.247Z" }, + { url = "https://files.pythonhosted.org/packages/7e/ad/701d83221865b2512067a9ab2b8e062145af2d362cc2451e72c146ef34cf/pyyaml-6.0.4-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:ab874ebcc5c12c31c859a9e9fe159d688df1f7a099818ef8a35906264a8f5d6b", size = 822547, upload-time = "2026-11-20T23:36:39.852Z" }, + { url = "https://files.pythonhosted.org/packages/61/d1/d88b389313be382ddabd1bca86dbf5da31ac02ecbf29c893588aafb6e11f/pyyaml-6.0.4-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:62c5b5669b05dabf991a705f3a3601f57b65e95121a1d3e3a4ae4446c8632865", size = 845538, upload-time = "2026-11-20T23:36:41.285Z" }, + { url = "https://files.pythonhosted.org/packages/1a/a6/c25ff1b5ebc8bfb11a783a5fde40435f0459629af6f56f9487479bca9766/pyyaml-6.0.4-cp314-cp314t-win_amd64.whl", hash = "sha256:609e8efaffa5662da16b7d53eef76fc4eedbbe56fce5829b67ba808a6e35d399", size = 164060, upload-time = "2026-11-20T23:36:42.238Z" }, + { url = "https://files.pythonhosted.org/packages/08/ad/25d2ac566f0e2f4eb822c9c5e8d9a053406cbfff142273a072b194856823/pyyaml-6.0.4-cp314-cp314t-win_arm64.whl", hash = "sha256:a266cf55ee5cf63c1803432a61c6386e750e0012ca49d12d26ccb0ffd80b343a", size = 157379, upload-time = "2026-11-20T23:36:43.181Z" }, + { url = "https://files.pythonhosted.org/packages/e5/29/fb680bd299c2c6e004c1cc1914f8bad276c6014fe8debd5d6d61ea4c4ff4/pyyaml-6.0.4-cp315-cp315-macosx_10_15_x86_64.whl", hash = "sha256:12a155bc41509d71a2eb73e2191d9e400c1345ea99ac3d9946c31f40a4c840f8", size = 189560, upload-time = "2026-11-20T23:36:46.145Z" }, + { url = "https://files.pythonhosted.org/packages/af/6c/2ffdab56d7afeb039d957479a305516ddbaa08d0162d1e9165fb928e3aeb/pyyaml-6.0.4-cp315-cp315-macosx_11_0_arm64.whl", hash = "sha256:070c22b6f490d6cc30912be9fb9ab1af9c752769b39b53616f6510c3f038ee6a", size = 181949, upload-time = "2026-11-20T23:36:47.065Z" }, + { url = "https://files.pythonhosted.org/packages/b3/07/3a20ed31a60084206ac20449583b0d1a42116b3c530d6857918e4ddbe4b6/pyyaml-6.0.4-cp315-cp315-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:872d2a592289061c1b987e335b3568a2616b474be02bd0608d8f551a385441cd", size = 803806, upload-time = "2026-11-20T23:36:48.145Z" }, + { url = "https://files.pythonhosted.org/packages/26/5b/3dd56027457b96e7e5ea2f4f5976e530d699884b4fd4e360e99e57fa6cca/pyyaml-6.0.4-cp315-cp315-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:914b19e17814315fbcca52031bf79b68237f3d87a948c584a667b18b468e4df7", size = 876808, upload-time = "2026-11-20T23:36:49.294Z" }, + { url = "https://files.pythonhosted.org/packages/b0/51/096a5495b33ff2da32f0c84f5bf8e042cf76f72641cba06ee9618ad01f4d/pyyaml-6.0.4-cp315-cp315-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:c57e40928738c4a202852759f9e1ee2c7063429a9469ee1ac15651bbf7d69963", size = 833052, upload-time = "2026-11-20T23:36:50.505Z" }, + { url = "https://files.pythonhosted.org/packages/da/75/b4e86b5a27fcb9a9cf88e3b81d1b0c12cae2734311e508af18b93ff56286/pyyaml-6.0.4-cp315-cp315-musllinux_1_2_aarch64.whl", hash = "sha256:8e0cd755ce5e9009fd95f9c553e5942478feb8f7dffa19435641fcdc3c20e8ca", size = 788983, upload-time = "2026-11-20T23:36:51.821Z" }, + { url = "https://files.pythonhosted.org/packages/2c/00/2a2cdad68237bcd416bd01688ecfb0e3fa1e68a841b74193db97ffd1c716/pyyaml-6.0.4-cp315-cp315-musllinux_1_2_x86_64.whl", hash = "sha256:2c11be5ab4d9f603a598b5ce93a2064ae38087bdf1b384c5397170054cda4e36", size = 828806, upload-time = "2026-11-20T23:36:52.959Z" }, + { url = "https://files.pythonhosted.org/packages/a8/15/39efefc88dd6fbc3be23cef08a819f5e8bf9a6c0bcf003fc09d38dd0010e/pyyaml-6.0.4-cp315-cp315-win_amd64.whl", hash = "sha256:67da066ca12eb60114ea87f2ecbcca622fff0c205c743cc900437127564fabf6", size = 157467, upload-time = "2026-11-20T23:37:04.171Z" }, + { url = "https://files.pythonhosted.org/packages/40/1d/fddc53420d9c12e7d27c36a59fabf186ba1f6117314da4927dc40b2da19b/pyyaml-6.0.4-cp315-cp315-win_arm64.whl", hash = "sha256:573debb9fe3075423d4f823795a678580e597218c25baef178d532b124a25a25", size = 151203, upload-time = "2026-11-20T23:37:05.079Z" }, + { url = "https://files.pythonhosted.org/packages/fa/ea/48e62a25084fc4b317f8bcc5c9823ddaaa73a0c7769ca451dda6919ff491/pyyaml-6.0.4-cp315-cp315t-macosx_10_15_x86_64.whl", hash = "sha256:c680622f85979f2ff59b4ae44c1ecb5566b2f0f0ffe5d0dc8b4bb6a0e916dabb", size = 193500, upload-time = "2026-11-20T23:36:54.416Z" }, + { url = "https://files.pythonhosted.org/packages/49/dd/8c4df6becc936125261607073fbcd55e1d902a8d53ae4e4893d53b9df0ef/pyyaml-6.0.4-cp315-cp315t-macosx_11_0_arm64.whl", hash = "sha256:18ea9bda247857fc0de05181675dc116b54c1b04ca3db71de5d2108c882823b7", size = 188474, upload-time = "2026-11-20T23:36:55.651Z" }, + { url = "https://files.pythonhosted.org/packages/d0/63/b60236ef09cbab7c5ce174aff59d49a3425b9a8e9bbe4690bd3b9b7d4fba/pyyaml-6.0.4-cp315-cp315t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:6ac167ebebc0c387290406a337b9b5c8c343fa5f7928d5941e45a94b8ba3aa39", size = 848311, upload-time = "2026-11-20T23:36:56.961Z" }, + { url = "https://files.pythonhosted.org/packages/f6/3b/4b14f064ae5d6f69638a86bb7bf1a46d02bb4de083798e693a4a83b1418a/pyyaml-6.0.4-cp315-cp315t-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:4a2a8f27d24d4cdc05aa11df5f4c08e13f30d9e6674809b6a5ddcfcba49a653a", size = 891181, upload-time = "2026-11-20T23:36:58.077Z" }, + { url = "https://files.pythonhosted.org/packages/01/36/4e0b01e380bf3695d34a4bf6b9272c529f4c8d3195c733687d64fb9f8f06/pyyaml-6.0.4-cp315-cp315t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:e956541cc7a3fff2bb5b17aeb6c5bb42c86c8e6dafb5ebdd41a05e72e702076b", size = 855715, upload-time = "2026-11-20T23:36:59.165Z" }, + { url = "https://files.pythonhosted.org/packages/6d/a8/2784a29e687fa7a5882d47c925a98d1dbdd60ead521be14a9342c6a74ff9/pyyaml-6.0.4-cp315-cp315t-musllinux_1_2_aarch64.whl", hash = "sha256:8708f6ab9c2581ffa05f66dae3206bb0385949650537d7295fc7ab0d6454dd70", size = 818754, upload-time = "2026-11-20T23:37:00.248Z" }, + { url = "https://files.pythonhosted.org/packages/bb/85/62d54e223b4bc89ff85f087a5ce2648e5d929d3214d64613dbae17d5e045/pyyaml-6.0.4-cp315-cp315t-musllinux_1_2_x86_64.whl", hash = "sha256:a65339c24f2fb8d4419e06ceec1bda98bdcff727b3b533a81d5af6bb2dd34520", size = 845763, upload-time = "2026-11-20T23:37:01.331Z" }, + { url = "https://files.pythonhosted.org/packages/eb/40/6bd9090368664be984a83fd7fe64f8e044b067a52449679c309706e3199d/pyyaml-6.0.4-cp315-cp315t-win_amd64.whl", hash = "sha256:a3cc63af3d639d1609143711837b926183418260aae89ed95193c07b25b99d33", size = 163170, upload-time = "2026-11-20T23:37:02.3Z" }, + { url = "https://files.pythonhosted.org/packages/0d/22/468d36762a0c650cf2295052998eb1d419053335ea9ff48a043f5ae4d578/pyyaml-6.0.4-cp315-cp315t-win_arm64.whl", hash = "sha256:d276f23e2371deb5ee68dd252cc9c2402b806b54d8d2cc7efbb6c34c3a78d886", size = 156942, upload-time = "2026-11-20T23:37:03.209Z" }, +] + +[[package]] +name = "ruff" +version = "0.17.6" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/df/8e/6929d337aa5380aafc7355f3149f3ccfe55cba5fdd34a045697ebaceb5a0/ruff-0.17.6.tar.gz", hash = "sha256:2b04276561331300325040bdca21460770029ec574d4c479099e39e8ad1ed43c", size = 5374388, upload-time = "2026-11-19T15:56:27.106Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/12/5d/38ef6310c22cacb094e9ae0ff7964062e04ffeecb45ee296894c2b1acc54/ruff-0.17.6-py3-none-linux_armv6l.whl", hash = "sha256:084d9c8f5ec718e7eba007dba339e7cb4f7571d2f267558ae080bf428fb6a69b", size = 10174693, upload-time = "2026-11-19T15:55:52.414Z" }, + { url = "https://files.pythonhosted.org/packages/a2/ed/fd35261049920a4888ef7c787a5c27089502077a4910f6ca8f1213157d6d/ruff-0.17.6-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:9d44ef2140402043fd6f689ef541858b80883a8b0a02e38539ef0614ebe57d0c", size = 10221650, upload-time = "2026-11-19T15:55:54.962Z" }, + { url = "https://files.pythonhosted.org/packages/ba/d4/c31391b36c729cd9fafa65b7a52a58850b99afb2b65da6be4263a53302f2/ruff-0.17.6-py3-none-macosx_11_0_arm64.whl", hash = "sha256:9fbddc08577592e283c265d865e0182de6e33db185494db7b06290d989d888e5", size = 9580986, upload-time = "2026-11-19T15:55:57.391Z" }, + { url = "https://files.pythonhosted.org/packages/eb/11/f3032684dcb3a676d7924545153d76fb56f76753e038f2ea650b99c71bdf/ruff-0.17.6-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:435241c61af5909a022f76219d3d1bf24730dc1bf0acabb5ddf4b569ab3cbb30", size = 10271368, upload-time = "2026-11-19T15:55:59.654Z" }, + { url = "https://files.pythonhosted.org/packages/08/30/c1e024eeb5bae99ae78c6b896ed108f64c9c845a03b56eaeff098e99b6e6/ruff-0.17.6-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:d006bbb2945edb17b0ce6a0c1b5f5a8d81ba11dbac294a0a925effa22ce34feb", size = 9981564, upload-time = "2026-11-19T15:56:01.807Z" }, + { url = "https://files.pythonhosted.org/packages/7d/a5/da3e0c2d4bf02b3ca6c1d7fa4bb04d0081e340b1dd03c4f83b1bec3e15c1/ruff-0.17.6-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:fd661702202a89c00a4c9d0339008805fa5876bfa1c57e165495c2e62230dfbf", size = 10641991, upload-time = "2026-11-19T15:56:03.981Z" }, + { url = "https://files.pythonhosted.org/packages/4d/c1/6d7f981e86201c9db457cca99fd2c09b77574ebab37dff3e9239b218603c/ruff-0.17.6-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:6a12c50a33936dc00db2be21ba25fb168a8b95c55eda2a3ac85005af69885e4b", size = 11403484, upload-time = "2026-11-19T15:56:05.778Z" }, + { url = "https://files.pythonhosted.org/packages/c3/92/8182f07b94998541d5f8f38f53da465aa28062afce24ecc398f45bfc62f1/ruff-0.17.6-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:b5aba93b3db4b70c5697e4fee6e0d5b9c8452a9a3a03679611cadc25915a2173", size = 10892316, upload-time = "2026-11-19T15:56:08.016Z" }, + { url = "https://files.pythonhosted.org/packages/be/48/3df7d81249fd69ee6a49519b149fb5d11e13118fd7d0e8d65329a237087b/ruff-0.17.6-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:aa3b08254a732acba246891089a152c47c5733dc36b8ecb76ce8602f8326e5e4", size = 10645279, upload-time = "2026-11-19T15:56:09.785Z" }, + { url = "https://files.pythonhosted.org/packages/71/80/4d232281544345d7beb98d1d32c24dae804ed360780a6f7753738b81225e/ruff-0.17.6-py3-none-manylinux_2_31_riscv64.whl", hash = "sha256:0692088e6b33455572fb18465e891b443f196e98dc1986825685c77ff6f4c5ac", size = 10534501, upload-time = "2026-11-19T15:56:11.718Z" }, + { url = "https://files.pythonhosted.org/packages/98/0a/b477f075a4a94eb541bf1c759a3e72b2a3d6390af7a13a5be0887229f67c/ruff-0.17.6-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:fb589e032806bb942e4fb526f30b80a1a64112147ed9f1d38cc3de2e255b6f45", size = 10136036, upload-time = "2026-11-19T15:56:13.779Z" }, + { url = "https://files.pythonhosted.org/packages/f1/d8/cf32fbfeb1fcda1470fb5c3bee50c69ee6bca257d487ec1eb17a0387edb4/ruff-0.17.6-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:1939b3d701c7b6981b7cf93473de5bf88b129b9ba84efaed5154cc517c44634d", size = 9969640, upload-time = "2026-11-19T15:56:15.738Z" }, + { url = "https://files.pythonhosted.org/packages/a7/22/bb9f9752f7fcdfdc8b9c51576cc142bb377ade745290e35085173963c7be/ruff-0.17.6-py3-none-musllinux_1_2_i686.whl", hash = "sha256:1a0bea6aa1216e0ec4cd35d3dbccec0d772a7c2aad28ec9c6e82571dff2c20b0", size = 10389427, upload-time = "2026-11-19T15:56:17.617Z" }, + { url = "https://files.pythonhosted.org/packages/81/c7/e09d220818ab146b736d62e0676dad215215d7de0884bbdad9fa075dc7d2/ruff-0.17.6-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:3db61f5015600543a581b07fa7f6f64afa0eeedefe16034cadd88c4074087582", size = 10760296, upload-time = "2026-11-19T15:56:19.463Z" }, + { url = "https://files.pythonhosted.org/packages/2e/09/28329441dfa2c463e2d377a69d4ebbe4d51665e9dbd49fb421f3bc80d775/ruff-0.17.6-py3-none-win32.whl", hash = "sha256:c2f4af6670b7a0501904e881bb3f1f24bd0d964dec1eedbd85f0eb73786e1128", size = 9966266, upload-time = "2026-11-19T15:56:21.581Z" }, + { url = "https://files.pythonhosted.org/packages/4b/9d/18ba9730addfc7554c70d6f171fb8dc2c08e774d9fb2b98e7946ef845c59/ruff-0.17.6-py3-none-win_amd64.whl", hash = "sha256:9cd2fd9923e9806b8b6b67a3469e2258e84bd4d21e45d5a1a690afdfb9c8e57d", size = 10365847, upload-time = "2026-11-19T15:56:23.582Z" }, + { url = "https://files.pythonhosted.org/packages/70/8a/59c33e2a64a4f9672f7f842a0dc522915cfbbaffd13d37d0cec57d1c5c5d/ruff-0.17.6-py3-none-win_arm64.whl", hash = "sha256:d8b14e1473dc86ab9069cf7a2ba5041dc012f59110201844ed04cfddf07055a0", size = 9926224, upload-time = "2026-11-19T15:56:25.269Z" }, +] + +[[package]] +name = "rust-fibonacci" +source = { editable = "rust" } + +[[package]] +name = "tomli" +version = "2.5.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/b0/78/9ad63712633ed3ab5cc1a648d863d7e7da371e9425e209555a0fe711b695/tomli-2.5.0.tar.gz", hash = "sha256:264507556cd8b8c8e7c6ee037cdf443a463f03f4c958e57195e3d369711b8ff6", size = 17662, upload-time = "2026-10-07T12:23:37.892Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/22/a6/ab99b60ee52acd949684febabc3005d0045d0f66bebd9cdebd67372d26dd/tomli-2.5.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:c4dc1c1781f2f716de763d1e9a7b34c6a894e167e291c7c5d16c72f7a9538545", size = 163901, upload-time = "2026-10-07T12:22:15.601Z" }, + { url = "https://files.pythonhosted.org/packages/bc/00/ee01b7ed4579180fff07142d290257f25ba786f23f3ec6005f620933c2f5/tomli-2.5.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:eff8babca5a7999bc137acbc7482a8b7e17ffca5075ab41f5d770ab408c7bfef", size = 163756, upload-time = "2026-10-07T12:22:16.957Z" }, + { url = "https://files.pythonhosted.org/packages/72/c2/4efebf65372f6583185f79799312109dddb61102d47e5c33dcfd1a297aca/tomli-2.5.0-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:86665cee9c4835b7a7f1e8ec2c719b5258d4dc782887aded5a8ae7352a96843b", size = 268038, upload-time = "2026-10-07T12:22:18.135Z" }, + { url = "https://files.pythonhosted.org/packages/53/07/5850468e925d898abb36038666f9c333a94d2a223e802a8ba5b6d319d23f/tomli-2.5.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:d7e369fd63331746182360977b1892bfc215476a30d61612d732425311639f56", size = 276422, upload-time = "2026-10-07T12:22:19.567Z" }, + { url = "https://files.pythonhosted.org/packages/b4/87/f293984cdcf83c054196d4fd3dad44fc68ae55b4b8c44bc76cef360c3150/tomli-2.5.0-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:7ad1ea345759240d6463efa0ed1c704402752e49aa21476620738d74d72d8aa1", size = 272616, upload-time = "2026-10-07T12:22:20.794Z" }, + { url = "https://files.pythonhosted.org/packages/ce/ce/db582886b3c1219d3fec93ebd669332482e5aee7a91e0f7838d84f2d1759/tomli-2.5.0-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:96243987194634bd411066ce40c952e108f86af04db533ecd8ac3ff2a85b1885", size = 276593, upload-time = "2026-10-07T12:22:22.12Z" }, + { url = "https://files.pythonhosted.org/packages/bf/72/7619b87dea4261fc27dd7b54c4461c129c1f7d9bb7ba3aec89c797a431b8/tomli-2.5.0-cp311-cp311-win32.whl", hash = "sha256:610b27d99f28ec5f191c7064a48f3ddb179a1fe6ca73d571483ae859f57b605e", size = 101830, upload-time = "2026-10-07T12:22:23.651Z" }, + { url = "https://files.pythonhosted.org/packages/1e/74/220106da34502304b6751a2a9b8a9fbca6c3fd47e737a2e2e3da7c61c9db/tomli-2.5.0-cp311-cp311-win_amd64.whl", hash = "sha256:c804ae44fe7b4bab5da295e4f980a1ff04670bca9d23fe0a4e887e08ebd741a8", size = 112742, upload-time = "2026-10-07T12:22:24.972Z" }, + { url = "https://files.pythonhosted.org/packages/27/99/7d9c8b41837a7773613e169504147375c157a290167aa59ad74a085f521f/tomli-2.5.0-cp311-cp311-win_arm64.whl", hash = "sha256:cfac177ebd6236003846ea339981f71457cb6eb748f23381eb257e45092e3980", size = 109332, upload-time = "2026-10-07T12:22:26.117Z" }, + { url = "https://files.pythonhosted.org/packages/52/ed/7baa86f87493646a594de388c7c1c40a39dd0461f7e9c0359cbeefc91fe8/tomli-2.5.0-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:1f4a40d03fb9f63424f0979855bdeaf44dd7696b8d59501822c10ed30ba532df", size = 164854, upload-time = "2026-10-07T12:22:27.444Z" }, + { url = "https://files.pythonhosted.org/packages/a5/b1/44c0341f2224397855723c7a8a39f718ea6fcbcc3dacc66e5aeca0f334e3/tomli-2.5.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:9ebf8d19b17bd0daeb7b7dec81a946a439b753942fd0210d6e96c532249eea6b", size = 164074, upload-time = "2026-10-07T12:22:28.679Z" }, + { url = "https://files.pythonhosted.org/packages/23/04/e2d5b7d3fba47adedb23de616c16d428ea076c79a3d8e1d95d649ffe197e/tomli-2.5.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:bf0b5e8e0f68ebb494356e577c06c139161efd8d3b9050f93b39b7c26cc54ff0", size = 274274, upload-time = "2026-10-07T12:22:29.804Z" }, + { url = "https://files.pythonhosted.org/packages/43/90/6090e706ff27a6f89f4a40578e3324b95c3cd8c4150868aabf33a8f414c3/tomli-2.5.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:6cf74416bdc94ae458b14e37286c1073081850ac8459a00d0c5efef5d44294c6", size = 286435, upload-time = "2026-10-07T12:22:31.297Z" }, + { url = "https://files.pythonhosted.org/packages/0a/9e/a2c40768df16c408f22430afb0a73e9d7e5f79c950884954649d1146b74d/tomli-2.5.0-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:61ea1ebe1e55a34ea8199cc8dbff398d35027b82271c8ac4802fd3a1fd5b1bcc", size = 278119, upload-time = "2026-10-07T12:22:32.601Z" }, + { url = "https://files.pythonhosted.org/packages/12/25/3c0cb485b98e9cfac495629b1c93c87ccf0b72fbe9d2689fd8fe62c6d5a3/tomli-2.5.0-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:ed53f7e89bb04f6d9e8e7799112360b0c4d5cbff067de0814c98c37c39b920f7", size = 286177, upload-time = "2026-10-07T12:22:33.745Z" }, + { url = "https://files.pythonhosted.org/packages/77/8b/0144c65f0e37e51c18d04ae15c21b19431c165002d0131fe9aa8b0b8b1e8/tomli-2.5.0-cp312-cp312-win32.whl", hash = "sha256:e7ad033e27a516a233bea839cdb77b80146facb3b4f40bf02cd0cac165cdd5c2", size = 102760, upload-time = "2026-10-07T12:22:34.887Z" }, + { url = "https://files.pythonhosted.org/packages/de/32/5d6d8f42fc9a05fce69354e00ff256484192f5f2fc9a2165718fa0de61ec/tomli-2.5.0-cp312-cp312-win_amd64.whl", hash = "sha256:bd05de8c1698f8413dd7d869492693a0bf2211543b787ac78cd5e7536af1a6d7", size = 112722, upload-time = "2026-10-07T12:22:36.162Z" }, + { url = "https://files.pythonhosted.org/packages/30/65/df18032218db0fb9b769fb23c8039a051f15c811993995ea04c350273a32/tomli-2.5.0-cp312-cp312-win_arm64.whl", hash = "sha256:069435bd5480429b98c5e5afb02ab21c219b6f0064680671c6dc0d46817346ea", size = 109534, upload-time = "2026-10-07T12:22:37.296Z" }, + { url = "https://files.pythonhosted.org/packages/42/e5/51736d70da209350969e15aca5c5ab6e2ce1ea87a0a892a6c13aec172a86/tomli-2.5.0-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:943276cf269e0071948d9ff697159c1735e623c1151d88abb09b74659ef0cbea", size = 163328, upload-time = "2026-10-07T12:22:38.373Z" }, + { url = "https://files.pythonhosted.org/packages/ec/55/086f80dab4ab497602644274e6dea7ec5dd0b4e262e443a8ad3bb7edee2d/tomli-2.5.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:463b16086865b97facd8d0b3fb4cb7c544e3f58d2a69dc3113d6db9653fdb043", size = 162246, upload-time = "2026-10-07T12:22:39.673Z" }, + { url = "https://files.pythonhosted.org/packages/aa/eb/3ecc94459f3635c92321f4e7bde571323fdb2267c50e19e3188a281eae3b/tomli-2.5.0-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:1245a6638fc4bb0a60af38a7d45413db34a13842027c77597c712c998c62fdf0", size = 272655, upload-time = "2026-10-07T12:22:41.08Z" }, + { url = "https://files.pythonhosted.org/packages/c0/d7/494fd1f0c37a621f1ad9975c2efadb523e8101f144ed6edb2e7fe64738f2/tomli-2.5.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:5d8bac3d603c97e6854424e5b2b5b741bdbde387e09f162fb0446812b4a8362b", size = 283595, upload-time = "2026-10-07T12:22:42.222Z" }, + { url = "https://files.pythonhosted.org/packages/70/51/bb8d62b1317e6640866f6949b2d5855e5300f2c99d46de1cd245570bba65/tomli-2.5.0-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:21e4cae4114aba25aa0d4f85cdf486d290fb35c0954d7bba536248da64d43066", size = 276253, upload-time = "2026-10-07T12:22:43.625Z" }, + { url = "https://files.pythonhosted.org/packages/66/f4/f46bd7f0763cd47de2db697dca9257c6a4adfd1a93b018cc75c8190ed5a8/tomli-2.5.0-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:bbaefc84548d754be821bba7c4141c4787dda182f9e77f2f87b71213529efa7b", size = 283582, upload-time = "2026-10-07T12:22:44.983Z" }, + { url = "https://files.pythonhosted.org/packages/ac/03/70f2bcb2923a6db37818d917e124270a7f4cfd38ea576f5aa753a91c0ef5/tomli-2.5.0-cp313-cp313-win32.whl", hash = "sha256:abdbf6313b8d9efe157edeb7ab6eae4de064b1300ad31abf73755154b30abe68", size = 102628, upload-time = "2026-10-07T12:22:46.508Z" }, + { url = "https://files.pythonhosted.org/packages/dc/98/d52024bb5b0ff68b4f0d276d867f634c84a67319a7e9f6b7708a37742333/tomli-2.5.0-cp313-cp313-win_amd64.whl", hash = "sha256:fd4dc129784e0c5335bd4e61dfcc4487499a013419e655cf2da1d091b7e0efdc", size = 113301, upload-time = "2026-10-07T12:22:47.647Z" }, + { url = "https://files.pythonhosted.org/packages/6f/f2/540db3a70572a8c23a28aba3e9c358ce0ffffbafc990905c1343aa265b31/tomli-2.5.0-cp313-cp313-win_arm64.whl", hash = "sha256:69491c143d2fe063046e0301e62a810bed338fa4d1ce0fd870c27dc1e09b0d84", size = 109744, upload-time = "2026-10-07T12:22:48.925Z" }, + { url = "https://files.pythonhosted.org/packages/e4/49/caf6b307766eb9567664a8707e9d6be5fcc0e8903f18781c6677a60d80c7/tomli-2.5.0-cp314-cp314-macosx_10_15_x86_64.whl", hash = "sha256:d3182ee2d887e507bd67319a0a61105d1dd33facc111329559a233b772c1a105", size = 162899, upload-time = "2026-10-07T12:22:50.088Z" }, + { url = "https://files.pythonhosted.org/packages/d3/c8/68cfce773a2733a49c74f99d627fb461bd990756860099eac25617889585/tomli-2.5.0-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:521345fd1f19d45b8df87657aaa38b6f2ca3800059fadf428e7ebf479a383646", size = 162080, upload-time = "2026-10-07T12:22:51.558Z" }, + { url = "https://files.pythonhosted.org/packages/7e/b2/e5bb8651fdad593f670501a7d718b1a7f73f064d44dea15e04c04dfef45d/tomli-2.5.0-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:6e95c7614e705bfe2b04b27aa124adec59752d15813df37e2156747cab3a006b", size = 273380, upload-time = "2026-10-07T12:22:52.918Z" }, + { url = "https://files.pythonhosted.org/packages/8d/d2/9e2d7f8b1dfe0e2b34c245986ebd55c4c553ea4ce6c47c443b332673253f/tomli-2.5.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:7ac2027d37c3afbdf4bdd377f2676f6f1d2122a5be1f1137b49dced590b37e75", size = 283228, upload-time = "2026-10-07T12:22:54.173Z" }, + { url = "https://files.pythonhosted.org/packages/ba/df/ec7b876b7b1a2718bd74a3743c076fff565b04029ba33e8f61fac262739f/tomli-2.5.0-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:c414be4ed9d3cac80c42e348fa5a956117d1a48227f48026e31f59cb4a7671eb", size = 277189, upload-time = "2026-10-07T12:22:55.342Z" }, + { url = "https://files.pythonhosted.org/packages/7d/7b/e192d9eed0b9cb80da799f4d77052297fb9a2c3cc9b19f571f56ea88add6/tomli-2.5.0-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:9b03d7dc168353b4132965bde20feceabaa470e570c6f59660dfae59b1f9eeb3", size = 283632, upload-time = "2026-10-07T12:22:56.735Z" }, + { url = "https://files.pythonhosted.org/packages/84/50/ff94454e75461d75623e47401ed323d65c10aab8fe9033242c20cd2fdf32/tomli-2.5.0-cp314-cp314-win32.whl", hash = "sha256:6f041843c4d3a37245c0c056fd955b186bf8b1fb85690cbe40b81230891dc34b", size = 103535, upload-time = "2026-10-07T12:22:58.084Z" }, + { url = "https://files.pythonhosted.org/packages/54/0b/bdacf05f963bd6026ebf6eeb0beda847d1d60e03e440725c64a4e08a0afd/tomli-2.5.0-cp314-cp314-win_amd64.whl", hash = "sha256:f4b653094e18f9031102d3a1da5c729c8f222d85225b18037dac621695e46e1a", size = 114621, upload-time = "2026-10-07T12:22:59.2Z" }, + { url = "https://files.pythonhosted.org/packages/61/99/53f438fa6ae4f9d4ed0ddde3e7242b3bdc34b48c8f9948b72b9e9b127676/tomli-2.5.0-cp314-cp314-win_arm64.whl", hash = "sha256:3f89d10c1ff6a38d992c27fc8a4816af71a909e08a40ec66934240b1e74347c3", size = 111572, upload-time = "2026-10-07T12:23:00.479Z" }, + { url = "https://files.pythonhosted.org/packages/b9/20/1f88f19427d380a40e90a770e087489eaafe4aeee070ae88ed2bbec00acd/tomli-2.5.0-cp314-cp314t-macosx_10_15_x86_64.whl", hash = "sha256:e9e15b4a6c7dd6b85b5fbab29488a73f1f70de516942308daa266bf0e0aeb0d4", size = 171814, upload-time = "2026-10-07T12:23:01.914Z" }, + { url = "https://files.pythonhosted.org/packages/d0/56/cbe5079c9f9a54b9b3e27fc82f08f3cb36edee75561679f53d2380c801d6/tomli-2.5.0-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:e12bbcd32897272fb05929110362ae9ff4c1b9bb26bd9e971e71dcd3275b4c3d", size = 171324, upload-time = "2026-10-07T12:23:03.18Z" }, + { url = "https://files.pythonhosted.org/packages/2b/30/1d53fd3b0f1cb3ba542e345ec32c26aefdddc4e829e4f3429af8a4f27782/tomli-2.5.0-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:20aa36de8f2cf87237143bc1fa1aae8d6612c09118f4da21c6a684db5dd1f6f9", size = 297441, upload-time = "2026-10-07T12:23:04.345Z" }, + { url = "https://files.pythonhosted.org/packages/66/d9/0800acb6a111686f764c1b91ef15cc42a20a66a46013bb42220f1d2c61c1/tomli-2.5.0-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:22185fad8a1e622f064e78008018a0dd3323550dcb479cb7a1d296888d74024f", size = 307476, upload-time = "2026-10-07T12:23:05.671Z" }, + { url = "https://files.pythonhosted.org/packages/e8/63/30a8f3cd51b5bec37f04744bad0b0dc6160df84aad4f27b0e9283d66f221/tomli-2.5.0-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:984012f71908165449a951de2050d52f276bfe3aa5d5f570f63ddad814370374", size = 296113, upload-time = "2026-10-07T12:23:07.202Z" }, + { url = "https://files.pythonhosted.org/packages/ab/18/0b9ffc597e69c5a1e20a7823cb60d54b39a9f54e91edcb8574f022186758/tomli-2.5.0-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:f79203b3965b4000e91808aaa7c040206093f2b8bf86f455982f2274c9ccf442", size = 307725, upload-time = "2026-10-07T12:23:08.508Z" }, + { url = "https://files.pythonhosted.org/packages/ab/c7/18f8baae0b5607a60e8e19b4a7fedee43a8ff6458e3896dcbbadeeac9c22/tomli-2.5.0-cp314-cp314t-win32.whl", hash = "sha256:91294a9fb94a75542f6e46e4a2ae709bd8d9b51134098cae5cf3bea5478b6d03", size = 108546, upload-time = "2026-10-07T12:23:09.956Z" }, + { url = "https://files.pythonhosted.org/packages/72/34/4cca9739254130627bde87500b3f2b512154fe2f278efa7e2a5e10ad4bcb/tomli-2.5.0-cp314-cp314t-win_amd64.whl", hash = "sha256:f15e3e0b835a6d68b10c86bf80a3149780498d6911c93c3ffd1861d19f9200f1", size = 117814, upload-time = "2026-10-07T12:23:11.486Z" }, + { url = "https://files.pythonhosted.org/packages/7d/fb/afa530d47dd80a78fce43beac6bc6e00f84558eafcffbc6f37b21e80d056/tomli-2.5.0-cp314-cp314t-win_arm64.whl", hash = "sha256:6664b7ae7af7294256c53960a6103077f4914cec8ff98479c352f622c6f6b2f0", size = 115188, upload-time = "2026-10-07T12:23:12.728Z" }, + { url = "https://files.pythonhosted.org/packages/66/98/316fdc00f8c0939e6fe50461dd343c162d3ad51d1286eb25b7db54361d50/tomli-2.5.0-cp315-cp315-macosx_10_15_x86_64.whl", hash = "sha256:a525685c2f97da40762b8695eb7aa0af4c8344ca1905c73e4e29cb04d34607dc", size = 162775, upload-time = "2026-10-07T12:23:13.941Z" }, + { url = "https://files.pythonhosted.org/packages/c5/22/7b10fa5bb01c9539f53f69b619361b19350acc73657772ea7ac70ba309a8/tomli-2.5.0-cp315-cp315-macosx_11_0_arm64.whl", hash = "sha256:9dbb18c1cfb2f6517942fc9314437f66aa06d94436ffb1f06102ef3572f35276", size = 161406, upload-time = "2026-10-07T12:23:15.215Z" }, + { url = "https://files.pythonhosted.org/packages/9c/e7/1a069d86dfd20f1f84f71c63faed9f83c1d890bc06c27d82dc7d888fb573/tomli-2.5.0-cp315-cp315-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:752e8b1aa6a4367ef8bf6a1a1e005540f7ed055ba36d7193796812ca5404eb52", size = 273855, upload-time = "2026-10-07T12:23:16.471Z" }, + { url = "https://files.pythonhosted.org/packages/ae/83/d1ef43d1687d092ab9c235455c76e6e709483b346b056f086095c7c263a5/tomli-2.5.0-cp315-cp315-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:c47300f9bf791808f77d82747691c4bb09cb14bdf3060cca99b42cdc4361d5a7", size = 284910, upload-time = "2026-10-07T12:23:18.166Z" }, + { url = "https://files.pythonhosted.org/packages/cc/05/f4d9cf7de61822ece0c3873f30d291e324911c71a378b8bfe5ced13fd9f5/tomli-2.5.0-cp315-cp315-musllinux_1_2_aarch64.whl", hash = "sha256:19b0dd8749f4ea2f112c5fcfb3c5248390c899d7e2e173f1d91abee1fa0ff391", size = 277723, upload-time = "2026-10-07T12:23:19.355Z" }, + { url = "https://files.pythonhosted.org/packages/42/28/78262493141fa543151cf005760c3cb01d09fc28a11f993c05109902cb8c/tomli-2.5.0-cp315-cp315-musllinux_1_2_x86_64.whl", hash = "sha256:57b1c3b01fab802e2899bc3d168dca320e14165e2fd9fd584760fb4ca5826859", size = 285115, upload-time = "2026-10-07T12:23:20.698Z" }, + { url = "https://files.pythonhosted.org/packages/1a/b9/e1dab9a30bcb677b5cc5cee810609cfd64f24306a3055767dd3fda00b1e0/tomli-2.5.0-cp315-cp315-win32.whl", hash = "sha256:667e521b37a6c5ccaa044202c235b530f90177ffe2cd4a64ecc213c7dd535feb", size = 103475, upload-time = "2026-10-07T12:23:21.941Z" }, + { url = "https://files.pythonhosted.org/packages/4c/bd/31a3790c11d6ea95fcf5e6022ac0f8d0543c9b61120b730fc481bd43d3b4/tomli-2.5.0-cp315-cp315-win_amd64.whl", hash = "sha256:d747252933c8a65ef6bd8da0fbb7ce28a90eb6119d8cd00772cd528aa07b68d5", size = 114589, upload-time = "2026-10-07T12:23:23.098Z" }, + { url = "https://files.pythonhosted.org/packages/47/a2/4f6310fa699364f0e3af7ee3af88dddd9af066d33e716a0265bbe2b3ea84/tomli-2.5.0-cp315-cp315-win_arm64.whl", hash = "sha256:75dbcde8751b0a960aa3de173aa5e894d590755c6d7758b7e774c06f1dc3cbdd", size = 111493, upload-time = "2026-10-07T12:23:24.233Z" }, + { url = "https://files.pythonhosted.org/packages/68/14/00853f0b396d8971107ae1921bb5b322fdee1650d2f16bf06c20adb532e5/tomli-2.5.0-cp315-cp315t-macosx_10_15_x86_64.whl", hash = "sha256:2419c2a189551987b59d80e63ec355671283336f41c6b9b89462df679c7d0c57", size = 171380, upload-time = "2026-10-07T12:23:25.512Z" }, + { url = "https://files.pythonhosted.org/packages/89/ad/fa6949321dadee46b27363974fb197b94c911c3b0f7a5fd26d7dc18fc2a0/tomli-2.5.0-cp315-cp315t-macosx_11_0_arm64.whl", hash = "sha256:0dc598040da8d42cf20f0be588ed7004f46db12a0ac6c32e03a59dccedaaadcd", size = 170553, upload-time = "2026-10-07T12:23:26.855Z" }, + { url = "https://files.pythonhosted.org/packages/53/aa/3056c919eb3e084df3752b2cf5f865dcc04af0b27dba2f66d7b28af4633a/tomli-2.5.0-cp315-cp315t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:49096930c8d886c9bbdab62d2d0d17ce823ddeea522309a190b36245d5b49e01", size = 294428, upload-time = "2026-10-07T12:23:28.132Z" }, + { url = "https://files.pythonhosted.org/packages/96/b2/faeeb5d8769ea3832021d73e892c8391eae7b4b4f8b55a789127bd8b18a9/tomli-2.5.0-cp315-cp315t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:b8ade5023067f99fe72b88accd30d0ea05a158e9e32a11f124e731ea9695313f", size = 304909, upload-time = "2026-10-07T12:23:29.381Z" }, + { url = "https://files.pythonhosted.org/packages/f6/52/f094c09e73fb654b621716d019acb5d29bdfd1be01df80c281d552bda48d/tomli-2.5.0-cp315-cp315t-musllinux_1_2_aarch64.whl", hash = "sha256:b69564772b5c8f22ea5f498dff08cfa825045b4d4c4400529000bdf818aa3b2a", size = 293220, upload-time = "2026-10-07T12:23:30.608Z" }, + { url = "https://files.pythonhosted.org/packages/86/f5/0c30541078ca4b505ce3bd76ed931facbfec524dd018535d691d1af0a6d2/tomli-2.5.0-cp315-cp315t-musllinux_1_2_x86_64.whl", hash = "sha256:8ff3a2ca028c7eee0c777f9a092038d0a594a9fa04e215f929a22c329e2cb142", size = 305705, upload-time = "2026-10-07T12:23:32.181Z" }, + { url = "https://files.pythonhosted.org/packages/05/74/590e7d19d6a118fc5cc5704ff358e21d95b8573f6b9443b1519f29ca8825/tomli-2.5.0-cp315-cp315t-win32.whl", hash = "sha256:62fc1bc8eb03e3a9cadfca713d65614ed8e09d974a283295ffe3a831976b4dc5", size = 108432, upload-time = "2026-10-07T12:23:33.496Z" }, + { url = "https://files.pythonhosted.org/packages/1c/b8/63a75cfb27a17c38550e44025d3a6e7be64516fd8608a3b75703bf37d81b/tomli-2.5.0-cp315-cp315t-win_amd64.whl", hash = "sha256:f3fcbc57b1791fa6cbe5d8434179d51de12be1a4811469529f47f6e7487a2571", size = 117281, upload-time = "2026-10-07T12:23:34.648Z" }, + { url = "https://files.pythonhosted.org/packages/72/01/e8c1debb2173973372934c68fc8e46170ab60ef23ed4592dff4dec6e8993/tomli-2.5.0-cp315-cp315t-win_arm64.whl", hash = "sha256:d2ba24db8a9376921b5e87b4762b9adb0f3f1deaea68f2b8b0bb2c11efb9c3e7", size = 115069, upload-time = "2026-10-07T12:23:35.77Z" }, + { url = "https://files.pythonhosted.org/packages/60/3f/3e3f8fd0919249b0200c80fbc4f9a1e70be19f9883da71dfb7f8b9ab8aca/tomli-2.5.0-py3-none-any.whl", hash = "sha256:32a7b79ac57a2e83670ce329ccf675798bc5a2094783a63676866b70503f2e2b", size = 14765, upload-time = "2026-10-07T12:23:36.875Z" }, +] + +[[package]] +name = "zensical" +version = "0.1.5" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "click" }, + { name = "jinja2" }, + { name = "markdown" }, + { name = "pathspec" }, + { name = "pygments" }, + { name = "pymdown-extensions", version = "12.3", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.11.5'" }, + { name = "pymdown-extensions", version = "13.1.2", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version >= '3.11.5'" }, + { name = "pyyaml" }, + { name = "tomli" }, + { name = "zensical-ui" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/a1/77/2c4eb3244aabfd4643c80f099f47e0fee0864a22d143fa4bf87ea5bb3197/zensical-0.1.5.tar.gz", hash = "sha256:0b4e8a95f07e97bc15a8a869027f0fb493f7f8cb4f40737bd619ffe30f0226c2", size = 557370, upload-time = "2026-12-02T19:44:04.032Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/7e/e9/f685679a6c9a4679d455c8a737305ec7d48c0b4d531a661cf1b4eeadd573/zensical-0.1.5-cp311-abi3-macosx_10_12_x86_64.whl", hash = "sha256:ec6e5bd33d5cadfecaec7fb31aa3b4a4033c8f8cb5f298ac4fd3eb49c4841133", size = 9039576, upload-time = "2026-12-02T19:43:47.167Z" }, + { url = "https://files.pythonhosted.org/packages/f7/b9/4fe8d4a685e25c9248337daa1edfae7ae6c26fa215e5c6030835b825c91f/zensical-0.1.5-cp311-abi3-macosx_11_0_arm64.whl", hash = "sha256:64a9edcaa5a044875d72a42963c81f6dc0ae3806cacb424a4234f2ef17492227", size = 8529191, upload-time = "2026-12-02T19:43:49.733Z" }, + { url = "https://files.pythonhosted.org/packages/06/86/3b711eef5ccd1ce89bc515d02be09123232c8c84d8aeb823b2b9c00d352f/zensical-0.1.5-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:ddebabd31d11111cefe105703c151c5585274737c7b45f0ec7cd0b3495023cd0", size = 8997451, upload-time = "2026-12-02T19:43:51.758Z" }, + { url = "https://files.pythonhosted.org/packages/36/d2/58c5c454b7b2ffcc5a8e7f503af694d4dbd9e6437af14632fd2f61963866/zensical-0.1.5-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:c3caf5893bdf28b61821073153989279e01f13bcbf59cdbb4d78bf7aa73409b1", size = 9508852, upload-time = "2026-12-02T19:43:54.063Z" }, + { url = "https://files.pythonhosted.org/packages/28/f4/5c90280cb972c63ac643448576ea838cfbbef4cde8bf2de4a2c546215b65/zensical-0.1.5-cp311-abi3-musllinux_1_2_aarch64.whl", hash = "sha256:56aa674c0c5cc25f9dd4bd0038a26b74986b18d011fe4c45aa5445f9263f5c1d", size = 9173064, upload-time = "2026-12-02T19:43:56.299Z" }, + { url = "https://files.pythonhosted.org/packages/82/74/d5308bff17270bb4bcc5e75e72a261f6a123c2330fd0b4c85dbc90949f6a/zensical-0.1.5-cp311-abi3-musllinux_1_2_x86_64.whl", hash = "sha256:1645373b53c423519b24832c4b7d1bdbdc91c8cb2382b985d3f385f3adad2e8a", size = 9784538, upload-time = "2026-12-02T19:43:58.192Z" }, + { url = "https://files.pythonhosted.org/packages/a6/64/9cafb8dcb19d8d5a0768b85e83aabe33953306ff464d067254667047971d/zensical-0.1.5-cp311-abi3-win_amd64.whl", hash = "sha256:4fbb07bd34fa95d0f7ec5e013307618f6ba218676dccce60f16e3f466df25688", size = 9723778, upload-time = "2026-12-02T19:44:00.19Z" }, + { url = "https://files.pythonhosted.org/packages/9f/f2/7b32f3e9d4900a746899560c5c14973a539463f942c85725a4447b007c07/zensical-0.1.5-cp311-abi3-win_arm64.whl", hash = "sha256:b4fb2008e31b055cbfb072abac1ee5803ed421ab9d1841c73fdb6a9058818b37", size = 9096754, upload-time = "2026-12-02T19:44:02.229Z" }, +] + +[[package]] +name = "zensical-ui" +version = "0.0.44" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/94/9e/7c128e546265461b059ceb3edc86d6871b526757c75eb0cee4e9626fec1f/zensical_ui-0.0.44.tar.gz", hash = "sha256:7c47d4f02b5ac6aedbd0ea0b9591012e13519448df75d5e009af2ea0e60567f2", size = 4081024, upload-time = "2026-11-27T15:33:31.231Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/48/8f/07fab10b6a18e9da5ce55df807a82ab34c1523394fd9df3892869378f3ef/zensical_ui-0.0.44-py3-none-any.whl", hash = "sha256:d3f15987042c1b9930df85418a1400c52a3bec96e310e35d42e4f9e69ffd8b9b", size = 10087156, upload-time = "2026-11-27T15:33:28.726Z" }, +] diff --git a/zensical.toml b/zensical.toml new file mode 100644 index 0000000..4be685a --- /dev/null +++ b/zensical.toml @@ -0,0 +1,12 @@ +[project] +site_name = "Python Native Interfaces" +site_description = "Call C, C++, and Rust from Python and compare the bindings on your machine." +site_url = "https://tleonhardt.github.io/Python_Interface_Cpp/" +repo_url = "https://github.com/tleonhardt/Python_Interface_Cpp" +repo_name = "tleonhardt/Python_Interface_Cpp" +nav = [ + { "Start here" = "index.md" }, + { "Compare the bindings" = "bindings.md" }, + { "Workshop exercises" = "exercises.md" }, + { "Measure performance" = "benchmark.md" }, +] From d89413afe47e06e134e653a29ebbf438e16ed6eb Mon Sep 17 00:00:00 2001 From: Todd Leonhardt <2812720+tleonhardt@users.noreply.github.com> Date: Sat, 5 Dec 2026 16:56:38 -0500 Subject: [PATCH 02/16] Verify buffer and vector conversion behavior in the labs --- docs/exercises.md | 2 +- tests/test_labs.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/exercises.md b/docs/exercises.md index 5122ba6..4283822 100644 --- a/docs/exercises.md +++ b/docs/exercises.md @@ -18,7 +18,7 @@ from native_examples.integration import integrate_cos for steps in (10, 100, 1_000): estimate = integrate_cos(0, pi / 2, steps) print(steps, round(estimate, 6)) -# 10 1.076484 +# 10 1.076483 # 100 1.007833 # 1000 1.000785 ``` diff --git a/tests/test_labs.py b/tests/test_labs.py index 75c1efb..d445024 100644 --- a/tests/test_labs.py +++ b/tests/test_labs.py @@ -38,6 +38,13 @@ def test_buffer_codec_uses_zlib_format(data): assert buffer_codec.decompress(zlib.compress(data), len(data)) == data +def test_buffer_codec_rejects_strided_input(): + from native_examples import buffer_codec + + with pytest.raises(BufferError): + buffer_codec.compress(memoryview(b"abcd")[::2]) + + @pytest.mark.parametrize("data", PAYLOADS) def test_vector_codec_uses_zlib_format(data): from native_examples import vector_codec @@ -47,6 +54,14 @@ def test_vector_codec_uses_zlib_format(data): assert bytes(vector_codec.decompress(list(zlib.compress(data)), len(data))) == data +@pytest.mark.parametrize("value", [-1, 256]) +def test_vector_codec_rejects_out_of_range_bytes(value): + from native_examples import vector_codec + + with pytest.raises(TypeError): + vector_codec.compress([value]) + + @pytest.mark.parametrize("module_name", ["buffer_codec", "vector_codec"]) @pytest.mark.parametrize( ("packed", "size"), From 75b176ec7544eac584b878695af0caa986e0fb3c Mon Sep 17 00:00:00 2001 From: Todd Leonhardt <2812720+tleonhardt@users.noreply.github.com> Date: Sat, 5 Dec 2026 16:57:44 -0500 Subject: [PATCH 03/16] Explain how binding argument conversions differ --- docs/bindings.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/bindings.md b/docs/bindings.md index fb32946..4e789ee 100644 --- a/docs/bindings.md +++ b/docs/bindings.md @@ -1,6 +1,6 @@ # Compare the bindings -Every module exports `compute_fibonacci(n)`. The workshop counts from `compute_fibonacci(0) == 1` and `compute_fibonacci(1) == 2`. Index 44 gives 1,836,311,903, the last term that fits in a signed 32-bit result. Each implementation checks the index before entering the loop. +Every module exports `compute_fibonacci(n)`. The workshop counts from `compute_fibonacci(0) == 1` and `compute_fibonacci(1) == 2`. Index 44 gives 1,836,311,903, the last term that fits in a signed 32-bit result. Each implementation checks the index before entering the loop. Use Python integers from 0 through 44 for comparisons. Argument conversion is part of each binding: for example, Cython converts `1.5` to the C integer 1, while the other examples reject that float. Very large integers can also fail conversion before reaching the range check. | Example | How the call reaches native code | What to look for | | --- | --- | --- | From 1d82f4e81f313854fbebe0f3bce76221869f6742 Mon Sep 17 00:00:00 2001 From: Todd Leonhardt <2812720+tleonhardt@users.noreply.github.com> Date: Sat, 5 Dec 2026 16:59:47 -0500 Subject: [PATCH 04/16] Use the vcpkg toolchain to locate static zlib on Windows --- .github/workflows/ci.yml | 3 ++- docs/index.md | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ab16e40..02b1d5f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,7 +43,8 @@ jobs: run: | vcpkg install zlib:x64-windows-static-md --classic if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } - "ZLIB_ROOT=$env:VCPKG_INSTALLATION_ROOT/installed/x64-windows-static-md" >> $env:GITHUB_ENV + "CMAKE_TOOLCHAIN_FILE=$env:VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake" >> $env:GITHUB_ENV + "CMAKE_ARGS=-DVCPKG_TARGET_TRIPLET=x64-windows-static-md" >> $env:GITHUB_ENV - name: Build and test the installed examples run: uv run --locked --no-default-groups --group test python -m pytest - name: Smoke-test the benchmark diff --git a/docs/index.md b/docs/index.md index 07d853a..9868e10 100644 --- a/docs/index.md +++ b/docs/index.md @@ -17,7 +17,8 @@ On Windows, run the following in a Developer PowerShell with vcpkg on your PATH. ```powershell $env:VCPKG_ROOT = 'C:\src\vcpkg' vcpkg install zlib:x64-windows-static-md --classic -$env:ZLIB_ROOT = "$env:VCPKG_ROOT/installed/x64-windows-static-md" +$env:CMAKE_TOOLCHAIN_FILE = "$env:VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" +$env:CMAKE_ARGS = "-DVCPKG_TARGET_TRIPLET=x64-windows-static-md" ``` ## Build and run From 24ce9d815533065c59edf79a13e653b630d0b464 Mon Sep 17 00:00:00 2001 From: Todd Leonhardt <2812720+tleonhardt@users.noreply.github.com> Date: Sat, 5 Dec 2026 17:06:12 -0500 Subject: [PATCH 05/16] Open the docs preview in the default browser --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index a556667..ca1d82c 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ benchmark: uv run --locked python -m comparison.benchmark docs: - uv run --isolated --locked --only-group docs zensical serve + uv run --isolated --locked --only-group docs zensical serve -o docs-test: uv run --isolated --locked --only-group docs zensical build --strict From 0b57d6aa8201c06e34ad6d5faa96341c0a2af617 Mon Sep 17 00:00:00 2001 From: Todd Leonhardt <2812720+tleonhardt@users.noreply.github.com> Date: Sat, 5 Dec 2026 17:27:20 -0500 Subject: [PATCH 06/16] Guard SWIG vector operations and retarget CI and Pages to main --- .github/workflows/ci.yml | 4 ++-- .github/workflows/docs.yml | 4 ++-- docs/exercises.md | 17 +++++++++-------- docs/index.md | 2 +- native/labs/vector_codec.i | 20 +++++++++++++++++++- pyproject.toml | 1 + tests/test_labs.py | 33 +++++++++++++++++++++++++++++++-- 7 files changed, 65 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 02b1d5f..276074d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,7 +3,7 @@ name: Native examples on: pull_request: push: - branches: [master] + branches: [main] permissions: contents: read @@ -46,7 +46,7 @@ jobs: "CMAKE_TOOLCHAIN_FILE=$env:VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake" >> $env:GITHUB_ENV "CMAKE_ARGS=-DVCPKG_TARGET_TRIPLET=x64-windows-static-md" >> $env:GITHUB_ENV - name: Build and test the installed examples - run: uv run --locked --no-default-groups --group test python -m pytest + run: uv run --locked --no-default-groups --group test pytest - name: Smoke-test the benchmark run: uv run --locked --no-default-groups --group test python -m comparison.benchmark --calls 100 --repeat 1 diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 279d1fc..eff27b2 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -3,7 +3,7 @@ name: Documentation on: pull_request: push: - branches: [master] + branches: [main] workflow_dispatch: permissions: @@ -24,7 +24,7 @@ jobs: deploy: needs: build - if: github.ref == 'refs/heads/master' && github.event_name != 'pull_request' + if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request' runs-on: ubuntu-latest concurrency: group: github-pages diff --git a/docs/exercises.md b/docs/exercises.md index 4283822..9a37a64 100644 --- a/docs/exercises.md +++ b/docs/exercises.md @@ -25,7 +25,7 @@ for steps in (10, 100, 1_000): Read the Cython loop. The index uses `Py_ssize_t`, the accumulator and width use `double`, and `cos` comes from the C math library. The positive-step check runs -once before the loop. [Integration source](https://github.com/tleonhardt/Python_Interface_Cpp/blob/master/native/labs/integration.pyx) +once before the loop. [Integration source](https://github.com/tleonhardt/Python_Interface_Cpp/blob/main/native/labs/integration.pyx) **Try it.** Reimplement the same loop in Python with `math.cos`. Compare both answers for two rectangles on the interval from zero to π, then reverse the bounds. Which @@ -55,7 +55,7 @@ assert buffer_codec.decompress(packed, len(payload)) == payload The declaration `const unsigned char[::1]` gives the wrapper a contiguous input view. The compressor allocates the output using `compressBound`. For decompression the caller supplies the original size. zlib updates the output length, and the wrapper checks it -before returning Python bytes. [Buffer binding](https://github.com/tleonhardt/Python_Interface_Cpp/blob/master/native/labs/buffer_codec.pyx) · [zlib utility functions](https://zlib.net/manual.html#Utility) +before returning Python bytes. [Buffer binding](https://github.com/tleonhardt/Python_Interface_Cpp/blob/main/native/labs/buffer_codec.pyx) · [zlib utility functions](https://zlib.net/manual.html#Utility) **Try it.** Compress 100,000 copies of the same byte, then decompress with the exact size and with an expected size one byte smaller. Which call raises `ValueError`? @@ -77,16 +77,17 @@ from native_examples import vector_codec samples = vector_codec.ByteVector([0, 127, 255]) samples.append(42) -packed = bytes(vector_codec.compress(samples)) +packed = vector_codec.compress(samples) assert zlib.decompress(packed) == bytes([0, 127, 255, 42]) restored = vector_codec.decompress(list(packed), len(samples)) -assert list(restored) == [0, 127, 255, 42] +assert restored == bytes([0, 127, 255, 42]) ``` Read the `%template(ByteVector)` declaration and the compression signature together. The C++ function borrows its input by const reference and returns its output by value. -SWIG handles conversion to a Python sequence at the return boundary. -[SWIG interface](https://github.com/tleonhardt/Python_Interface_Cpp/blob/master/native/labs/vector_codec.i) · [C++ implementation](https://github.com/tleonhardt/Python_Interface_Cpp/blob/master/native/labs/vector_codec.cpp) +The output typemap copies the contiguous result directly into a Python `bytes` object. +Use indexing or `pop()` on a `ByteVector` for checked access. +[SWIG interface](https://github.com/tleonhardt/Python_Interface_Cpp/blob/main/native/labs/vector_codec.i) · [C++ implementation](https://github.com/tleonhardt/Python_Interface_Cpp/blob/main/native/labs/vector_codec.cpp) **Try it.** Change the final element in `samples`, compress it again and decompress with the Cython binding from lab 2. Predict the last byte before inspecting it. @@ -119,7 +120,7 @@ assert recorder.messages == [(30, "low battery")] Python owns the recorder throughout. The C++ function borrows it for one call and keeps no pointer afterward. The SWIG interface enables directors for `Logger` and returns any exception from the Python override to the original caller. -[Logger and dispatch function](https://github.com/tleonhardt/Python_Interface_Cpp/blob/master/native/labs/callbacks.hpp) · [Director interface](https://github.com/tleonhardt/Python_Interface_Cpp/blob/master/native/labs/callbacks.i) · [SWIG director exceptions](https://www.swig.org/Doc4.5/Python.html#Python_director_exception_unrolling) +[Logger and dispatch function](https://github.com/tleonhardt/Python_Interface_Cpp/blob/main/native/labs/callbacks.hpp) · [Director interface](https://github.com/tleonhardt/Python_Interface_Cpp/blob/main/native/labs/callbacks.i) · [SWIG director exceptions](https://www.swig.org/Doc4.5/Python.html#Python_director_exception_unrolling) **Try it.** Add a Python subclass whose `log` raises `LookupError(message)`. Call `emit_message` with it and catch the exception in Python. Trace the path from the @@ -131,4 +132,4 @@ uv run --locked pytest tests/test_labs.py -k callback The full lab test file includes standard-library interoperability, invalid output sizes, empty streams, callback exceptions and object lifetimes. -[Lab tests](https://github.com/tleonhardt/Python_Interface_Cpp/blob/master/tests/test_labs.py) +[Lab tests](https://github.com/tleonhardt/Python_Interface_Cpp/blob/main/tests/test_labs.py) diff --git a/docs/index.md b/docs/index.md index 9868e10..2d3b97d 100644 --- a/docs/index.md +++ b/docs/index.md @@ -44,6 +44,6 @@ At the Python prompt, compare the two C++ bindings and Rust. With Make installed, use `make hooks` once to install prek, `make check` to run the hooks across the repository, and `make test` after editing code. The Python and Cargo lockfiles are committed. To test another supported interpreter, set `UV_PYTHON` to the desired version before running Make, or run `uv run --locked --python 3.11 python -m pytest`. -Run `make docs` for a live preview and `make docs-test` for a strict build. GitHub Actions builds the documentation on pull requests and uploads the rendered site as an artifact. A merge to `master` publishes the site through GitHub Pages. +Run `make docs` for a live preview and `make docs-test` for a strict build. GitHub Actions builds the documentation on pull requests and uploads the rendered site as an artifact. A merge to `main` publishes the site through GitHub Pages. Continue to the [worked examples and optional exercises](exercises.md). diff --git a/native/labs/vector_codec.i b/native/labs/vector_codec.i index 652e48b..eaf7213 100644 --- a/native/labs/vector_codec.i +++ b/native/labs/vector_codec.i @@ -5,11 +5,18 @@ %include %include -%template(ByteVector) std::vector; +// Python indexing and pop() check bounds before accessing an element. +%ignore std::vector::front; +%ignore std::vector::back; +%ignore std::vector::pop_back; %exception { try { $action + } catch (const std::out_of_range& e) { + SWIG_exception(SWIG_IndexError, e.what()); + } catch (const std::length_error& e) { + SWIG_exception(SWIG_OverflowError, e.what()); } catch (const std::invalid_argument& e) { SWIG_exception(SWIG_ValueError, e.what()); } catch (const std::overflow_error& e) { @@ -20,4 +27,15 @@ SWIG_exception(SWIG_RuntimeError, e.what()); } } +%template(ByteVector) std::vector; + +// Copy the contiguous result directly into a single Python bytes object. +%typemap(out) std::vector { + const std::vector& bytes = $1; + if (bytes.size() > static_cast(PY_SSIZE_T_MAX)) { + SWIG_exception(SWIG_OverflowError, "result exceeds the Python bytes size limit"); + } + $result = PyBytes_FromStringAndSize(reinterpret_cast(bytes.data()), + static_cast(bytes.size())); +} %include "vector_codec.hpp" diff --git a/pyproject.toml b/pyproject.toml index 09557bb..d6b59d4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,6 +23,7 @@ rust-fibonacci = { workspace = true } [tool.pytest.ini_options] testpaths = ["tests"] +pythonpath = ["."] addopts = "-ra --strict-config --strict-markers" [tool.ruff] diff --git a/tests/test_labs.py b/tests/test_labs.py index d445024..87b993b 100644 --- a/tests/test_labs.py +++ b/tests/test_labs.py @@ -1,4 +1,5 @@ import math +import sys import weakref import zlib from importlib import import_module @@ -50,8 +51,36 @@ def test_vector_codec_uses_zlib_format(data): from native_examples import vector_codec vector = vector_codec.ByteVector(list(data)) - assert zlib.decompress(bytes(vector_codec.compress(vector))) == data - assert bytes(vector_codec.decompress(list(zlib.compress(data)), len(data))) == data + packed = vector_codec.compress(vector) + restored = vector_codec.decompress(list(zlib.compress(data)), len(data)) + assert isinstance(packed, bytes) + assert isinstance(restored, bytes) + assert zlib.decompress(packed) == data + assert restored == data + + +def test_byte_vector_uses_checked_element_access(): + from native_examples.vector_codec import ByteVector + + vector = ByteVector() + for unchecked_method in ("front", "back", "pop_back"): + assert not hasattr(vector, unchecked_method) + with pytest.raises(IndexError): + _ = vector[0] + with pytest.raises(IndexError): + vector.pop() + vector.append(42) + assert vector[-1] == 42 + assert vector.pop() == 42 + + +def test_byte_vector_rejects_impossible_capacity(): + from native_examples.vector_codec import ByteVector + + vector = ByteVector([42]) + with pytest.raises(OverflowError): + vector.reserve(sys.maxsize + 1) + assert list(vector) == [42] @pytest.mark.parametrize("value", [-1, 256]) From fa14b7f78ce62f9316c55bd347be9699593c3ffc Mon Sep 17 00:00:00 2001 From: Todd Leonhardt <2812720+tleonhardt@users.noreply.github.com> Date: Sat, 5 Dec 2026 17:43:00 -0500 Subject: [PATCH 07/16] Use checked iteration and Python slice semantics for ByteVector --- docs/exercises.md | 4 +-- native/labs/vector_codec.i | 35 ++++++++++++++++++++ tests/test_labs.py | 68 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 2 deletions(-) diff --git a/docs/exercises.md b/docs/exercises.md index 9a37a64..3e68091 100644 --- a/docs/exercises.md +++ b/docs/exercises.md @@ -86,14 +86,14 @@ assert restored == bytes([0, 127, 255, 42]) Read the `%template(ByteVector)` declaration and the compression signature together. The C++ function borrows its input by const reference and returns its output by value. The output typemap copies the contiguous result directly into a Python `bytes` object. -Use indexing or `pop()` on a `ByteVector` for checked access. +Iteration uses checked integer indexing, and slices return independent byte vectors. [SWIG interface](https://github.com/tleonhardt/Python_Interface_Cpp/blob/main/native/labs/vector_codec.i) · [C++ implementation](https://github.com/tleonhardt/Python_Interface_Cpp/blob/main/native/labs/vector_codec.cpp) **Try it.** Change the final element in `samples`, compress it again and decompress with the Cython binding from lab 2. Predict the last byte before inspecting it. ```sh -uv run --locked pytest tests/test_labs.py -k vector_codec +uv run --locked pytest tests/test_labs.py -k "vector_codec or byte_vector" ``` ## 4. Call a Python logger from C++ diff --git a/native/labs/vector_codec.i b/native/labs/vector_codec.i index eaf7213..3485c60 100644 --- a/native/labs/vector_codec.i +++ b/native/labs/vector_codec.i @@ -3,12 +3,47 @@ #include "vector_codec.hpp" %} +// Python's sequence iterator calls checked integer indexing on each step. +#define SWIG_NO_EXPORT_ITERATOR_METHODS %include %include // Python indexing and pop() check bounds before accessing an element. %ignore std::vector::front; %ignore std::vector::back; %ignore std::vector::pop_back; +%ignore std::vector::get_allocator; + +// Keep the native integer overloads. Handle slices with Python's bounds and step rules. +%ignore std::vector::__getitem__(SWIGPY_SLICEOBJECT *); +%ignore std::vector::__setitem__(SWIGPY_SLICEOBJECT *); +%ignore std::vector::__setitem__( + SWIGPY_SLICEOBJECT *, const std::vector >&); +%ignore std::vector::__delitem__(SWIGPY_SLICEOBJECT *); + +%feature("shadow") std::vector::__getitem__ %{ +def __getitem__(self, key): + if isinstance(key, slice): + return ByteVector(bytes(self[i] for i in range(*key.indices(len(self))))) + return $action(self, key) +%} +%feature("shadow") std::vector::__setitem__ %{ +def __setitem__(self, key, value): + if isinstance(key, slice): + data = bytearray(self) + data[key] = value + self.swap(ByteVector(data)) + else: + $action(self, key, value) +%} +%feature("shadow") std::vector::__delitem__ %{ +def __delitem__(self, key): + if isinstance(key, slice): + data = bytearray(self) + del data[key] + self.swap(ByteVector(data)) + else: + $action(self, key) +%} %exception { try { diff --git a/tests/test_labs.py b/tests/test_labs.py index 87b993b..5b402bf 100644 --- a/tests/test_labs.py +++ b/tests/test_labs.py @@ -74,6 +74,74 @@ def test_byte_vector_uses_checked_element_access(): assert vector.pop() == 42 +def test_byte_vector_keeps_native_iterators_and_allocator_private(): + from native_examples.vector_codec import ByteVector + + native_methods = { + "iterator", + "begin", + "end", + "rbegin", + "rend", + "erase", + "insert", + "get_allocator", + } + assert native_methods.isdisjoint(dir(ByteVector)) + + +@pytest.mark.parametrize( + "key", [slice(3, None), slice(30, None), slice(-30, 2), slice(None, None, -1)] +) +def test_byte_vector_slice_matches_python(key): + from native_examples.vector_codec import ByteVector + + data = [1, 2, 3] + result = ByteVector(data)[key] + assert isinstance(result, ByteVector) + assert list(result) == data[key] + + +def test_byte_vector_iteration_uses_checked_indices(): + from native_examples.vector_codec import ByteVector + + indices = [] + + class TracedVector(ByteVector): + def __getitem__(self, key): + indices.append(key) + return super().__getitem__(key) + + vector = TracedVector([1, 2, 3]) + iterator = iter(vector) + assert next(iterator) == 1 + assert indices == [0] + vector.clear() + assert list(iterator) == [] + + +def test_byte_vector_slice_edits_follow_python(): + from native_examples.vector_codec import ByteVector + + vector = ByteVector([10, 20, 30]) + suffix = vector[1:] + suffix[0] = 40 + assert list(vector) == [10, 20, 30] + + vector[100:] = [40] + del vector[4:] + assert list(vector) == [10, 20, 30, 40] + vector[::-2] = [41, 21] + assert list(vector) == [10, 21, 30, 41] + del vector[::-2] + assert list(vector) == [10, 30] + with pytest.raises(ValueError): + vector[::2] = [1, 2] + with pytest.raises(ValueError): + _ = vector[::0] + assert list(vector) == [10, 30] + + def test_byte_vector_rejects_impossible_capacity(): from native_examples.vector_codec import ByteVector From 9696a1d4e6d34d89afdeea66171d395d43b4fc31 Mon Sep 17 00:00:00 2001 From: Todd Leonhardt <2812720+tleonhardt@users.noreply.github.com> Date: Sat, 5 Dec 2026 17:45:37 -0500 Subject: [PATCH 08/16] Restore linked tool names and publish measured Fibonacci benchmarks --- README.md | 26 +++++++++++++++++++++++--- comparison/benchmark.py | 14 ++++++++++++-- docs/benchmark.md | 6 ++++++ 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2511b08..0a8f1ef 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Python Native Interfaces -Call the same Fibonacci function from Python through CFFI, Cython, SWIG, pybind11, nanobind, and PyO3. The examples also show how to pass byte buffers, expose a C struct, and call a Python override from C++. Every worked example builds into a Python environment and runs under pytest. +Call the same Fibonacci function from Python through [CFFI](https://cffi.readthedocs.io/), [Cython](https://cython.org/), [SWIG](https://www.swig.org/), [pybind11](https://github.com/pybind/pybind11), [nanobind](https://nanobind.readthedocs.io/), and [PyO3](https://pyo3.rs/). ## Try it @@ -23,11 +23,31 @@ The Rust call prints `17711`. The original workshop starts its sequence at `1, 2 | Serve the Zensical guide | `make docs` | | Build the site with strict validation | `make docs-test` | +## Fibonacci benchmark + +On December 5, 2026, each implementation computed `fib(20) = 17711` on an Apple M3 Max running macOS 27.2.1 and CPython 3.15.2 (Apple Clang 21.0.0, rustc 1.100.1). Each row shows the median of nine samples of one million calls. Speedup is relative to pure Python on the same machine. + +| Implementation | Median ns/call | Speedup vs. Python | +| --- | ---: | ---: | +| Python | 219.0 | 1.00× | +| CFFI (ABI) | 107.5 | 2.04× | +| Cython (wrapper) | 21.4 | 10.21× | +| Cython (typed) | 21.2 | 10.35× | +| SWIG | 30.6 | 7.17× | +| pybind11 | 39.4 | 5.56× | +| nanobind | 23.6 | 9.28× | +| PyO3 | 25.9 | 8.44× | + +To generate this table on your machine, run the following from the repository root after setup. See the [benchmark guide](docs/benchmark.md) for how the calls are timed and how to change the workload. + +```sh +uv run --locked python -m comparison.benchmark --markdown -n 20 --calls 1000000 --repeat 9 +``` + ## Explore the code - [C and C++ bindings](native/) share one scikit-build-core/CMake build. Compare the binding declarations and the native functions they call. - [Rust extension](rust/) uses PyO3 and maturin. It exposes the same Python function as the C and C++ examples. - [The guide to the bindings](docs/bindings.md) explains when each approach fits. [Workshop exercises](docs/exercises.md) walk through typed loops, buffers, vectors, and callbacks. -- [Benchmark instructions](docs/benchmark.md) describe the measurements and their limits. -The original [slides](Interfacing_C_C++_with_Python.pdf) and [lab handout](Interfacing_C_C++_with_Python-Exercises.pdf) accompany the [2019 workshop checkout](https://github.com/tleonhardt/Python_Interface_Cpp/tree/398eab0c6e7f5e0358edb6644c71b5fdc6b2606a). Its PyPy comparisons, Ruby extension, FastLZ exercises, and platform-specific build scripts are available there. For the current exercises, use the [Zensical guide](https://tleonhardt.github.io/Python_Interface_Cpp/). +The original [slides](Interfacing_C_C++_with_Python.pdf) and [lab handout](Interfacing_C_C++_with_Python-Exercises.pdf) accompany the [2019 workshop checkout](https://github.com/tleonhardt/Python_Interface_Cpp/tree/398eab0c6e7f5e0358edb6644c71b5fdc6b2606a). Its [PyPy](https://pypy.org/) comparisons, Ruby extension, FastLZ exercises, and platform-specific build scripts are available there. For the current exercises, use the [Zensical guide](https://tleonhardt.github.io/Python_Interface_Cpp/). diff --git a/comparison/benchmark.py b/comparison/benchmark.py index d06e83c..d0d9b54 100644 --- a/comparison/benchmark.py +++ b/comparison/benchmark.py @@ -19,6 +19,9 @@ def main() -> None: ) parser.add_argument("--calls", type=int, default=100_000, help="calls per timing sample") parser.add_argument("--repeat", type=int, default=5, help="number of timing samples") + parser.add_argument( + "--markdown", action="store_true", help="print the results as a Markdown table" + ) args = parser.parse_args() if not 0 <= args.n <= 44 or min(args.calls, args.repeat) < 1: parser.error("use an index from 0 to 44 and positive sample sizes") @@ -26,7 +29,14 @@ def main() -> None: expected = reference.compute_fibonacci(args.n) print(f"{sys.implementation.name} {platform.python_version()} on {platform.platform()}") print(f"fib({args.n}) = {expected}, median of {args.repeat} × {args.calls:,} calls") - print(f"{'Implementation':<18} {'ns/call':>10} {'speedup':>9}") + if args.markdown: + print() + print("| Implementation | Median ns/call | Speedup vs. Python |") + print("| --- | ---: | ---: |") + row = "| {name} | {ns:.1f} | {speedup:.2f}× |" + else: + print(f"{'Implementation':<18} {'ns/call':>10} {'speedup':>9}") + row = "{name:<18} {ns:>10.1f} {speedup:>8.2f}x" for name, module in ( ("Python", reference), ("CFFI (ABI)", cffi_fib), @@ -44,7 +54,7 @@ def main() -> None: seconds = median(timer.repeat(repeat=args.repeat, number=args.calls)) / args.calls if module is reference: baseline = seconds - print(f"{name:<18} {seconds * 1e9:>10.1f} {baseline / seconds:>8.2f}x") + print(row.format(name=name, ns=seconds * 1e9, speedup=baseline / seconds)) if __name__ == "__main__": diff --git a/docs/benchmark.md b/docs/benchmark.md index bf64685..b940769 100644 --- a/docs/benchmark.md +++ b/docs/benchmark.md @@ -8,6 +8,12 @@ uv run --locked python -m comparison.benchmark -n 0 --calls 200000 --repeat 7 uv run --locked python -m comparison.benchmark -n 44 --calls 200000 --repeat 7 ``` +To generate a Markdown table with the same settings as the README, run this command from the repository root after [installing the toolchain](index.md). Each speedup is the Python median divided by the corresponding implementation's median. + +```sh +uv run --locked python -m comparison.benchmark --markdown -n 20 --calls 1000000 --repeat 9 +``` + At index 0 the native loop has no iterations, so the measurement is dominated by calling the function, converting arguments and results, and checking the range. At index 44 the same call includes 44 additions. The benchmark looks up the callable before timing and keeps imports, compilation, and printing outside the timed region. The defaults are index 20, 100,000 calls per sample, and five samples. Run on an idle machine and record the git revision, Python version, compiler versions, operating system, and processor when sharing results. The original Python 3.6 speedups describe the environment used for that workshop. Timing tiny scalar calls here tells you little about the cost of passing a large array or calling back into Python for each element. From e8543467c3639c9896177c190c426cc3ec587a1f Mon Sep 17 00:00:00 2001 From: Todd Leonhardt <2812720+tleonhardt@users.noreply.github.com> Date: Sat, 5 Dec 2026 17:51:24 -0500 Subject: [PATCH 09/16] Format Markdown with Prettier in prek and CI --- .github/workflows/ci.yml | 3 +- .pre-commit-config.yaml | 6 +++ .prettierrc.json | 5 +++ README.md | 69 ++++++++++++++++++----------- docs/benchmark.md | 19 ++++++-- docs/bindings.md | 49 ++++++++++++++------- docs/exercises.md | 93 +++++++++++++++++++++------------------- docs/index.md | 38 +++++++++++----- 8 files changed, 182 insertions(+), 100 deletions(-) create mode 100644 .prettierrc.json diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 276074d..1e9093b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,4 +59,5 @@ jobs: version: "0.13.13" - run: uv lock --check - run: uv sync --locked --only-group quality - - run: uv run --locked --no-sync prek run --all-files --show-diff-on-failure + - name: Run prek checks and Markdown formatting + run: uv run --locked --no-sync prek run --all-files --show-diff-on-failure diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 628e590..951e559 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,3 +17,9 @@ repos: entry: cargo fmt --manifest-path rust/Cargo.toml -- --check types: [rust] pass_filenames: false + - id: prettier + name: Format Markdown with Prettier + language: node + additional_dependencies: [prettier@3.10.2] + entry: prettier --write + types: [markdown] diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 0000000..964c15d --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,5 @@ +{ + "printWidth": 100, + "proseWrap": "always", + "tabWidth": 4 +} diff --git a/README.md b/README.md index 0a8f1ef..e94c02c 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,15 @@ # Python Native Interfaces -Call the same Fibonacci function from Python through [CFFI](https://cffi.readthedocs.io/), [Cython](https://cython.org/), [SWIG](https://www.swig.org/), [pybind11](https://github.com/pybind/pybind11), [nanobind](https://nanobind.readthedocs.io/), and [PyO3](https://pyo3.rs/). +Call the same Fibonacci function from Python through [CFFI](https://cffi.readthedocs.io/), +[Cython](https://cython.org/), [SWIG](https://www.swig.org/), +[pybind11](https://github.com/pybind/pybind11), [nanobind](https://nanobind.readthedocs.io/), and +[PyO3](https://pyo3.rs/). ## Try it -Install [uv](https://docs.astral.sh/uv/getting-started/installation/), a C/C++17 compiler, Rust with Cargo, and the zlib development headers. The default interpreter is CPython 3.15. Platform-specific instructions are in the [getting-started guide](docs/index.md). +Install [uv](https://docs.astral.sh/uv/getting-started/installation/), a C/C++17 compiler, Rust with +Cargo, and the zlib development headers. The default interpreter is CPython 3.15. Platform-specific +instructions are in the [getting-started guide](docs/index.md). ```sh uv sync --locked @@ -12,33 +17,37 @@ uv run --locked python -c "from rust_fibonacci import compute_fibonacci; print(c uv run --locked python -m pytest ``` -The Rust call prints `17711`. The original workshop starts its sequence at `1, 2, 3, 5`, so its index 20 corresponds to the conventional Fibonacci number F(22). +The Rust call prints `17711`. The original workshop starts its sequence at `1, 2, 3, 5`, so its +index 20 corresponds to the conventional Fibonacci number F(22). -| To | Run | -| --- | --- | -| Build the extensions and run tests | `make test` | -| Compare timings on your machine | `make benchmark` | -| Install the prek Git hook | `make hooks` | -| Run code quality checks | `make check` | -| Serve the Zensical guide | `make docs` | +| To | Run | +| ------------------------------------- | ---------------- | +| Build the extensions and run tests | `make test` | +| Compare timings on your machine | `make benchmark` | +| Install the prek Git hook | `make hooks` | +| Run code quality checks | `make check` | +| Serve the Zensical guide | `make docs` | | Build the site with strict validation | `make docs-test` | ## Fibonacci benchmark -On December 5, 2026, each implementation computed `fib(20) = 17711` on an Apple M3 Max running macOS 27.2.1 and CPython 3.15.2 (Apple Clang 21.0.0, rustc 1.100.1). Each row shows the median of nine samples of one million calls. Speedup is relative to pure Python on the same machine. +On December 5, 2026, each implementation computed `fib(20) = 17711` on an Apple M3 Max running macOS +27.2.1 and CPython 3.15.2 (Apple Clang 21.0.0, rustc 1.100.1). Each row shows the median of nine +samples of one million calls. Speedup is relative to pure Python on the same machine. -| Implementation | Median ns/call | Speedup vs. Python | -| --- | ---: | ---: | -| Python | 219.0 | 1.00× | -| CFFI (ABI) | 107.5 | 2.04× | -| Cython (wrapper) | 21.4 | 10.21× | -| Cython (typed) | 21.2 | 10.35× | -| SWIG | 30.6 | 7.17× | -| pybind11 | 39.4 | 5.56× | -| nanobind | 23.6 | 9.28× | -| PyO3 | 25.9 | 8.44× | +| Implementation | Median ns/call | Speedup vs. Python | +| ---------------- | -------------: | -----------------: | +| Python | 219.0 | 1.00× | +| CFFI (ABI) | 107.5 | 2.04× | +| Cython (wrapper) | 21.4 | 10.21× | +| Cython (typed) | 21.2 | 10.35× | +| SWIG | 30.6 | 7.17× | +| pybind11 | 39.4 | 5.56× | +| nanobind | 23.6 | 9.28× | +| PyO3 | 25.9 | 8.44× | -To generate this table on your machine, run the following from the repository root after setup. See the [benchmark guide](docs/benchmark.md) for how the calls are timed and how to change the workload. +To generate this table on your machine, run the following from the repository root after setup. See +the [benchmark guide](docs/benchmark.md) for how the calls are timed and how to change the workload. ```sh uv run --locked python -m comparison.benchmark --markdown -n 20 --calls 1000000 --repeat 9 @@ -46,8 +55,16 @@ uv run --locked python -m comparison.benchmark --markdown -n 20 --calls 1000000 ## Explore the code -- [C and C++ bindings](native/) share one scikit-build-core/CMake build. Compare the binding declarations and the native functions they call. -- [Rust extension](rust/) uses PyO3 and maturin. It exposes the same Python function as the C and C++ examples. -- [The guide to the bindings](docs/bindings.md) explains when each approach fits. [Workshop exercises](docs/exercises.md) walk through typed loops, buffers, vectors, and callbacks. +- [C and C++ bindings](native/) share one scikit-build-core/CMake build. Compare the binding + declarations and the native functions they call. +- [Rust extension](rust/) uses PyO3 and maturin. It exposes the same Python function as the C and + C++ examples. +- [The guide to the bindings](docs/bindings.md) explains when each approach fits. + [Workshop exercises](docs/exercises.md) walk through typed loops, buffers, vectors, and callbacks. -The original [slides](Interfacing_C_C++_with_Python.pdf) and [lab handout](Interfacing_C_C++_with_Python-Exercises.pdf) accompany the [2019 workshop checkout](https://github.com/tleonhardt/Python_Interface_Cpp/tree/398eab0c6e7f5e0358edb6644c71b5fdc6b2606a). Its [PyPy](https://pypy.org/) comparisons, Ruby extension, FastLZ exercises, and platform-specific build scripts are available there. For the current exercises, use the [Zensical guide](https://tleonhardt.github.io/Python_Interface_Cpp/). +The original [slides](Interfacing_C_C++_with_Python.pdf) and +[lab handout](Interfacing_C_C++_with_Python-Exercises.pdf) accompany the +[2019 workshop checkout](https://github.com/tleonhardt/Python_Interface_Cpp/tree/398eab0c6e7f5e0358edb6644c71b5fdc6b2606a). +Its [PyPy](https://pypy.org/) comparisons, Ruby extension, FastLZ exercises, and platform-specific +build scripts are available there. For the current exercises, use the +[Zensical guide](https://tleonhardt.github.io/Python_Interface_Cpp/). diff --git a/docs/benchmark.md b/docs/benchmark.md index b940769..7aa3e00 100644 --- a/docs/benchmark.md +++ b/docs/benchmark.md @@ -1,6 +1,8 @@ # Measure performance -The benchmark calls each implementation with the same integer, verifies its answer against Python, and prints the median nanoseconds per call and speedup relative to Python. It also reports the interpreter, platform, and sample sizes. +The benchmark calls each implementation with the same integer, verifies its answer against Python, +and prints the median nanoseconds per call and speedup relative to Python. It also reports the +interpreter, platform, and sample sizes. ```sh make benchmark @@ -8,12 +10,21 @@ uv run --locked python -m comparison.benchmark -n 0 --calls 200000 --repeat 7 uv run --locked python -m comparison.benchmark -n 44 --calls 200000 --repeat 7 ``` -To generate a Markdown table with the same settings as the README, run this command from the repository root after [installing the toolchain](index.md). Each speedup is the Python median divided by the corresponding implementation's median. +To generate a Markdown table with the same settings as the README, run this command from the +repository root after [installing the toolchain](index.md). Each speedup is the Python median +divided by the corresponding implementation's median. ```sh uv run --locked python -m comparison.benchmark --markdown -n 20 --calls 1000000 --repeat 9 ``` -At index 0 the native loop has no iterations, so the measurement is dominated by calling the function, converting arguments and results, and checking the range. At index 44 the same call includes 44 additions. The benchmark looks up the callable before timing and keeps imports, compilation, and printing outside the timed region. +At index 0 the native loop has no iterations, so the measurement is dominated by calling the +function, converting arguments and results, and checking the range. At index 44 the same call +includes 44 additions. The benchmark looks up the callable before timing and keeps imports, +compilation, and printing outside the timed region. -The defaults are index 20, 100,000 calls per sample, and five samples. Run on an idle machine and record the git revision, Python version, compiler versions, operating system, and processor when sharing results. The original Python 3.6 speedups describe the environment used for that workshop. Timing tiny scalar calls here tells you little about the cost of passing a large array or calling back into Python for each element. +The defaults are index 20, 100,000 calls per sample, and five samples. Run on an idle machine and +record the git revision, Python version, compiler versions, operating system, and processor when +sharing results. The original Python 3.6 speedups describe the environment used for that workshop. +Timing tiny scalar calls here tells you little about the cost of passing a large array or calling +back into Python for each element. diff --git a/docs/bindings.md b/docs/bindings.md index 4e789ee..d33d0bc 100644 --- a/docs/bindings.md +++ b/docs/bindings.md @@ -1,16 +1,21 @@ # Compare the bindings -Every module exports `compute_fibonacci(n)`. The workshop counts from `compute_fibonacci(0) == 1` and `compute_fibonacci(1) == 2`. Index 44 gives 1,836,311,903, the last term that fits in a signed 32-bit result. Each implementation checks the index before entering the loop. Use Python integers from 0 through 44 for comparisons. Argument conversion is part of each binding: for example, Cython converts `1.5` to the C integer 1, while the other examples reject that float. Very large integers can also fail conversion before reaching the range check. - -| Example | How the call reaches native code | What to look for | -| --- | --- | --- | -| CFFI | Python declares a C ABI and opens a shared library at runtime. | The declaration must agree with the compiled header. | -| Cython wrapping C | A declaration tells Cython how to call the existing C function. | The generated extension links against the C implementation. | -| Typed Cython | Cython compiles the loop itself. | C integer locals move arithmetic out of the Python interpreter. | -| SWIG | An interface file tells SWIG which declarations to wrap. | A generated Python proxy presents C functions and struct fields. | -| pybind11 | A C++ module registers a function with pybind11. | Its argument and return types determine how values are converted. | -| nanobind | A second C++ module registers the same C++ function with nanobind. | Compare the two registration calls while keeping the native work fixed. | -| PyO3 | A Rust function is exported through a PyO3 module and built with maturin. | Rust can return a Python exception through a `PyResult`. | +Every module exports `compute_fibonacci(n)`. The workshop counts from `compute_fibonacci(0) == 1` +and `compute_fibonacci(1) == 2`. Index 44 gives 1,836,311,903, the last term that fits in a signed +32-bit result. Each implementation checks the index before entering the loop. Use Python integers +from 0 through 44 for comparisons. Argument conversion is part of each binding: for example, Cython +converts `1.5` to the C integer 1, while the other examples reject that float. Very large integers +can also fail conversion before reaching the range check. + +| Example | How the call reaches native code | What to look for | +| ----------------- | ------------------------------------------------------------------------- | ----------------------------------------------------------------------- | +| CFFI | Python declares a C ABI and opens a shared library at runtime. | The declaration must agree with the compiled header. | +| Cython wrapping C | A declaration tells Cython how to call the existing C function. | The generated extension links against the C implementation. | +| Typed Cython | Cython compiles the loop itself. | C integer locals move arithmetic out of the Python interpreter. | +| SWIG | An interface file tells SWIG which declarations to wrap. | A generated Python proxy presents C functions and struct fields. | +| pybind11 | A C++ module registers a function with pybind11. | Its argument and return types determine how values are converted. | +| nanobind | A second C++ module registers the same C++ function with nanobind. | Compare the two registration calls while keeping the native work fixed. | +| PyO3 | A Rust function is exported through a PyO3 module and built with maturin. | Rust can return a Python exception through a `PyResult`. | ## Inspect the C interface @@ -23,12 +28,26 @@ Every module exports `compute_fibonacci(n)`. The workshop counts from `compute_f (7, 42, 1024) ``` -The CFFI example is useful when a library already exposes a C ABI and can ship as a shared object. Cython can call an existing C function or compile the hot loop itself. SWIG is useful when you have headers to expose and want the generator to produce wrappers. Compare the [CFFI modes](https://cffi.readthedocs.io/en/stable/overview.html), [Cython language guide](https://cython.readthedocs.io/en/stable/src/userguide/index.html), and [SWIG Python guide](https://www.swig.org/Doc4.5/Python.html). +The CFFI example is useful when a library already exposes a C ABI and can ship as a shared object. +Cython can call an existing C function or compile the hot loop itself. SWIG is useful when you have +headers to expose and want the generator to produce wrappers. Compare the +[CFFI modes](https://cffi.readthedocs.io/en/stable/overview.html), +[Cython language guide](https://cython.readthedocs.io/en/stable/src/userguide/index.html), and +[SWIG Python guide](https://www.swig.org/Doc4.5/Python.html). ## Inspect the C++ and Rust interfaces -Read the C++ module definitions side by side in `native/bindings/`. Both call the implementation in `native/core/`. pybind11 offers an extensive set of conversions and integrations. nanobind was designed with smaller extension binaries and lower binding overhead in mind. The [pybind11 build guide](https://pybind11.readthedocs.io/en/stable/compiling.html) and [nanobind design notes](https://nanobind.readthedocs.io/en/latest/why.html) explain their tradeoffs. +Read the C++ module definitions side by side in `native/bindings/`. Both call the implementation in +`native/core/`. pybind11 offers an extensive set of conversions and integrations. nanobind was +designed with smaller extension binaries and lower binding overhead in mind. The +[pybind11 build guide](https://pybind11.readthedocs.io/en/stable/compiling.html) and +[nanobind design notes](https://nanobind.readthedocs.io/en/latest/why.html) explain their tradeoffs. -For Rust, start at `rust/src/lib.rs`. Follow the Python argument into the native loop and the result back into Python. Cargo resolves Rust dependencies, PyO3 handles Python objects and exceptions, and maturin builds an installable extension. See the [PyO3 guide](https://pyo3.rs/) and [maturin guide](https://www.maturin.rs/). +For Rust, start at `rust/src/lib.rs`. Follow the Python argument into the native loop and the result +back into Python. Cargo resolves Rust dependencies, PyO3 handles Python objects and exceptions, and +maturin builds an installable extension. See the [PyO3 guide](https://pyo3.rs/) and +[maturin guide](https://www.maturin.rs/). -PyPy is an alternative Python interpreter. This workshop tests CPython so that changes in interpreter and changes in binding library can be studied separately. The [CFFI documentation](https://cffi.readthedocs.io/en/stable/overview.html) also covers use with PyPy. +PyPy is an alternative Python interpreter. This workshop tests CPython so that changes in +interpreter and changes in binding library can be studied separately. The +[CFFI documentation](https://cffi.readthedocs.io/en/stable/overview.html) also covers use with PyPy. diff --git a/docs/exercises.md b/docs/exercises.md index 3e68091..e331461 100644 --- a/docs/exercises.md +++ b/docs/exercises.md @@ -1,15 +1,15 @@ # Workshop labs These four labs have working implementations and tests. From the repository root, run -`uv run --locked python` to try the Python snippets interactively. After editing a -`.pyx`, `.i`, or C++ file, exit Python and run the corresponding pytest command. uv -rebuilds the local package when its native sources change. +`uv run --locked python` to try the Python snippets interactively. After editing a `.pyx`, `.i`, or +C++ file, exit Python and run the corresponding pytest command. uv rebuilds the local package when +its native sources change. ## 1. Integrate a cosine with Cython -The left-rectangle rule divides an interval into equal widths, samples the function -at each rectangle's left edge, and sums the areas. The integral of cosine from zero -to π/2 is exactly one, so you can measure the approximation error directly. +The left-rectangle rule divides an interval into equal widths, samples the function at each +rectangle's left edge, and sums the areas. The integral of cosine from zero to π/2 is exactly one, +so you can measure the approximation error directly. ```python from math import pi @@ -23,13 +23,13 @@ for steps in (10, 100, 1_000): # 1000 1.000785 ``` -Read the Cython loop. The index uses `Py_ssize_t`, the accumulator and width use -`double`, and `cos` comes from the C math library. The positive-step check runs -once before the loop. [Integration source](https://github.com/tleonhardt/Python_Interface_Cpp/blob/main/native/labs/integration.pyx) +Read the Cython loop. The index uses `Py_ssize_t`, the accumulator and width use `double`, and `cos` +comes from the C math library. The positive-step check runs once before the loop. +[Integration source](https://github.com/tleonhardt/Python_Interface_Cpp/blob/main/native/labs/integration.pyx) -**Try it.** Reimplement the same loop in Python with `math.cos`. Compare both answers -for two rectangles on the interval from zero to π, then reverse the bounds. Which -endpoint does each approximation sample first? +**Try it.** Reimplement the same loop in Python with `math.cos`. Compare both answers for two +rectangles on the interval from zero to π, then reverse the bounds. Which endpoint does each +approximation sample first? ```sh uv run --locked pytest tests/test_labs.py -k integration @@ -37,9 +37,9 @@ uv run --locked pytest tests/test_labs.py -k integration ## 2. Pass a Python buffer to zlib with Cython -The buffer binding accepts any one-dimensional, contiguous buffer of unsigned bytes, -including `bytes` and `bytearray`. A sliced memoryview can select the region to -compress without copying the input. +The buffer binding accepts any one-dimensional, contiguous buffer of unsigned bytes, including +`bytes` and `bytearray`. A sliced memoryview can select the region to compress without copying the +input. ```python import zlib @@ -52,14 +52,15 @@ assert zlib.decompress(packed) == payload assert buffer_codec.decompress(packed, len(payload)) == payload ``` -The declaration `const unsigned char[::1]` gives the wrapper a contiguous input view. -The compressor allocates the output using `compressBound`. For decompression the caller -supplies the original size. zlib updates the output length, and the wrapper checks it -before returning Python bytes. [Buffer binding](https://github.com/tleonhardt/Python_Interface_Cpp/blob/main/native/labs/buffer_codec.pyx) · [zlib utility functions](https://zlib.net/manual.html#Utility) +The declaration `const unsigned char[::1]` gives the wrapper a contiguous input view. The compressor +allocates the output using `compressBound`. For decompression the caller supplies the original size. +zlib updates the output length, and the wrapper checks it before returning Python bytes. +[Buffer binding](https://github.com/tleonhardt/Python_Interface_Cpp/blob/main/native/labs/buffer_codec.pyx) +· [zlib utility functions](https://zlib.net/manual.html#Utility) -**Try it.** Compress 100,000 copies of the same byte, then decompress with the exact -size and with an expected size one byte smaller. Which call raises `ValueError`? -Why would allocating a fixed multiple of the compressed size be unreliable? +**Try it.** Compress 100,000 copies of the same byte, then decompress with the exact size and with +an expected size one byte smaller. Which call raises `ValueError`? Why would allocating a fixed +multiple of the compressed size be unreliable? ```sh uv run --locked pytest tests/test_labs.py -k buffer_codec @@ -67,9 +68,9 @@ uv run --locked pytest tests/test_labs.py -k buffer_codec ## 3. Wrap a C++ byte vector with SWIG -This binding uses the same zlib format. SWIG's `std_vector.i` converts a Python -sequence of integers into a `std::vector`. The interface also exposes -the vector class as `ByteVector` so you can build or mutate a C++ container from Python. +This binding uses the same zlib format. SWIG's `std_vector.i` converts a Python sequence of integers +into a `std::vector`. The interface also exposes the vector class as `ByteVector` so +you can build or mutate a C++ container from Python. ```python import zlib @@ -83,14 +84,16 @@ restored = vector_codec.decompress(list(packed), len(samples)) assert restored == bytes([0, 127, 255, 42]) ``` -Read the `%template(ByteVector)` declaration and the compression signature together. -The C++ function borrows its input by const reference and returns its output by value. -The output typemap copies the contiguous result directly into a Python `bytes` object. -Iteration uses checked integer indexing, and slices return independent byte vectors. -[SWIG interface](https://github.com/tleonhardt/Python_Interface_Cpp/blob/main/native/labs/vector_codec.i) · [C++ implementation](https://github.com/tleonhardt/Python_Interface_Cpp/blob/main/native/labs/vector_codec.cpp) +Read the `%template(ByteVector)` declaration and the compression signature together. The C++ +function borrows its input by const reference and returns its output by value. The output typemap +copies the contiguous result directly into a Python `bytes` object. Iteration uses checked integer +indexing, and slices return independent byte vectors. +[SWIG interface](https://github.com/tleonhardt/Python_Interface_Cpp/blob/main/native/labs/vector_codec.i) +· +[C++ implementation](https://github.com/tleonhardt/Python_Interface_Cpp/blob/main/native/labs/vector_codec.cpp) -**Try it.** Change the final element in `samples`, compress it again and decompress -with the Cython binding from lab 2. Predict the last byte before inspecting it. +**Try it.** Change the final element in `samples`, compress it again and decompress with the Cython +binding from lab 2. Predict the last byte before inspecting it. ```sh uv run --locked pytest tests/test_labs.py -k "vector_codec or byte_vector" @@ -98,8 +101,8 @@ uv run --locked pytest tests/test_labs.py -k "vector_codec or byte_vector" ## 4. Call a Python logger from C++ -A SWIG director routes a C++ virtual method call to an override on a Python subclass. -Here, `emit_message` takes a `Logger&` and calls its `log` method synchronously. +A SWIG director routes a C++ virtual method call to an override on a Python subclass. Here, +`emit_message` takes a `Logger&` and calls its `log` method synchronously. ```python from native_examples.callbacks import Logger, emit_message @@ -117,19 +120,23 @@ emit_message(recorder, 30, "low battery") assert recorder.messages == [(30, "low battery")] ``` -Python owns the recorder throughout. The C++ function borrows it for one call and -keeps no pointer afterward. The SWIG interface enables directors for `Logger` and -returns any exception from the Python override to the original caller. -[Logger and dispatch function](https://github.com/tleonhardt/Python_Interface_Cpp/blob/main/native/labs/callbacks.hpp) · [Director interface](https://github.com/tleonhardt/Python_Interface_Cpp/blob/main/native/labs/callbacks.i) · [SWIG director exceptions](https://www.swig.org/Doc4.5/Python.html#Python_director_exception_unrolling) +Python owns the recorder throughout. The C++ function borrows it for one call and keeps no pointer +afterward. The SWIG interface enables directors for `Logger` and returns any exception from the +Python override to the original caller. +[Logger and dispatch function](https://github.com/tleonhardt/Python_Interface_Cpp/blob/main/native/labs/callbacks.hpp) +· +[Director interface](https://github.com/tleonhardt/Python_Interface_Cpp/blob/main/native/labs/callbacks.i) +· +[SWIG director exceptions](https://www.swig.org/Doc4.5/Python.html#Python_director_exception_unrolling) -**Try it.** Add a Python subclass whose `log` raises `LookupError(message)`. Call -`emit_message` with it and catch the exception in Python. Trace the path from the -call site through the C++ function to the override and back. +**Try it.** Add a Python subclass whose `log` raises `LookupError(message)`. Call `emit_message` +with it and catch the exception in Python. Trace the path from the call site through the C++ +function to the override and back. ```sh uv run --locked pytest tests/test_labs.py -k callback ``` -The full lab test file includes standard-library interoperability, invalid output -sizes, empty streams, callback exceptions and object lifetimes. +The full lab test file includes standard-library interoperability, invalid output sizes, empty +streams, callback exceptions and object lifetimes. [Lab tests](https://github.com/tleonhardt/Python_Interface_Cpp/blob/main/tests/test_labs.py) diff --git a/docs/index.md b/docs/index.md index 2d3b97d..a0507c0 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,18 +1,23 @@ # Call native code from Python -Build the extensions once and try two versions of the same function. Follow the [binding comparison](bindings.md) to see what crosses the Python/native boundary in each version. +Build the extensions once and try two versions of the same function. Follow the +[binding comparison](bindings.md) to see what crosses the Python/native boundary in each version. ## Install the toolchain -Use CPython 3.11 through 3.15. The repository selects CPython 3.15 by default, and uv can provision it. Install [uv](https://docs.astral.sh/uv/getting-started/installation/) and [stable Rust with Cargo](https://rustup.rs/). uv installs the Python build backends, binding generators, and development tools. You also need a C and C++17 compiler and zlib development files. +Use CPython 3.11 through 3.15. The repository selects CPython 3.15 by default, and uv can provision +it. Install [uv](https://docs.astral.sh/uv/getting-started/installation/) and +[stable Rust with Cargo](https://rustup.rs/). uv installs the Python build backends, binding +generators, and development tools. You also need a C and C++17 compiler and zlib development files. -| Platform | Native prerequisites | -| --- | --- | -| macOS | Install Xcode Command Line Tools with `xcode-select --install`. The macOS SDK supplies zlib. | -| Ubuntu / Debian | Install the compiler, Make, and zlib headers with `sudo apt-get install build-essential zlib1g-dev`. | -| Windows x64 | Install Visual Studio Build Tools with **Desktop development with C++**, the Windows SDK, and the MSVC Rust toolchain. Install zlib using [vcpkg](https://learn.microsoft.com/vcpkg/get_started/get-started). | +| Platform | Native prerequisites | +| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| macOS | Install Xcode Command Line Tools with `xcode-select --install`. The macOS SDK supplies zlib. | +| Ubuntu / Debian | Install the compiler, Make, and zlib headers with `sudo apt-get install build-essential zlib1g-dev`. | +| Windows x64 | Install Visual Studio Build Tools with **Desktop development with C++**, the Windows SDK, and the MSVC Rust toolchain. Install zlib using [vcpkg](https://learn.microsoft.com/vcpkg/get_started/get-started). | -On Windows, run the following in a Developer PowerShell with vcpkg on your PATH. Set the root to your vcpkg checkout first. The static zlib build uses the same dynamic C runtime as CPython. +On Windows, run the following in a Developer PowerShell with vcpkg on your PATH. Set the root to +your vcpkg checkout first. The static zlib build uses the same dynamic C runtime as CPython. ```powershell $env:VCPKG_ROOT = 'C:\src\vcpkg' @@ -23,7 +28,9 @@ $env:CMAKE_ARGS = "-DVCPKG_TARGET_TRIPLET=x64-windows-static-md" ## Build and run -From the repository root, run these commands on any supported platform. The first sync compiles a C/C++ package with scikit-build-core and a Rust package with maturin. Later syncs reuse the builds until their inputs change. +From the repository root, run these commands on any supported platform. The first sync compiles a +C/C++ package with scikit-build-core and a Rust package with maturin. Later syncs reuse the builds +until their inputs change. ```sh uv sync --locked @@ -42,8 +49,17 @@ At the Python prompt, compare the two C++ bindings and Rust. ## Develop locally -With Make installed, use `make hooks` once to install prek, `make check` to run the hooks across the repository, and `make test` after editing code. The Python and Cargo lockfiles are committed. To test another supported interpreter, set `UV_PYTHON` to the desired version before running Make, or run `uv run --locked --python 3.11 python -m pytest`. +With Make installed, use `make hooks` once to install prek, `make check` to run the hooks across the +repository, and `make test` after editing code. The Python and Cargo lockfiles are committed. To +test another supported interpreter, set `UV_PYTHON` to the desired version before running Make, or +run `uv run --locked --python 3.11 python -m pytest`. -Run `make docs` for a live preview and `make docs-test` for a strict build. GitHub Actions builds the documentation on pull requests and uploads the rendered site as an artifact. A merge to `main` publishes the site through GitHub Pages. +The prek hook formats staged Markdown with Prettier. To format all tracked Markdown, including the +README and this guide, run `uv run --locked prek run prettier --all-files`. Review and stage the +changes before committing. The GitHub Actions quality job runs the same hook across the repository. + +Run `make docs` for a live preview and `make docs-test` for a strict build. GitHub Actions builds +the documentation on pull requests and uploads the rendered site as an artifact. A merge to `main` +publishes the site through GitHub Pages. Continue to the [worked examples and optional exercises](exercises.md). From 428d1e58dc651bb910120c7c862d5ba9e313a0c6 Mon Sep 17 00:00:00 2001 From: Todd Leonhardt <2812720+tleonhardt@users.noreply.github.com> Date: Sat, 5 Dec 2026 18:11:44 -0500 Subject: [PATCH 10/16] Preserve one-shot iterable inputs to ByteVector --- native/labs/vector_codec.i | 14 ++++++++++++++ tests/test_labs.py | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/native/labs/vector_codec.i b/native/labs/vector_codec.i index 3485c60..4d2588d 100644 --- a/native/labs/vector_codec.i +++ b/native/labs/vector_codec.i @@ -7,6 +7,20 @@ #define SWIG_NO_EXPORT_ITERATOR_METHODS %include %include + +%pythoncode %{ +from collections.abc import Iterable as _Iterable, Sequence as _Sequence +%} + +// SWIG probes the elements before calling the sequence constructor. Give it a +// reusable input for generators and other iterable sources that may be single-pass. +%pythonprepend std::vector::vector %{ + if len(args) == 1: + source = args[0] + if isinstance(source, _Iterable) and not isinstance(source, (_Sequence, ByteVector)): + args = (tuple(source),) +%} + // Python indexing and pop() check bounds before accessing an element. %ignore std::vector::front; %ignore std::vector::back; diff --git a/tests/test_labs.py b/tests/test_labs.py index 5b402bf..4a55fd4 100644 --- a/tests/test_labs.py +++ b/tests/test_labs.py @@ -59,6 +59,14 @@ def test_vector_codec_uses_zlib_format(data): assert restored == data +def test_byte_vector_constructs_from_iterator(): + from native_examples.vector_codec import ByteVector + + assert list(ByteVector(iter([1, 2, 3]))) == [1, 2, 3] + with pytest.raises(TypeError): + ByteVector(iter([1, 256])) + + def test_byte_vector_uses_checked_element_access(): from native_examples.vector_codec import ByteVector From d40de81130c5409eff4d7f8665fddc2ef0b426d2 Mon Sep 17 00:00:00 2001 From: Todd Leonhardt <2812720+tleonhardt@users.noreply.github.com> Date: Sat, 5 Dec 2026 18:37:40 -0500 Subject: [PATCH 11/16] Validate slice elements, ship the Rust license, and ignore dotenv files --- .gitignore | 1 + native/labs/vector_codec.i | 3 ++- rust/LICENSE | 21 +++++++++++++++++++++ rust/pyproject.toml | 3 +++ tests/test_labs.py | 13 +++++++++++++ 5 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 rust/LICENSE diff --git a/.gitignore b/.gitignore index 2199f38..434e656 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .venv/ +.env __pycache__/ *.py[cod] *.egg-info/ diff --git a/native/labs/vector_codec.i b/native/labs/vector_codec.i index 4d2588d..e59a21d 100644 --- a/native/labs/vector_codec.i +++ b/native/labs/vector_codec.i @@ -44,7 +44,8 @@ def __getitem__(self, key): def __setitem__(self, key, value): if isinstance(key, slice): data = bytearray(self) - data[key] = value + # Assign each element, including when the source exports a multi-byte buffer. + data[key] = (element for element in value) self.swap(ByteVector(data)) else: $action(self, key, value) diff --git a/rust/LICENSE b/rust/LICENSE new file mode 100644 index 0000000..1496144 --- /dev/null +++ b/rust/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Todd Leonhardt + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/rust/pyproject.toml b/rust/pyproject.toml index a6405b0..f57447a 100644 --- a/rust/pyproject.toml +++ b/rust/pyproject.toml @@ -6,6 +6,8 @@ build-backend = "maturin" name = "rust-fibonacci" dynamic = ["version", "description"] requires-python = ">=3.11" +license = "MIT" +license-files = ["LICENSE"] [tool.maturin] locked = true @@ -15,5 +17,6 @@ cache-keys = [ { file = "pyproject.toml" }, { file = "Cargo.toml" }, { file = "Cargo.lock" }, + { file = "LICENSE" }, { file = "src/**/*.rs" }, ] diff --git a/tests/test_labs.py b/tests/test_labs.py index 4a55fd4..80c30b9 100644 --- a/tests/test_labs.py +++ b/tests/test_labs.py @@ -2,6 +2,7 @@ import sys import weakref import zlib +from array import array from importlib import import_module import pytest @@ -150,6 +151,18 @@ def test_byte_vector_slice_edits_follow_python(): assert list(vector) == [10, 30] +def test_byte_vector_slice_assigns_multibyte_buffer_elements(): + from native_examples.vector_codec import ByteVector + + vector = ByteVector([42]) + vector[:] = array("H", [1, 2]) + assert list(vector) == [1, 2] + + with pytest.raises(ValueError): + vector[:] = array("H", [3, 256]) + assert list(vector) == [1, 2] + + def test_byte_vector_rejects_impossible_capacity(): from native_examples.vector_codec import ByteVector From d691e5ee74beedc9e5b88db57ffdbdbc104688a2 Mon Sep 17 00:00:00 2001 From: Todd Leonhardt <2812720+tleonhardt@users.noreply.github.com> Date: Sat, 5 Dec 2026 18:48:07 -0500 Subject: [PATCH 12/16] Preserve custom sequence inputs and allow interrupts during integration --- docs/exercises.md | 3 ++- native/labs/integration.pyx | 13 +++++++++--- native/labs/vector_codec.i | 10 ++++++---- tests/test_labs.py | 40 ++++++++++++++++++++++++++++++++++++- 4 files changed, 57 insertions(+), 9 deletions(-) diff --git a/docs/exercises.md b/docs/exercises.md index e331461..7caff0d 100644 --- a/docs/exercises.md +++ b/docs/exercises.md @@ -24,7 +24,8 @@ for steps in (10, 100, 1_000): ``` Read the Cython loop. The index uses `Py_ssize_t`, the accumulator and width use `double`, and `cos` -comes from the C math library. The positive-step check runs once before the loop. +comes from the C math library. The loop releases the GIL while summing each chunk, so other Python +threads can run. Between chunks it checks for signals, so Ctrl-C can interrupt a long calculation. [Integration source](https://github.com/tleonhardt/Python_Interface_Cpp/blob/main/native/labs/integration.pyx) **Try it.** Reimplement the same loop in Python with `math.cos`. Compare both answers for two diff --git a/native/labs/integration.pyx b/native/labs/integration.pyx index 964a051..c2967ef 100644 --- a/native/labs/integration.pyx +++ b/native/labs/integration.pyx @@ -1,5 +1,6 @@ """Approximate the integral of cos(x) using left-endpoint rectangles.""" +from cpython.exc cimport PyErr_CheckSignals from libc.math cimport cos @@ -9,7 +10,13 @@ def integrate_cos(double start, double stop, Py_ssize_t steps): cdef double width = (stop - start) / steps cdef double total = 0.0 - cdef Py_ssize_t i - for i in range(steps): - total += cos(start + i * width) + cdef Py_ssize_t i, first = 0, end + cdef Py_ssize_t chunk_size = 65_536 + while first < steps: + end = first + min(steps - first, chunk_size) + with nogil: + for i in range(first, end): + total += cos(start + i * width) + PyErr_CheckSignals() + first = end return total * width diff --git a/native/labs/vector_codec.i b/native/labs/vector_codec.i index e59a21d..7511f53 100644 --- a/native/labs/vector_codec.i +++ b/native/labs/vector_codec.i @@ -9,15 +9,17 @@ %include %pythoncode %{ -from collections.abc import Iterable as _Iterable, Sequence as _Sequence +from collections.abc import Iterable as _Iterable %} // SWIG probes the elements before calling the sequence constructor. Give it a -// reusable input for generators and other iterable sources that may be single-pass. +// reusable input even if a sequence subclass overrides iteration. %pythonprepend std::vector::vector %{ - if len(args) == 1: + if len(args) == 1 and not isinstance(args[0], (int, ByteVector)): source = args[0] - if isinstance(source, _Iterable) and not isinstance(source, (_Sequence, ByteVector)): + source_type = type(source) + reusable = source_type in (list, tuple, bytes, bytearray, range, memoryview, str) + if not reusable and (isinstance(source, _Iterable) or hasattr(source_type, "__getitem__")): args = (tuple(source),) %} diff --git a/tests/test_labs.py b/tests/test_labs.py index 80c30b9..c78d62c 100644 --- a/tests/test_labs.py +++ b/tests/test_labs.py @@ -1,9 +1,11 @@ import math +import subprocess import sys import weakref import zlib from array import array from importlib import import_module +from textwrap import dedent import pytest @@ -18,7 +20,7 @@ def test_integration_uses_left_endpoints(): from native_examples.integration import integrate_cos assert integrate_cos(0, math.pi, 2) == pytest.approx(math.pi / 2) - assert integrate_cos(0, math.pi / 2, 10_000) == pytest.approx(1, abs=0.0001) + assert integrate_cos(0, math.pi / 2, 100_000) == pytest.approx(1, abs=0.00001) assert integrate_cos(math.pi / 2, 0, 10_000) == pytest.approx(-1, abs=0.0001) @@ -30,6 +32,28 @@ def test_integration_rejects_nonpositive_counts(count): integrate_cos(0, 1, count) +def test_long_integration_can_be_interrupted_by_another_thread(): + # A regression can hold the GIL indefinitely, so bound the run from another process. + script = dedent(""" + import _thread + import sys + from threading import Timer + from native_examples.integration import integrate_cos + + timer = Timer(0.1, _thread.interrupt_main) + timer.start() + try: + integrate_cos(0, 1, sys.maxsize) + except KeyboardInterrupt: + pass + else: + raise AssertionError("integration finished before the interrupt") + finally: + timer.join() + """) + subprocess.run([sys.executable, "-c", script], check=True, timeout=10) + + @pytest.mark.parametrize("data", PAYLOADS) def test_buffer_codec_uses_zlib_format(data): from native_examples import buffer_codec @@ -68,6 +92,20 @@ def test_byte_vector_constructs_from_iterator(): ByteVector(iter([1, 256])) +def test_byte_vector_constructs_from_single_pass_sequence(): + from native_examples.vector_codec import ByteVector + + class SinglePassList(list): + def __init__(self, values): + super().__init__(values) + self.items = super().__iter__() + + def __iter__(self): + return self.items + + assert list(ByteVector(SinglePassList([7, 9]))) == [7, 9] + + def test_byte_vector_uses_checked_element_access(): from native_examples.vector_codec import ByteVector From 5bebfebce0aa6cfb6b0f7f657dde961499dad4c7 Mon Sep 17 00:00:00 2001 From: Todd Leonhardt <2812720+tleonhardt@users.noreply.github.com> Date: Sat, 5 Dec 2026 18:52:50 -0500 Subject: [PATCH 13/16] Ship third-party license notices with both native wheels --- native/THIRD_PARTY_NOTICES.txt | 366 +++++++++++++++++++++++++++++++++ native/pyproject.toml | 7 +- rust/THIRD_PARTY_NOTICES.txt | 162 +++++++++++++++ rust/pyproject.toml | 5 +- tests/test_notices.py | 32 +++ 5 files changed, 568 insertions(+), 4 deletions(-) create mode 100644 native/THIRD_PARTY_NOTICES.txt create mode 100644 rust/THIRD_PARTY_NOTICES.txt create mode 100644 tests/test_notices.py diff --git a/native/THIRD_PARTY_NOTICES.txt b/native/THIRD_PARTY_NOTICES.txt new file mode 100644 index 0000000..0351704 --- /dev/null +++ b/native/THIRD_PARTY_NOTICES.txt @@ -0,0 +1,366 @@ +The native-examples project sources are licensed under the MIT License. +The accompanying LICENSE file contains the project's copyright notice and grant. +The following notices apply to third-party code included in binary builds. + +pybind11 3.1.0 +============== + +Copyright (c) 2016 Wenzel Jakob , All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Please also refer to the file .github/CONTRIBUTING.md, which clarifies licensing of +external contributions to this project including patches, pull requests, etc. + +Additional copyright notices from the binding headers: + +Copyright (c) 2016 Wenzel Jakob +Copyright (c) 2016-2024 The Pybind Development Team. +Copyright (c) 2016-2025 The Pybind Development Team. +Copyright (c) 2017 Jason Rhinelander +Copyright (c) 2017 Wenzel Jakob +Copyright (c) 2020-2024 The Pybind Development Team. +Copyright (c) 2021 The Pybind Development Team. +Copyright (c) 2022-2025 The pybind Community. +Copyright (c) 2023 Dustin Spicuzza +Copyright (c) 2023 The pybind Community. +Copyright (c) 2024 The Pybind Development Team. +Copyright (c) 2024 The pybind Community. +Copyright (c) 2024-2025 The Pybind Development Team. +Copyright (c) 2025 Hudson River Trading LLC +Copyright (c) Meta Platforms, Inc. and affiliates. + +The function_ref header in pybind11 is derived from LLVM under the Apache License +2.0 with LLVM Exceptions (https://llvm.org/LICENSE.txt). + +============================================================================== +The LLVM Project is under the Apache License v2.0 with LLVM Exceptions: +============================================================================== + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + +---- LLVM Exceptions to the Apache 2.0 License ---- + +As an exception, if, as a result of your compiling your source code, portions +of this Software are embedded into an Object form of such source code, you +may redistribute such embedded portions in such Object form without complying +with the conditions of Sections 4(a), 4(b) and 4(d) of the License. + +In addition, if you combine or link compiled forms of this Software with +software that is licensed under the GPLv2 ("Combined Software") and if a +court of competent jurisdiction determines that the patent provision (Section +3), the indemnity provision (Section 9) or other Section of the License +conflicts with the conditions of the GPLv2, you may retroactively and +prospectively choose to deem waived or otherwise exclude such Section(s) of +the License, but only in their entirety and only with respect to the Combined +Software. + +nanobind 3.1.0 +============== + +Copyright (c) 2022 Wenzel Jakob , All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Additional notice from src/nb_datetime.cpp: + +Copyright (c) 2023 Hudson River Trading LLC +Copyright (c) 2026 Wenzel Jakob + +Tessil robin-map (bundled with nanobind 3.1.0) +============================================== + +MIT License + +Copyright (c) 2017 Thibaut Goetghebuer-Planchon + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +zlib (statically linked in Windows builds using zlib 1.4) +========================================================= + +Copyright notice: + + (C) 1995-2026 Jean-loup Gailly and Mark Adler + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jean-loup Gailly Mark Adler + jloup@gzip.org madler@alumni.caltech.edu diff --git a/native/pyproject.toml b/native/pyproject.toml index c9202e6..5612774 100644 --- a/native/pyproject.toml +++ b/native/pyproject.toml @@ -13,8 +13,9 @@ name = "native-examples" version = "0.1.0" description = "Runnable examples of Python interfaces to C and C++" requires-python = ">=3.11" -license = "MIT" -license-files = ["LICENSE"] +# The project's MIT license and component notices cover distributions with +# different contents (for example, zlib may be linked statically or dynamically). +license-files = ["LICENSE", "THIRD_PARTY_NOTICES.txt"] dependencies = ["cffi==2.1.1"] [tool.scikit-build] @@ -24,6 +25,8 @@ wheel.packages = ["src/native_examples"] [tool.uv] cache-keys = [ { file = "pyproject.toml" }, + { file = "LICENSE" }, + { file = "THIRD_PARTY_NOTICES.txt" }, { file = "CMakeLists.txt" }, { file = "labs.cmake" }, { file = "bindings/**/*" }, diff --git a/rust/THIRD_PARTY_NOTICES.txt b/rust/THIRD_PARTY_NOTICES.txt new file mode 100644 index 0000000..7298400 --- /dev/null +++ b/rust/THIRD_PARTY_NOTICES.txt @@ -0,0 +1,162 @@ +The rust-fibonacci project sources are licensed under the MIT License. +The accompanying LICENSE file contains the project's copyright notice and grant. + +PyO3 0.30.1 (including pyo3-ffi and the PyO3 macros) +==================================================== + +Copyright (c) 2023-present PyO3 Project and Contributors. https://github.com/PyO3 + +Permission is hereby granted, free of charge, to any +person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the +Software without restriction, including without +limitation the rights to use, copy, modify, merge, +publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice +shall be included in all copies or substantial portions +of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF +ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR +IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. + +PyO3 buffer module (src/buffer.rs) +================================== + +Copyright (c) 2017 Daniel Grunwald + +Permission is hereby granted, free of charge, to any person obtaining a copy of this +software and associated documentation files (the "Software"), to deal in the Software +without restriction, including without limitation the rights to use, copy, modify, merge, +publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons +to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or +substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR +PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE +FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. + +libc 0.2.191 and the Rust standard library +========================================== + +Copyright (c) The Rust Project Developers + +Permission is hereby granted, free of charge, to any +person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the +Software without restriction, including without +limitation the rights to use, copy, modify, merge, +publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice +shall be included in all copies or substantial portions +of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF +ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR +IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. + +The Rust toolchain includes its standard library attribution report in +share/doc/rust/COPYRIGHT-library.html. + +The same MIT terms also apply to the following code in the Rust runtime: + +backtrace and rustc-demangle: Copyright (c) 2014 Alex Crichton +addr2line: Copyright (c) 2016-2018 The gimli Developers +gimli: Copyright (c) 2015 The Rust Project Developers +object: Copyright (c) 2015 The Gimli Developers +memchr: Copyright (c) 2015 Andrew Gallant + +once_cell 1.21.4 and portable-atomic 1.15.0 +=========================================== + +Permission is hereby granted, free of charge, to any +person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the +Software without restriction, including without +limitation the rights to use, copy, modify, merge, +publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice +shall be included in all copies or substantial portions +of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF +ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR +IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. + +Unicode data tables in the Rust standard library +================================================ + +UNICODE LICENSE V3 + +COPYRIGHT AND PERMISSION NOTICE + +Copyright © 1991-2024 Unicode, Inc. + +NOTICE TO USER: Carefully read the following legal agreement. BY +DOWNLOADING, INSTALLING, COPYING OR OTHERWISE USING DATA FILES, AND/OR +SOFTWARE, YOU UNEQUIVOCALLY ACCEPT, AND AGREE TO BE BOUND BY, ALL OF THE +TERMS AND CONDITIONS OF THIS AGREEMENT. IF YOU DO NOT AGREE, DO NOT +DOWNLOAD, INSTALL, COPY, DISTRIBUTE OR USE THE DATA FILES OR SOFTWARE. + +Permission is hereby granted, free of charge, to any person obtaining a +copy of data files and any associated documentation (the "Data Files") or +software and any associated documentation (the "Software") to deal in the +Data Files or Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, and/or sell +copies of the Data Files or Software, and to permit persons to whom the +Data Files or Software are furnished to do so, provided that either (a) +this copyright and permission notice appear with all copies of the Data +Files or Software, or (b) this copyright and permission notice appear in +associated Documentation. + +THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF +THIRD PARTY RIGHTS. + +IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE +BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, +OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, +ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THE DATA +FILES OR SOFTWARE. + +Except as contained in this notice, the name of a copyright holder shall +not be used in advertising or otherwise to promote the sale, use or other +dealings in these Data Files or Software without prior written +authorization of the copyright holder. diff --git a/rust/pyproject.toml b/rust/pyproject.toml index f57447a..970c94f 100644 --- a/rust/pyproject.toml +++ b/rust/pyproject.toml @@ -6,8 +6,8 @@ build-backend = "maturin" name = "rust-fibonacci" dynamic = ["version", "description"] requires-python = ">=3.11" -license = "MIT" -license-files = ["LICENSE"] +license = "MIT AND Unicode-3.0" +license-files = ["LICENSE", "THIRD_PARTY_NOTICES.txt"] [tool.maturin] locked = true @@ -18,5 +18,6 @@ cache-keys = [ { file = "Cargo.toml" }, { file = "Cargo.lock" }, { file = "LICENSE" }, + { file = "THIRD_PARTY_NOTICES.txt" }, { file = "src/**/*.rs" }, ] diff --git a/tests/test_notices.py b/tests/test_notices.py new file mode 100644 index 0000000..9abef5c --- /dev/null +++ b/tests/test_notices.py @@ -0,0 +1,32 @@ +from importlib.metadata import distribution + +import pytest + + +@pytest.mark.parametrize( + ("package", "attributions"), + [ + ( + "native-examples", + [ + "pybind11", + "nanobind", + "Thibaut Goetghebuer-Planchon", + "LLVM Exceptions to the Apache 2.0 License", + "Jean-loup Gailly and Mark Adler", + ], + ), + ( + "rust-fibonacci", + ["PyO3 Project and Contributors", "The Rust Project Developers", "UNICODE LICENSE V3"], + ), + ], +) +def test_wheel_includes_third_party_notices(package, attributions): + installed = distribution(package) + notice_file = "THIRD_PARTY_NOTICES.txt" + assert notice_file in installed.metadata.get_all("License-File", []) + contents = installed.read_text(f"licenses/{notice_file}") + assert contents is not None + for attribution in attributions: + assert attribution in contents From efe0298094b0a9b0724b8d407555da91f475e206 Mon Sep 17 00:00:00 2001 From: Todd Leonhardt <2812720+tleonhardt@users.noreply.github.com> Date: Sat, 5 Dec 2026 19:03:01 -0500 Subject: [PATCH 14/16] Reject invalid iterator bytes early and skip stale Pages deployments --- .github/workflows/docs.yml | 11 +++++++++++ native/labs/vector_codec.i | 12 +++++++++--- tests/test_labs.py | 23 +++++++++++++++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index eff27b2..3fed599 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -29,13 +29,24 @@ jobs: concurrency: group: github-pages cancel-in-progress: false + # A late build must not displace a newer commit already waiting to deploy. + queue: max permissions: + contents: read pages: write id-token: write environment: name: github-pages url: ${{ steps.deployment.outputs.page_url }} steps: + - name: Read the current main commit after acquiring the deployment slot + id: main + env: + GH_TOKEN: ${{ github.token }} + run: | + sha=$(gh api "repos/$GITHUB_REPOSITORY/git/ref/heads/main" --jq '.object.sha') + echo "sha=$sha" >> "$GITHUB_OUTPUT" - name: Deploy the guide + if: steps.main.outputs.sha == github.sha id: deployment uses: actions/deploy-pages@368f82528645a54fb793d4d04e342629a3f51346 # v5.0.1 diff --git a/native/labs/vector_codec.i b/native/labs/vector_codec.i index 7511f53..78c48ec 100644 --- a/native/labs/vector_codec.i +++ b/native/labs/vector_codec.i @@ -12,15 +12,21 @@ from collections.abc import Iterable as _Iterable %} -// SWIG probes the elements before calling the sequence constructor. Give it a -// reusable input even if a sequence subclass overrides iteration. +// SWIG probes a Python iterable during overload resolution. Validate single-pass +// inputs as they arrive, then pass the native vector to the copy constructor. %pythonprepend std::vector::vector %{ if len(args) == 1 and not isinstance(args[0], (int, ByteVector)): source = args[0] source_type = type(source) reusable = source_type in (list, tuple, bytes, bytearray, range, memoryview, str) if not reusable and (isinstance(source, _Iterable) or hasattr(source_type, "__getitem__")): - args = (tuple(source),) + validated = ByteVector() + for item in source: + try: + validated.append(item) + except OverflowError as exc: + raise TypeError("ByteVector elements must be integers from 0 to 255") from exc + args = (validated,) %} // Python indexing and pop() check bounds before accessing an element. diff --git a/tests/test_labs.py b/tests/test_labs.py index c78d62c..69ad85f 100644 --- a/tests/test_labs.py +++ b/tests/test_labs.py @@ -92,6 +92,29 @@ def test_byte_vector_constructs_from_iterator(): ByteVector(iter([1, 256])) +@pytest.mark.parametrize("invalid", [256, -1, 2.5]) +def test_byte_vector_stops_iterator_at_first_invalid_element(invalid): + from native_examples.vector_codec import ByteVector + + def values(): + yield invalid + pytest.fail("constructor read past an invalid byte") + + with pytest.raises(TypeError): + ByteVector(values()) + + +def test_byte_vector_propagates_iterator_error_after_valid_elements(): + from native_examples.vector_codec import ByteVector + + def values(): + yield 42 + raise OverflowError("input stream failed") + + with pytest.raises(OverflowError, match="input stream failed"): + ByteVector(values()) + + def test_byte_vector_constructs_from_single_pass_sequence(): from native_examples.vector_codec import ByteVector From 34b4a549dfd204fef92b23190f3163901fb4608a Mon Sep 17 00:00:00 2001 From: Todd Leonhardt <2812720+tleonhardt@users.noreply.github.com> Date: Sat, 5 Dec 2026 19:47:51 -0500 Subject: [PATCH 15/16] Consume vector codec inputs once and preserve iterator mutations during slicing --- native/labs/vector_codec.i | 28 ++++++++++++++++-------- tests/test_labs.py | 44 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 9 deletions(-) diff --git a/native/labs/vector_codec.i b/native/labs/vector_codec.i index 78c48ec..028d218 100644 --- a/native/labs/vector_codec.i +++ b/native/labs/vector_codec.i @@ -10,6 +10,19 @@ %pythoncode %{ from collections.abc import Iterable as _Iterable + + +def _as_byte_vector(source): + if isinstance(source, ByteVector): + return source + + vector = ByteVector() + for item in source: + try: + vector.append(item) + except OverflowError as exc: + raise TypeError("ByteVector elements must be integers from 0 to 255") from exc + return vector %} // SWIG probes a Python iterable during overload resolution. Validate single-pass @@ -20,13 +33,7 @@ from collections.abc import Iterable as _Iterable source_type = type(source) reusable = source_type in (list, tuple, bytes, bytearray, range, memoryview, str) if not reusable and (isinstance(source, _Iterable) or hasattr(source_type, "__getitem__")): - validated = ByteVector() - for item in source: - try: - validated.append(item) - except OverflowError as exc: - raise TypeError("ByteVector elements must be integers from 0 to 255") from exc - args = (validated,) + args = (_as_byte_vector(source),) %} // Python indexing and pop() check bounds before accessing an element. @@ -51,9 +58,10 @@ def __getitem__(self, key): %feature("shadow") std::vector::__setitem__ %{ def __setitem__(self, key, value): if isinstance(key, slice): + # The iterable may mutate self or export a multi-byte buffer. + replacement = bytes(element for element in value) data = bytearray(self) - # Assign each element, including when the source exports a multi-byte buffer. - data[key] = (element for element in value) + data[key] = replacement self.swap(ByteVector(data)) else: $action(self, key, value) @@ -96,4 +104,6 @@ def __delitem__(self, key): $result = PyBytes_FromStringAndSize(reinterpret_cast(bytes.data()), static_cast(bytes.size())); } +%pythonprepend lab::compress %{ data = _as_byte_vector(data) %} +%pythonprepend lab::decompress %{ data = _as_byte_vector(data) %} %include "vector_codec.hpp" diff --git a/tests/test_labs.py b/tests/test_labs.py index 69ad85f..abe5bbb 100644 --- a/tests/test_labs.py +++ b/tests/test_labs.py @@ -84,6 +84,42 @@ def test_vector_codec_uses_zlib_format(data): assert restored == data +@pytest.mark.parametrize("operation", ["compress", "decompress"]) +def test_vector_codec_reads_single_pass_input_once(operation): + from native_examples import vector_codec + + class DrainingList(list): + iterations = 0 + + def __iter__(self): + self.iterations += 1 + batch = self.copy() + self.clear() + return iter(batch) + + payload = b"\x01\x02\x03" + if operation == "compress": + source = DrainingList(payload) + packed = vector_codec.compress(source) + assert zlib.decompress(packed) == payload + else: + source = DrainingList(zlib.compress(payload)) + assert vector_codec.decompress(source, len(payload)) == payload + assert source.iterations == 1 + + +def test_vector_codec_borrows_existing_byte_vector(): + from native_examples import vector_codec + + class NativeInput(vector_codec.ByteVector): + def __iter__(self): + pytest.fail("codec iterated an existing native vector") + + data = b"abc" + assert zlib.decompress(vector_codec.compress(NativeInput(data))) == data + assert vector_codec.decompress(NativeInput(zlib.compress(data)), len(data)) == data + + def test_byte_vector_constructs_from_iterator(): from native_examples.vector_codec import ByteVector @@ -224,6 +260,14 @@ def test_byte_vector_slice_assigns_multibyte_buffer_elements(): assert list(vector) == [1, 2] +def test_byte_vector_slice_preserves_mutations_from_replacement_iterator(): + from native_examples.vector_codec import ByteVector + + vector = ByteVector([1, 2, 3]) + vector[:0] = (vector.pop() for _ in range(1)) + assert list(vector) == [3, 1, 2] + + def test_byte_vector_rejects_impossible_capacity(): from native_examples.vector_codec import ByteVector From f6e27e4e046f4426c58c924f82fe2586736b25fa Mon Sep 17 00:00:00 2001 From: Todd Leonhardt <2812720+tleonhardt@users.noreply.github.com> Date: Sat, 5 Dec 2026 19:51:05 -0500 Subject: [PATCH 16/16] Teach Python sequence conversion in a hands-on PyO3 lab --- README.md | 3 ++- docs/exercises.md | 43 +++++++++++++++++++++++++++++++++++++------ rust/src/lib.rs | 6 ++++++ tests/test_labs.py | 19 +++++++++++++++++++ 4 files changed, 64 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index e94c02c..f594dcf 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,8 @@ uv run --locked python -m comparison.benchmark --markdown -n 20 --calls 1000000 - [Rust extension](rust/) uses PyO3 and maturin. It exposes the same Python function as the C and C++ examples. - [The guide to the bindings](docs/bindings.md) explains when each approach fits. - [Workshop exercises](docs/exercises.md) walk through typed loops, buffers, vectors, and callbacks. + [Workshop exercises](docs/exercises.md) cover typed loops, buffers, vectors, callbacks, and + passing Python sequences to Rust with PyO3. The original [slides](Interfacing_C_C++_with_Python.pdf) and [lab handout](Interfacing_C_C++_with_Python-Exercises.pdf) accompany the diff --git a/docs/exercises.md b/docs/exercises.md index 7caff0d..afaeb7f 100644 --- a/docs/exercises.md +++ b/docs/exercises.md @@ -1,9 +1,9 @@ # Workshop labs -These four labs have working implementations and tests. From the repository root, run -`uv run --locked python` to try the Python snippets interactively. After editing a `.pyx`, `.i`, or -C++ file, exit Python and run the corresponding pytest command. uv rebuilds the local package when -its native sources change. +These five labs have working implementations and tests. From the repository root, run +`uv run --locked python` to try the Python snippets interactively. After editing Cython, SWIG, C++, +or Rust source, exit Python and run the corresponding pytest command. uv rebuilds the local package +when its native sources change. ## 1. Integrate a cosine with Cython @@ -138,6 +138,37 @@ function to the override and back. uv run --locked pytest tests/test_labs.py -k callback ``` -The full lab test file includes standard-library interoperability, invalid output sizes, empty -streams, callback exceptions and object lifetimes. +## 5. Pass a sequence from Python to Rust with PyO3 + +Suppose a Python caller needs several Fibonacci terms. Use the workshop’s `rust_fibonacci` extension +to request them in one call. Predict the result for a repeated index and for an empty list, then try +both. + +```python +from rust_fibonacci import compute_fibonacci, fibonacci_batch + +indices = [4, 0, 4, 1] +assert fibonacci_batch(indices) == [8, 1, 8, 2] +assert fibonacci_batch(indices) == [compute_fibonacci(i) for i in indices] +assert fibonacci_batch([]) == [] +``` + +Find `fibonacci_batch` in `rust/src/lib.rs`. PyO3 collects the input sequence into a Rust `Vec` of +handles to Python integers. The function maps the existing `compute_fibonacci` over those handles. +Collecting into `PyResult>` propagates a range error from the scalar function. On success, +PyO3 converts the resulting vector into a Python list. +[Rust implementation](https://github.com/tleonhardt/Python_Interface_Cpp/blob/main/rust/src/lib.rs) + +**Try it.** Rewrite the body of `fibonacci_batch` using a `for` loop. Create an empty results +vector, call `compute_fibonacci` for each index, and use Rust’s `?` operator to propagate an error +before pushing the term. Return `Ok(results)`. Run the tests below, then compare what happens in +Python for `[0, 45]` and `[0, 1.5]`. Which input reaches the scalar function’s range check, and +which fails while PyO3 converts the arguments? + +```sh +uv run --locked pytest tests/test_labs.py -k rust_fibonacci_batch +``` + +The lab tests cover empty inputs, conversion errors, interoperability with Python’s standard +library, callback exceptions and object lifetimes. [Lab tests](https://github.com/tleonhardt/Python_Interface_Cpp/blob/main/tests/test_labs.py) diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 546673f..9396088 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -21,4 +21,10 @@ mod rust_fibonacci { _ => Err(PyValueError::new_err("n must be between 0 and 44")), } } + + /// Return the Fibonacci terms for a sequence of indices, in input order. + #[pyfunction] + fn fibonacci_batch(indices: Vec>) -> PyResult> { + indices.iter().map(compute_fibonacci).collect() + } } diff --git a/tests/test_labs.py b/tests/test_labs.py index abe5bbb..3547d67 100644 --- a/tests/test_labs.py +++ b/tests/test_labs.py @@ -328,3 +328,22 @@ def log(self, level, message): with pytest.raises(LookupError, match="offline"): emit_message(BrokenLogger(), 40, "offline") + + +@pytest.mark.parametrize( + ("indices", "expected"), [([], []), ([4, 0, 4, 1], [8, 1, 8, 2]), ((2, 3), [3, 5])] +) +def test_rust_fibonacci_batch_preserves_order(indices, expected): + from rust_fibonacci import fibonacci_batch + + assert fibonacci_batch(indices) == expected + + +@pytest.mark.parametrize( + ("invalid", "error"), [(-1, ValueError), (45, ValueError), (1.5, TypeError)] +) +def test_rust_fibonacci_batch_rejects_invalid_elements(invalid, error): + from rust_fibonacci import fibonacci_batch + + with pytest.raises(error): + fibonacci_batch([0, invalid, 2])