Skip to content

Commit 74caf29

Browse files
authored
Merge pull request #314 from isuruf/pypy
Fixes for PyPy support
2 parents 9c5c632 + c0681b2 commit 74caf29

File tree

4 files changed

+40
-27
lines changed

4 files changed

+40
-27
lines changed

cmake/FindCython.cmake

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
# This finds the "cython" executable in your PATH, and then in some standard
66
# paths:
7-
SET(CYTHON_BIN cython CACHE STRING "Cython executable name")
7+
8+
find_program(CYTHON_BIN NAMES cython cython3 cython2)
89
SET(CYTHON_FLAGS --cplus --fast-fail)
910

1011
SET(Cython_FOUND FALSE)
@@ -27,21 +28,22 @@ ENDIF (CYTHON_BIN)
2728

2829

2930
IF (Cython_FOUND)
30-
IF (NOT Cython_FIND_QUIETLY)
31-
MESSAGE(STATUS "Found CYTHON: ${CYTHON_BIN}")
32-
ENDIF (NOT Cython_FIND_QUIETLY)
31+
IF (NOT Cython_FIND_QUIETLY)
32+
MESSAGE(STATUS "Found CYTHON: ${CYTHON_BIN}")
33+
ENDIF (NOT Cython_FIND_QUIETLY)
3334
ELSE (Cython_FOUND)
34-
IF (Cython_FIND_REQUIRED)
35+
IF (Cython_FIND_REQUIRED)
3536
if(Cython_Compilation_Failed)
3637
MESSAGE(STATUS "Found CYTHON: ${CYTHON_BIN}")
37-
# On Win the testing of Cython does not return any accessible value, so the test is not carried out. Fresh Cython install was tested and works.
38-
IF(NOT MSVC)
39-
MESSAGE(FATAL_ERROR "Your Cython version is too old. Please upgrade Cython.")
40-
ENDIF(NOT MSVC)
38+
# On Win the testing of Cython does not return any accessible value, so the test is not carried out.
39+
# Fresh Cython install was tested and works.
40+
IF(NOT MSVC)
41+
MESSAGE(FATAL_ERROR "Your Cython version is too old. Please upgrade Cython.")
42+
ENDIF(NOT MSVC)
4143
else(Cython_Compilation_Failed)
4244
MESSAGE(FATAL_ERROR "Could not find Cython. Please install Cython.")
4345
endif(Cython_Compilation_Failed)
44-
ENDIF (Cython_FIND_REQUIRED)
46+
ENDIF (Cython_FIND_REQUIRED)
4547
ENDIF (Cython_FOUND)
4648

4749

cmake/FindPython.cmake

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,12 @@ set(PYTHON_INSTALL_PATH ${PYTHON_INSTALL_PATH_tmp}
5656
CACHE BOOL "Python install path")
5757
message(STATUS "Python install path: ${PYTHON_INSTALL_PATH}")
5858

59-
if (NOT WIN32)
60-
execute_process(
61-
COMMAND ${PYTHON_BIN} -c "from distutils.sysconfig import get_config_var; print(get_config_var('SOABI'))"
62-
OUTPUT_VARIABLE PYTHON_EXTENSION_SOABI_tmp
63-
)
64-
string(STRIP ${PYTHON_EXTENSION_SOABI_tmp} PYTHON_EXTENSION_SOABI_tmp)
65-
if (NOT "${PYTHON_EXTENSION_SOABI_tmp}" STREQUAL "None")
66-
set(PYTHON_EXTENSION_SOABI_tmp ".${PYTHON_EXTENSION_SOABI_tmp}")
67-
else()
68-
set(PYTHON_EXTENSION_SOABI_tmp "")
69-
endif()
70-
endif()
59+
execute_process(
60+
COMMAND ${PYTHON_BIN} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/get_suffix.py
61+
OUTPUT_VARIABLE PYTHON_EXTENSION_SOABI_tmp
62+
)
63+
string(STRIP ${PYTHON_EXTENSION_SOABI_tmp} PYTHON_EXTENSION_SOABI_tmp)
64+
7165
set(PYTHON_EXTENSION_SOABI ${PYTHON_EXTENSION_SOABI_tmp}
7266
CACHE STRING "Suffix for python extensions")
7367

cmake/get_suffix.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from __future__ import print_function
2+
from distutils.sysconfig import get_config_var
3+
extsuffix = get_config_var('EXT_SUFFIX')
4+
if extsuffix is None:
5+
print("")
6+
else:
7+
print(extsuffix[0:].rsplit(".", 1)[0])

symengine/tests/test_symbol.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from symengine import Symbol, symbols, symarray, has_symbol, Dummy
22
from symengine.utilities import raises
3+
import unittest
4+
import platform
35

46

57
def test_symbol():
@@ -8,9 +10,6 @@ def test_symbol():
810
assert str(x) == "x"
911
assert str(x) != "y"
1012
assert repr(x) == str(x)
11-
# Verify the successful use of slots.
12-
assert not hasattr(x, "__dict__")
13-
assert not hasattr(x, "__weakref__")
1413

1514

1615
def test_symbols():
@@ -163,6 +162,17 @@ def test_dummy():
163162
assert xdummy1 != xdummy2
164163
assert Dummy() != Dummy()
165164
assert Dummy('x') != Dummy('x')
165+
166+
# Cython cdef classes on PyPy has a __dict__ attribute always
167+
# __slots__ on PyPy are useless anyways. https://stackoverflow.com/a/23077685/4768820
168+
@unittest.skipUnless(platform.python_implementation()=="CPython", "__slots__ are useless on PyPy")
169+
def test_slots():
170+
x = Dummy('x')
166171
# Verify the successful use of slots.
167-
assert not hasattr(xdummy1, "__dict__")
168-
assert not hasattr(xdummy1, "__weakref__")
172+
assert not hasattr(x, "__dict__")
173+
assert not hasattr(x, "__weakref__")
174+
175+
x1 = Symbol('x')
176+
# Verify the successful use of slots.
177+
assert not hasattr(x, "__dict__")
178+
assert not hasattr(x, "__weakref__")

0 commit comments

Comments
 (0)