Skip to content

Commit

Permalink
Remove py2 (#185)
Browse files Browse the repository at this point in the history
* cylp/*/CyClpSimplex_api.h: Remove Python 2 support
* setup.py: Remove Python 2 support
  • Loading branch information
mkoeppe authored Oct 21, 2023
1 parent c152a78 commit 036f0f1
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 55 deletions.
20 changes: 0 additions & 20 deletions cylp/cpp/CyClpSimplex_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ static PyObject *__Pyx_ImportModule(const char *name) {
PyObject *py_name = 0;
PyObject *py_module = 0;

#if PY_MAJOR_VERSION < 3
py_name = PyString_FromString(name);
#else
py_name = PyUnicode_FromString(name);
#endif
if (!py_name)
goto bad;
py_module = PyImport_Import(py_name);
Expand Down Expand Up @@ -49,29 +45,13 @@ static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**
PyModule_GetName(module), funcname);
goto bad;
}
#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0)
if (!PyCapsule_IsValid(cobj, sig)) {
PyErr_Format(PyExc_TypeError,
"C function %s.%s has wrong signature (expected %s, got %s)",
PyModule_GetName(module), funcname, sig, PyCapsule_GetName(cobj));
goto bad;
}
tmp.p = PyCapsule_GetPointer(cobj, sig);
#else
{const char *desc, *s1, *s2;
desc = (const char *)PyCObject_GetDesc(cobj);
if (!desc)
goto bad;
s1 = desc; s2 = sig;
while (*s1 != '\0' && *s1 == *s2) { s1++; s2++; }
if (*s1 != *s2) {
PyErr_Format(PyExc_TypeError,
"C function %s.%s has wrong signature (expected %s, got %s)",
PyModule_GetName(module), funcname, sig, desc);
goto bad;
}
tmp.p = PyCObject_AsVoidPtr(cobj);}
#endif
*f = tmp.fp;
if (!(*f))
goto bad;
Expand Down
20 changes: 0 additions & 20 deletions cylp/cy/CyClpSimplex_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ static PyObject *__Pyx_ImportModule(const char *name) {
PyObject *py_name = 0;
PyObject *py_module = 0;

#if PY_MAJOR_VERSION < 3
py_name = PyString_FromString(name);
#else
py_name = PyUnicode_FromString(name);
#endif
if (!py_name)
goto bad;
py_module = PyImport_Import(py_name);
Expand Down Expand Up @@ -49,29 +45,13 @@ static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**
PyModule_GetName(module), funcname);
goto bad;
}
#if PY_VERSION_HEX >= 0x02070000 && !(PY_MAJOR_VERSION==3&&PY_MINOR_VERSION==0)
if (!PyCapsule_IsValid(cobj, sig)) {
PyErr_Format(PyExc_TypeError,
"C function %s.%s has wrong signature (expected %s, got %s)",
PyModule_GetName(module), funcname, sig, PyCapsule_GetName(cobj));
goto bad;
}
tmp.p = PyCapsule_GetPointer(cobj, sig);
#else
{const char *desc, *s1, *s2;
desc = (const char *)PyCObject_GetDesc(cobj);
if (!desc)
goto bad;
s1 = desc; s2 = sig;
while (*s1 != '\0' && *s1 == *s2) { s1++; s2++; }
if (*s1 != *s2) {
PyErr_Format(PyExc_TypeError,
"C function %s.%s has wrong signature (expected %s, got %s)",
PyModule_GetName(module), funcname, sig, desc);
goto bad;
}
tmp.p = PyCObject_AsVoidPtr(cobj);}
#endif
*f = tmp.fp;
if (!(*f))
goto bad;
Expand Down
17 changes: 2 additions & 15 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,10 @@
import platform
from os.path import join, abspath, dirname
import numpy
import unicodedata
from subprocess import check_output

#A unicode function that is compatible with Python 2 and 3
u = lambda s: s if sys.version_info[0] > 2 else unicode(s, 'utf-8')
myopen = lambda s: open(s) if sys.version_info[0] == 2 else open(s, encoding="utf-8")

from setuptools import setup
from setuptools import Extension
from setuptools.command.install import install

def getBdistFriendlyString(s):
'''
Solve the issue with restructuredText README
"ordinal not in range error" when using bdist_mpkg or bdist_wininst
'''
return unicodedata.normalize('NFKD', u(s))

VERSION = open(join('cylp', 'VERSION')).read().strip()

Expand Down Expand Up @@ -404,8 +391,8 @@ def getBdistFriendlyString(s):
extra_link_args=extra_link_args), ]


s_README = getBdistFriendlyString(myopen('README.rst').read())
s_AUTHORS = u(open('AUTHORS').read())
s_README = open('README.rst').read()
s_AUTHORS = open('AUTHORS').read()

extra_files = ['cpp/*.hpp', 'cpp/*.h', 'cy/*.pxd', 'VERSION']

Expand Down

0 comments on commit 036f0f1

Please sign in to comment.