Skip to content

Commit

Permalink
Merge branch 'master' into cython-linting-one
Browse files Browse the repository at this point in the history
  • Loading branch information
fchapoton authored Oct 18, 2023
2 parents 7c4e967 + d212a13 commit 9b86cd1
Show file tree
Hide file tree
Showing 16 changed files with 267 additions and 75 deletions.
101 changes: 93 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,119 @@ on:
tags:
- '*'

concurrency:
# Cancel previous runs of this workflow for the same branch
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: ['3.7', '3.10', '3.11']
pari-version: ['pari-2.9.5', 'pari-2.11.4', 'pari-2.13.0', 'pari-2.15.1']
python-version: ['3.9', '3.10', '3.11', '3.12']
pari-version: ['pari-2.11.4', 'pari-2.13.0', 'pari-2.15.4']
env:
LC_ALL: C
PARI_VERSION: ${{ matrix.pari-version }}
steps:
- name: Set up the repository
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install pari
run: |
ccache -M 256M && ccache -s
export PATH="/usr/lib/ccache:$PATH"
bash -x .install-pari.sh
- name: Local build
run: |
pip install sphinx cython cysignals
make build
make install
make check
pip install sphinx
(cd docs && make html)
dist:
runs-on: ubuntu-latest
steps:
- name: Check out ${{ env.SPKG }}
uses: actions/checkout@v4
with:
path: build/pkgs/${{ env.SPKG }}/src
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
- name: Install prerequisites
run: |
sudo DEBIAN_FRONTEND=noninteractive apt-get update
sudo DEBIAN_FRONTEND=noninteractive apt-get install $DIST_PREREQ
python3 -m pip install build
- name: Run make dist, prepare upstream artifact
run: |
(cd build/pkgs/${{ env.SPKG }}/src && python3 -m build --sdist) \
&& mkdir -p upstream && cp build/pkgs/${{ env.SPKG }}/src/dist/*.tar.gz upstream/${{ env.SPKG }}-git.tar.gz \
&& echo "sage-package create ${{ env.SPKG }} --version git --tarball ${{ env.SPKG }}-git.tar.gz --type=standard" > upstream/update-pkgs.sh \
&& if [ -n "${{ env.REMOVE_PATCHES }}" ]; then echo "(cd ../build/pkgs/${{ env.SPKG }}/patches && rm -f ${{ env.REMOVE_PATCHES }}; :)" >> upstream/update-pkgs.sh; fi \
&& ls -l upstream/
- uses: actions/upload-artifact@v3
with:
path: upstream
name: upstream

linux-sage:
uses: sagemath/sage/.github/workflows/docker.yml@develop
with:
targets: SAGE_CHECK=no SAGE_CHECK_PACKAGES="cypari" cypari
targets_optional: build/make/Makefile
sage_repo: sagemath/sage
sage_ref: develop
upstream_artifact: upstream
# We prefix the image name with the SPKG name ("cypari2-") to avoid the error
# 'Package "sage-docker-..." is already associated with another repository.'
docker_push_repository: ghcr.io/${{ github.repository }}/cypari2-
needs: [dist]

linux-sage-incremental:
uses: sagemath/sage/.github/workflows/docker.yml@develop
with:
# Build incrementally from published Docker image
incremental: true
free_disk_space: true
from_docker_repository: ghcr.io/sagemath/sage/
from_docker_target: "with-targets"
from_docker_tag: "dev"
docker_targets: "with-targets"
targets_pre: build/make/Makefile
targets: "cypari-uninstall build doc-html ptest"
targets_optional: build/make/Makefile
sage_repo: sagemath/sage
sage_ref: develop
upstream_artifact: upstream
# We prefix the image name with the SPKG name ("cypari2-") to avoid the error
# 'Package "sage-docker-..." is already associated with another repository.'
docker_push_repository: ghcr.io/${{ github.repository }}/cypari2-
needs: [linux-sage]

macos-sage:
uses: sagemath/sage/.github/workflows/macos.yml@develop
with:
osversion_xcodeversion_toxenv_tuples: >-
[["latest", "", "homebrew-macos-usrlocal-minimal"],
["latest", "", "homebrew-macos-usrlocal-standard"],
["13", "xcode_15.0", "homebrew-macos-usrlocal-standard"],
["latest", "", "conda-forge-macos-standard"]]
targets: SAGE_CHECK=no SAGE_CHECK_PACKAGES="cypari" cypari
# Standard setting: Test the current beta release of Sage
sage_repo: sagemath/sage
sage_ref: develop
upstream_artifact: upstream
needs: [dist]

env:
# Ubuntu packages to install so that the project's "setup.py sdist" can succeed
DIST_PREREQ: libpari-dev pari-doc
# Name of this project in the Sage distribution
SPKG: cypari
# Remove all downstream patches
REMOVE_PATCHES: "*"
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include LICENSE README.rst VERSION
include Makefile
global-include *.py *.pyx *.pxd *.pxi

recursive-exclude cypari2 auto_*
Expand Down
10 changes: 4 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ PYTHON = python
PIP = $(PYTHON) -m pip -v


build:
$(PYTHON) setup.py build

install:
$(PIP) install --no-index --upgrade .
$(PIP) install --upgrade .

check:
ulimit -s 8192; $(PYTHON) -u tests/rundoctest.py
Expand All @@ -19,7 +16,8 @@ check:

dist:
chmod go+rX-w -R .
umask 0022 && $(PYTHON) setup.py sdist --formats=gztar
$(PIP) install build
umask 0022 && $(PYTHON) -m build --sdist


.PHONY: build install check dist
.PHONY: install check dist
7 changes: 7 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
cypari2 change log
==================

v2.1.4
------

- compatibility with Python 3.12 [`https://github.com/sagemath/cypari2/pull/138`]
- compatibility with Cython 3 [`https://github.com/sagemath/cypari2/pull/139`]
- declare build dependencies in `pyproject.toml` [`https://github.com/sagemath/cypari2/pull/139`]

v2.1.3
------

Expand Down
34 changes: 16 additions & 18 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,23 @@ A Python interface to the number theory library `PARI/GP <http://pari.math.u-bor
Installation
------------

GNU/Linux
^^^^^^^^^
From a distribution package (GNU/Linux, conda-forge)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

A package `python-cypari2` or `python2-cypari2` or `python3-cypari2` might be
available in your package manager.
A package might be available in your package manager, see
https://repology.org/project/python:cypari2/versions

Using pip
^^^^^^^^^
From source with pip
^^^^^^^^^^^^^^^^^^^^

Requirements:

- PARI/GP >= 2.9.4 (header files and library)
- 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.6
- pip
- `cysignals <https://pypi.python.org/pypi/cysignals/>`_ >= 1.7
- Cython >= 0.29

Install cypari2 via the Python Package Index (PyPI) via

Expand All @@ -34,10 +35,13 @@ Install cypari2 via the Python Package Index (PyPI) via
$ pip install cypari2 [--user]

(the optional option *--user* allows to install cypari2 for a single user
and avoids using pip with administrator rights). Depending on your operating
system the pip command might also be called pip3.
and avoids using pip with administrator rights).

If you want to try the development version use
`pip` builds the package using build isolation. All Python build dependencies
of the package, declared in pyproject.toml, are automatically installed in
a temporary virtual environment.

If you want to try the development version, use

::

Expand All @@ -51,12 +55,6 @@ already installed, try to reinstall cysignals and cypari2
$ pip install cysignals --upgrade [--user]
$ pip install cypari2 --upgrade [--user]

Other
^^^^^

Any other way to install cypari2 is not supported. In particular, ``python
setup.py install`` will produce an error.

Usage
-----

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.3
2.1.4
2 changes: 2 additions & 0 deletions _custom_build_meta.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# See https://setuptools.pypa.io/en/latest/build_meta.html#dynamic-build-dependencies-and-other-build-meta-tweaks
from setuptools.build_meta import *
7 changes: 4 additions & 3 deletions autogen/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
from __future__ import absolute_import, unicode_literals

import os
import shutil

from glob import glob
from distutils.spawn import find_executable


# find_executable() returns None if nothing was found
gppath = find_executable("gp")
gppath = shutil.which("gp")

if gppath is None:
# This almost certainly won't work, but we need to put something here
prefix = "."
Expand Down
8 changes: 0 additions & 8 deletions cypari2/Py_SET_SIZE.h

This file was deleted.

27 changes: 9 additions & 18 deletions cypari2/convert.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,8 @@ from libc.math cimport INFINITY
from .paridecl cimport *
from .stack cimport new_gen, reset_avma
from .string_utils cimport to_string, to_bytes

cdef extern from *:
ctypedef struct PyLongObject:
digit* ob_digit

cdef extern from "Py_SET_SIZE.h":
void Py_SET_SIZE(py_long o, Py_ssize_t size)

from .pycore_long cimport (ob_digit, _PyLong_IsZero, _PyLong_IsNegative,
_PyLong_IsPositive, _PyLong_DigitCount, _PyLong_SetSignAndDigitCount)

########################################################################
# Conversion PARI -> Python
Expand Down Expand Up @@ -424,7 +418,7 @@ cdef PyLong_FromINT(GEN g):
cdef Py_ssize_t sizedigits_final = 0

cdef py_long x = _PyLong_New(sizedigits)
cdef digit* D = x.ob_digit
cdef digit* D = ob_digit(x)

cdef digit d
cdef ulong w
Expand Down Expand Up @@ -452,10 +446,7 @@ cdef PyLong_FromINT(GEN g):
sizedigits_final = i+1

# Set correct size
if signe(g) > 0:
Py_SET_SIZE(x, sizedigits_final)
else:
Py_SET_SIZE(x, -sizedigits_final)
_PyLong_SetSignAndDigitCount(x, signe(g), sizedigits_final)

return x

Expand All @@ -465,18 +456,18 @@ cdef PyLong_FromINT(GEN g):
########################################################################

cdef GEN PyLong_AS_GEN(py_long x):
cdef const digit* D = x.ob_digit
cdef const digit* D = ob_digit(x)

# Size of the input
cdef size_t sizedigits
cdef long sgn
if Py_SIZE(x) == 0:
if _PyLong_IsZero(x):
return gen_0
elif Py_SIZE(x) > 0:
sizedigits = Py_SIZE(x)
elif _PyLong_IsPositive(x):
sizedigits = _PyLong_DigitCount(x)
sgn = evalsigne(1)
else:
sizedigits = -Py_SIZE(x)
sizedigits = _PyLong_DigitCount(x)
sgn = evalsigne(-1)

# Size of the output, in bits and in words
Expand Down
2 changes: 1 addition & 1 deletion cypari2/gen.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ cdef class Gen(Gen_base):
>>> pari = Pari()
>>> L = pari("vector(10,i,i^2)")
>>> L.__iter__()
<generator object at ...>
<...generator object at ...>
>>> [x for x in L]
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
>>> list(L)
Expand Down
Loading

0 comments on commit 9b86cd1

Please sign in to comment.