From 8587094008aad758ca9f839dd823bd9b275b7a56 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Mon, 22 Dec 2025 11:47:08 +0100 Subject: [PATCH 1/3] Migrate build system to Meson --- .github/workflows/main.yml | 13 ++++--------- MANIFEST.in | 3 --- README.md | 13 +++++++++++++ meson.build | 34 ++++++++++++++++++++++++++++++++++ pyproject.toml | 13 +++---------- setup.py | 28 ---------------------------- 6 files changed, 54 insertions(+), 50 deletions(-) delete mode 100644 MANIFEST.in create mode 100644 meson.build delete mode 100644 setup.py diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9e7cedf..6f1b649 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -35,15 +35,10 @@ jobs: with: python-version: ${{ matrix.python-version }} architecture: ${{ matrix.architecture }} - - name: Install dependencies + - name: Build run: | python -m pip install --upgrade pip - pip install setuptools Cython Sphinx flake8 - - name: Freeze pip + python -m pip install . + - name: Test run: | - pip freeze - - name: Local build - run: | - python setup.py build_ext -i - python test.py || exit 1 - git clean -xfd + python test.py diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 0938776..0000000 --- a/MANIFEST.in +++ /dev/null @@ -1,3 +0,0 @@ -include AUTHORS -include setup.py cydoctest.py test.py pyproject.toml -graft memory_allocator diff --git a/README.md b/README.md index 956269a..fa8be15 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,21 @@ It provides a single extension class `MemoryAllocator` with `cdef` methods Memory is freed when the instance of `MemoryAllocator` is deallocated. On failure to allocate the memory, a proper error is raised. +## Building from source + +This project uses [meson-python](https://mesonbuild.com/meson-python/) for +its build backend. A typical editable install looks like: + +```shell + python -m pip install -e . +``` + # Changelog +## 0.1.5 +- Migrate build system to Meson. + + ## 0.1.4 - Modernize Python metadata, require Python >= 3.8. diff --git a/meson.build b/meson.build new file mode 100644 index 0000000..c0176b5 --- /dev/null +++ b/meson.build @@ -0,0 +1,34 @@ +project( + 'memory_allocator', + 'c', 'cython', + meson_version: '>=1.2.0', +) +# Python +py_module = import('python') +py = py_module.find_installation(pure: false) +py_dep = py.dependency() + +py.install_sources( + 'memory_allocator/__init__.py', + 'memory_allocator/__init__.pxd', + 'memory_allocator/memory_allocator.pxd', + 'memory_allocator/memory.pxd', + 'memory_allocator/signals.pxd', + subdir: 'memory_allocator', +) + +extensions = { + 'memory_allocator': files('memory_allocator/memory_allocator.pyx'), + 'test': files('memory_allocator/test.pyx'), +} + +src = include_directories('memory_allocator') +foreach name, pyx : extensions + py.extension_module(name, + pyx, + include_directories: [src], + dependencies: [py_dep], + install: true, + subdir: 'memory_allocator' + ) +endforeach diff --git a/pyproject.toml b/pyproject.toml index f075564..6e5ed97 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,20 +1,13 @@ [build-system] -requires = [ - "setuptools>=61.2", - "Cython", - "Cython>=0.29.30; python_version > '3.10'" -] -build-backend = "setuptools.build_meta" +requires = ["meson-python>=0.15.0", "Cython>=3.0"] +build-backend = "mesonpy" [project] name = "memory_allocator" version = "0.1.4" description = "An extension class to allocate memory easily with cython" authors = [ - {name = "Jeroen Demeyer, Nathann Cohen, Jonathan Kliem", email = "sage-devel@googlegroups.com"}, -] -dependencies = [ - "Cython", + { name = "Jeroen Demeyer, Nathann Cohen, Jonathan Kliem", email = "sage-devel@googlegroups.com" }, ] requires-python = ">=3.11" readme = "README.md" diff --git a/setup.py b/setup.py deleted file mode 100644 index 263497c..0000000 --- a/setup.py +++ /dev/null @@ -1,28 +0,0 @@ -from setuptools import setup, find_packages -from setuptools.extension import Extension -from distutils.command.build_ext import build_ext as du_build_ext - - -class build_ext(du_build_ext): - def run(self): - from Cython.Build.Dependencies import cythonize - self.distribution.ext_modules[:] = cythonize( - self.distribution.ext_modules, - language_level=3) - du_build_ext.run(self) - - -extensions = [ - Extension( - "memory_allocator.memory_allocator", - sources=["memory_allocator/memory_allocator.pyx"]), - Extension( - "memory_allocator.test", - sources=["memory_allocator/test.pyx"]), -] - - -setup( - packages=find_packages(), - ext_modules=extensions, -) From 2deaf4dbb0d20eff8b029927f6f76fc65c785d9e Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Mon, 22 Dec 2025 12:06:25 +0100 Subject: [PATCH 2/3] Migrate to src layout --- meson.build | 16 ++++++++-------- .../memory_allocator}/__init__.pxd | 0 .../memory_allocator}/__init__.py | 0 .../memory_allocator}/memory.pxd | 0 .../memory_allocator}/memory_allocator.pxd | 0 .../memory_allocator}/memory_allocator.pyx | 0 .../memory_allocator}/signals.pxd | 0 .../memory_allocator}/test.pyx | 0 8 files changed, 8 insertions(+), 8 deletions(-) rename {memory_allocator => src/memory_allocator}/__init__.pxd (100%) rename {memory_allocator => src/memory_allocator}/__init__.py (100%) rename {memory_allocator => src/memory_allocator}/memory.pxd (100%) rename {memory_allocator => src/memory_allocator}/memory_allocator.pxd (100%) rename {memory_allocator => src/memory_allocator}/memory_allocator.pyx (100%) rename {memory_allocator => src/memory_allocator}/signals.pxd (100%) rename {memory_allocator => src/memory_allocator}/test.pyx (100%) diff --git a/meson.build b/meson.build index c0176b5..be5d494 100644 --- a/meson.build +++ b/meson.build @@ -9,20 +9,20 @@ py = py_module.find_installation(pure: false) py_dep = py.dependency() py.install_sources( - 'memory_allocator/__init__.py', - 'memory_allocator/__init__.pxd', - 'memory_allocator/memory_allocator.pxd', - 'memory_allocator/memory.pxd', - 'memory_allocator/signals.pxd', + 'src/memory_allocator/__init__.py', + 'src/memory_allocator/__init__.pxd', + 'src/memory_allocator/memory_allocator.pxd', + 'src/memory_allocator/memory.pxd', + 'src/memory_allocator/signals.pxd', subdir: 'memory_allocator', ) extensions = { - 'memory_allocator': files('memory_allocator/memory_allocator.pyx'), - 'test': files('memory_allocator/test.pyx'), + 'memory_allocator': files('src/memory_allocator/memory_allocator.pyx'), + 'test': files('src/memory_allocator/test.pyx'), } -src = include_directories('memory_allocator') +src = include_directories('src/memory_allocator') foreach name, pyx : extensions py.extension_module(name, pyx, diff --git a/memory_allocator/__init__.pxd b/src/memory_allocator/__init__.pxd similarity index 100% rename from memory_allocator/__init__.pxd rename to src/memory_allocator/__init__.pxd diff --git a/memory_allocator/__init__.py b/src/memory_allocator/__init__.py similarity index 100% rename from memory_allocator/__init__.py rename to src/memory_allocator/__init__.py diff --git a/memory_allocator/memory.pxd b/src/memory_allocator/memory.pxd similarity index 100% rename from memory_allocator/memory.pxd rename to src/memory_allocator/memory.pxd diff --git a/memory_allocator/memory_allocator.pxd b/src/memory_allocator/memory_allocator.pxd similarity index 100% rename from memory_allocator/memory_allocator.pxd rename to src/memory_allocator/memory_allocator.pxd diff --git a/memory_allocator/memory_allocator.pyx b/src/memory_allocator/memory_allocator.pyx similarity index 100% rename from memory_allocator/memory_allocator.pyx rename to src/memory_allocator/memory_allocator.pyx diff --git a/memory_allocator/signals.pxd b/src/memory_allocator/signals.pxd similarity index 100% rename from memory_allocator/signals.pxd rename to src/memory_allocator/signals.pxd diff --git a/memory_allocator/test.pyx b/src/memory_allocator/test.pyx similarity index 100% rename from memory_allocator/test.pyx rename to src/memory_allocator/test.pyx From fa4111e6d819bb90e7a3cb6ffe6b823e2df7fc0c Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Mon, 22 Dec 2025 12:16:14 +0100 Subject: [PATCH 3/3] Remove 32-bit tests Meson randomly tries to select the 64-bit Python, which then breaks the compilation. Probably fixable (see eg https://github.com/mesonbuild/meson-python/issues/610) but not really worth the effort as 32-bit Windows is anyway quite outdated. --- .github/workflows/main.yml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6f1b649..3aa2103 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,23 +18,16 @@ jobs: matrix: os: [ubuntu-latest, macos-latest, windows-latest] python-version: ['3.12', '3.13', '3.14'] - architecture: [x64, x86] - exclude: - - os: ubuntu-latest - architecture: x86 - - os: macos-latest - architecture: x86 steps: - name: Set up the repository uses: actions/checkout@v4 with: submodules: recursive fetch-depth: 0 - - name: Set up Python ${{ matrix.python-version }} + - name: Set up Python uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - architecture: ${{ matrix.architecture }} - name: Build run: | python -m pip install --upgrade pip