Skip to content

Migrate from setuptools to meson-python build backend #182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ jobs:
needs: [dist]

env:
# Ubuntu packages to install so that the project's "setup.py sdist" can succeed
# Ubuntu packages to install so that building the sdist can succeed
DIST_PREREQ: libpari-dev pari-doc libbz2-dev bzip2
# Name of this project in the Sage distribution
SPKG: cypari
Expand Down
9 changes: 0 additions & 9 deletions MANIFEST.in

This file was deleted.

22 changes: 15 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,10 @@ From source with pip

Requirements:

- PARI/GP >= 2.9.4 (header files and library); see
PARI/GP >= 2.9.4 (header files and library); see
https://doc.sagemath.org/html/en/reference/spkg/pari#spkg-pari
for availability in distributions (GNU/Linux, conda-forge, Homebrew, FreeBSD),
or install from source.
- Python >= 3.9
- pip
- `cysignals <https://pypi.python.org/pypi/cysignals/>`_ >= 1.11.3
- Cython >= 3.0

Install cypari2 via the Python Package Index (PyPI) via

Expand Down Expand Up @@ -139,10 +135,22 @@ same computations be done via
The complete documentation of cypari2 is available at http://cypari2.readthedocs.io and
the PARI/GP documentation at http://pari.math.u-bordeaux.fr/doc.html

Contributing
------------
Contributing & Development
--------------------------

CyPari 2 is maintained by the SageMath community.

Open issues or submit pull requests at https://github.com/sagemath/cypari2
and join https://groups.google.com/group/sage-devel to discuss.

To get started with development, you can set up an environment using Conda
as follows:

::
$ conda create -n cypari2-dev python cython pari=*=*_pthread ninja meson-python cysignals c-compiler
$ conda activate cypari2-dev

Afterwards, you can build and install the package in editable mode:

::
$ pip install -e . --no-build-isolation
2 changes: 0 additions & 2 deletions _custom_build_meta.py

This file was deleted.

4 changes: 2 additions & 2 deletions cypari2/gen.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1789,9 +1789,9 @@ cdef class Gen(Gen_base):
while sp[0] == c'0':
sp = sp + 1
sp -= 1
sp[0] = 'x'
sp[0] = c'x'
sp -= 1
sp[0] = '0'
sp[0] = c'0'
if signe(x) < 0:
sp -= 1
sp[0] = c'-'
Expand Down
44 changes: 44 additions & 0 deletions cypari2/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
py.install_sources(
'__init__.py',
'closure.pxd',
'convert.pxd',
'gen.pxd',
'handle_error.pxd',
'pari_instance.pxd',
'paridecl.pxd',
'paripriv.pxd',
'pycore_long.pxd',
'stack.pxd',
'string_utils.pxd',
'types.pxd',
'cypari.h',
'pycore_long.h',
'auto_paridecl.pxd',
'auto_gen.pxi',
'auto_instance.pxi',
subdir: 'cypari2'
)


extension_data = {
'closure': files('closure.pyx'),
'stack': files('stack.pyx'),
'custom_block': files('custom_block.pyx'),
'convert': files('convert.pyx'),
'string_utils': files('string_utils.pyx'),
'handle_error': files('handle_error.pyx'),
'gen': files('gen.pyx'),
'pari_instance': files('pari_instance.pyx')
}

foreach name, pyx : extension_data
py.extension_module(
name,
sources: pyx,
subdir: 'cypari2',
install: true,
#include_directories: [inc_dirs, 'cypari2'],
dependencies: [cysignals, pari],
)
endforeach

53 changes: 53 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
project('cypari2',
['c', 'cython'],
version: files('VERSION'),
license: 'GPL v3',
default_options: ['c_std=c17', 'cpp_std=c++17', 'python.install_env=auto'],
meson_version: '>=1.2',
)

# Python module
# https://mesonbuild.com/Python-module.html
py = import('python').find_installation(pure: false)

# Compilers
cc = meson.get_compiler('c')
cython = meson.get_compiler('cython')
# Workaround as described in https://cython.readthedocs.io/en/latest/src/userguide/special_methods.html#arithmetic-methods
add_project_arguments('-X c_api_binop_methods=True', language: 'cython')

# Dependencies
inc_cysignals = run_command(
py,
[
'-c',
'''
from os.path import relpath
import cysignals
path = cysignals.__file__.replace('__init__.py', '')
try:
print(relpath(path))
except Exception:
print(path)
'''.strip(),
],
check: true,
).stdout().strip()
cysignals = declare_dependency(include_directories: inc_cysignals)
# Cannot be found via pkg-config
pari = cc.find_library('pari', required: true)

# Run code generation step
code_gen_result = run_command(
py.full_path(), '-c',
'''
import sys
sys.path.insert(0, ".")
from autogen import rebuild
rebuild(force=True)
print("Code generation successful")
''',
check: true
)

subdir('cypari2')
28 changes: 7 additions & 21 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,36 +1,22 @@
[build-system]
requires = [
"setuptools",
"Cython>=3.0",
"cysignals>=1.11.3",
]
# We need access to the autogen package at build time.
# Hence we declare a custom build backend.
build-backend = "_custom_build_meta" # just re-exports setuptools.build_meta definitions
backend-path = ["."]
requires = ["meson-python>=0.15.0", "cython>=3.0", "cysignals>=1.11.3"]
build-backend = "mesonpy"

[project]
name = "cypari2"
description = "A Python interface to the number theory library PARI/GP"
authors = [
{name = "Luca De Feo, Vincent Delecroix, Jeroen Demeyer, Vincent Klein"},
{ name = "Luca De Feo, Vincent Delecroix, Jeroen Demeyer, Vincent Klein" },
]
maintainers = [
{name = "SageMath developers", email = "[email protected]"},
]
dependencies = [
"cysignals>=1.11.3",
{ name = "SageMath developers", email = "[email protected]" },
]
dependencies = ["cysignals>=1.11.3"]
requires-python = ">=3.9"
readme = "README.rst"
license = {text = "GNU General Public License, version 2 or later"}
license = { text = "GNU General Public License, version 2 or later" }
keywords = ["PARI/GP number theory"]
dynamic = [
"version",
]
dynamic = ["version"]

[project.urls]
Homepage = "https://github.com/sagemath/cypari2"

[tool.setuptools.dynamic]
version = {file = "VERSION"}
67 changes: 0 additions & 67 deletions setup.py

This file was deleted.

Loading