Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
serge-sans-paille committed Oct 14, 2023
1 parent 2dd2bec commit 0fe855f
Show file tree
Hide file tree
Showing 21 changed files with 55 additions and 51 deletions.
2 changes: 1 addition & 1 deletion docs/MANUAL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ Setuptools Integration
Pythran comes with a ``PythranExtension`` class that extends ``setuptools`` and
can be used like this to compile Pythan modules into extension modules::

from distutils.core import setup
from setuptools import setup

# These two lines are required to be able to use pythran in the setup.py
import setuptools
Expand Down
2 changes: 1 addition & 1 deletion omp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def compiler():


# This function and the `msvc_runtime_*` ones below are taken over from
# numpy.distutils
# the legacy numpy.distutils
def get_shared_lib_extension(is_python_ext=False):
"""Return the correct file extension for shared libraries.
Expand Down
17 changes: 9 additions & 8 deletions pythran/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,9 @@ def run():
Dump on stdout the config flags required to compile pythran-generated code.
'''
import argparse
import distutils.ccompiler
import distutils.sysconfig
import setuptools._distutils.ccompiler as ccompiler
from setuptools._distutils.sysconfig import customize_compiler
import sysconfig
import pythran
import numpy

Expand Down Expand Up @@ -346,8 +347,8 @@ def run():
if args.compiler:
output.append(cxx)

compiler_obj = distutils.ccompiler.new_compiler()
distutils.sysconfig.customize_compiler(compiler_obj)
compiler_obj = ccompiler.new_compiler()
customize_compiler(compiler_obj)

if args.cflags or args.verbose >= 2:
def fmt_define(define):
Expand All @@ -364,7 +365,7 @@ def fmt_define(define):
for include in extension['include_dirs'])
if args.python:
cflags.append('-I' + numpy.get_include())
cflags.append('-I' + distutils.sysconfig.get_python_inc())
cflags.append('-I' + sysconfig.get_config_var('INCLUDEPY'))

logger.info('CXXFLAGS = '.rjust(10) + ' '.join(cflags))
if args.cflags:
Expand All @@ -378,14 +379,14 @@ def fmt_define(define):
for include in extension['libraries'])

if args.python:
libpl = distutils.sysconfig.get_config_var('LIBPL')
libpl = sysconfig.get_config_var('LIBPL')
if libpl:
ldflags.append(libpl)
libs = distutils.sysconfig.get_config_var('LIBS')
libs = sysconfig.get_config_var('LIBS')
if libs:
ldflags.extend(shsplit(libs))
ldflags.append(compiler_obj.library_option('python')
+ distutils.sysconfig.get_config_var('VERSION'))
+ sysconfig.get_config_var('VERSION'))

logger.info('LDFLAGS = '.rjust(10) + ' '.join(ldflags))
if args.libs:
Expand Down
18 changes: 9 additions & 9 deletions pythran/dist.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'''
This modules contains a distutils extension mechanism for Pythran
* PythranExtension: is used as distutils's Extension
This modules contains a setuptools extension mechanism for Pythran
* PythranExtension: is used as setuptools's Extension
'''

import pythran.config as cfg
Expand All @@ -13,13 +13,13 @@
import os.path
import os

from distutils.command.build_ext import build_ext as LegacyBuildExt
from distutils.extension import Extension
from setuptools.command.build_ext import build_ext as LegacyBuildExt
from setuptools.extension import Extension



class PythranBuildExtMixIn(object):
"""Subclass of `distutils.command.build_ext.build_ext` which is required to
"""Subclass of `setuptools.command.build_ext.build_ext` which is required to
build `PythranExtension` with the configured C++ compiler. It may also be
subclassed if you want to combine with another build_ext class (NumPy,
Cython implementations).
Expand Down Expand Up @@ -70,7 +70,7 @@ def set_value(obj, key, value):
find_exe = None
if getattr(ext, 'cc', None) is not None:
try:
import distutils._msvccompiler as msvc
import setuptools._distutils._msvccompiler as msvc
# install hook
find_exe = msvc._find_exe

Expand All @@ -83,7 +83,7 @@ def _find_exe(exe, *args, **kwargs):
except ImportError:
pass

# In general, distutils uses -Wstrict-prototypes, but this option
# In general, setuptools uses -Wstrict-prototypes, but this option
# is not valid for C++ code, only for C. Remove it if it's there
# to avoid a spurious warning on every compilation.
for flag in cfg.cfg.get('compiler', "ignoreflags").split():
Expand Down Expand Up @@ -114,7 +114,7 @@ def _find_exe(exe, *args, **kwargs):

# uninstall hook
if find_exe is not None:
import distutils._msvccompiler as msvc
import setuptools._distutils._msvccompiler as msvc
msvc._find_exe = find_exe


Expand All @@ -135,7 +135,7 @@ class PythranExtension(Extension):
'''
Description of a Pythran extension
Similar to distutils.core.Extension except that the sources are .py files
Similar to setuptools.Extension except that the sources are .py files
They must be processable by pythran, of course.
The compilation process ends up in a native Python module.
Expand Down
2 changes: 1 addition & 1 deletion pythran/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import pythran
import pythran.types.tog

from distutils.errors import CompileError
from setuptools.errors import CompileError

logger = logging.getLogger("pythran")

Expand Down
1 change: 0 additions & 1 deletion pythran/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ class TestEnv(unittest.TestCase):

""" Test environment to validate a pythran execution against python. """

module = pytest.mark.module
# default options used for the c++ compiler
PYTHRAN_CXX_FLAGS = ['-O0', '-UNDEBUG', '-U_FORTIFY_SOURCE',
] if sys.platform != "win32" else []
Expand Down
2 changes: 1 addition & 1 deletion pythran/tests/cython/setup_add.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from distutils.core import setup
from setuptools import setup
from Cython.Build import cythonize

setup(
Expand Down
2 changes: 1 addition & 1 deletion pythran/tests/cython/setup_diffuse.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from distutils.core import setup
from setuptools import setup
from Cython.Build import cythonize

setup(
Expand Down
2 changes: 1 addition & 1 deletion pythran/tests/cython/setup_indexing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from distutils.core import setup
from setuptools import setup
from Cython.Build import cythonize

setup(
Expand Down
2 changes: 1 addition & 1 deletion pythran/tests/cython/setup_tax.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from distutils.core import setup
from setuptools import setup
from Cython.Build import cythonize

setup(
Expand Down
4 changes: 2 additions & 2 deletions pythran/tests/test_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# TODO: check http://code.google.com/p/unladen-swallow/wiki/Benchmarks
import os
from distutils.version import LooseVersion
from packaging.version import Version
import numpy
import unittest

Expand All @@ -18,7 +18,7 @@ class TestCases(TestFromDir):

TestCases.populate(TestCases)

if LooseVersion(numpy.__version__) >= '1.20':
if Version(numpy.__version__) >= '1.20':
del TestCases.test_train_equalizer_norun0
del TestCases.test_train_eq_run0
del TestCases.test_train_eq_run1
Expand Down
29 changes: 17 additions & 12 deletions pythran/tests/test_distutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@

cwd = os.path.dirname(__file__)

pythran_dir = os.path.dirname(os.path.dirname(cwd))

os.environ['PYTHONPATH'] = os.pathsep.join((pythran_dir, os.environ.get('PYTHONPATH',
'')))

def _get_implementation():
if sys.implementation.name == 'pypy':
return 'pypy'
Expand Down Expand Up @@ -81,35 +86,35 @@ def test_setup_wheel_install(self):

def test_setup_build2(self):
check_call([python, 'setup.py', 'build'],
cwd=os.path.join(cwd, 'test_distutils_packaged'))
cwd=os.path.join(cwd, 'test_setuptools_packaged'))
check_call([python, '-m', 'pip', 'install', '.', '--prefix=demo_install2'],
cwd=os.path.join(cwd, 'test_distutils_packaged'))
cwd=os.path.join(cwd, 'test_setuptools_packaged'))

base = os.path.join(cwd, 'test_distutils_packaged', 'demo_install2',)
base = os.path.join(cwd, 'test_setuptools_packaged', 'demo_install2',)
libdir = os.path.join(base, 'lib')
if not os.path.isdir(libdir):
libdir = os.path.join(base, 'lib64')
local_env = os.environ.copy()
local_env['PYTHONPATH'] = os.path.join(libdir, python_version, 'site-packages')
check_call([python, '-c', 'import demo2.a'], env=local_env)
check_call([python, 'setup.py', 'clean'],
cwd=os.path.join(cwd, 'test_distutils_packaged'))
shutil.rmtree(os.path.join(cwd, 'test_distutils_packaged', 'demo_install2'))
shutil.rmtree(os.path.join(cwd, 'test_distutils_packaged', 'build'))
cwd=os.path.join(cwd, 'test_setuptools_packaged'))
shutil.rmtree(os.path.join(cwd, 'test_setuptools_packaged', 'demo_install2'))
shutil.rmtree(os.path.join(cwd, 'test_setuptools_packaged', 'build'))

def test_setup_sdist_install2(self):
check_call([python, 'setup.py', 'sdist', "--dist-dir=sdist2"],
cwd=os.path.join(cwd, 'test_distutils_packaged'))
cwd=os.path.join(cwd, 'test_setuptools_packaged'))
check_call(['tar', 'xzf', 'demo2-1.0.tar.gz'],
cwd=os.path.join(cwd, 'test_distutils_packaged', 'sdist2'))
cwd=os.path.join(cwd, 'test_setuptools_packaged', 'sdist2'))
check_call([python, 'setup.py', 'install', '--prefix=demo_install2'],
cwd=os.path.join(cwd, 'test_distutils_packaged', 'sdist2', 'demo2-1.0'))
shutil.rmtree(os.path.join(cwd, 'test_distutils_packaged', 'sdist2'))
cwd=os.path.join(cwd, 'test_setuptools_packaged', 'sdist2', 'demo2-1.0'))
shutil.rmtree(os.path.join(cwd, 'test_setuptools_packaged', 'sdist2'))

def test_setup_bdist_install2(self):
check_call([python, 'setup.py', 'bdist', "--dist-dir=bdist"],
cwd=os.path.join(cwd, 'test_distutils_packaged'))
dist_path = os.path.join(cwd, 'test_distutils_packaged', 'bdist')
cwd=os.path.join(cwd, 'test_setuptools_packaged'))
dist_path = os.path.join(cwd, 'test_setuptools_packaged', 'bdist')
tgz = [f for f in os.listdir(dist_path) if f.endswith(".tar.gz")][0]
check_call(['tar', 'xzf', tgz], cwd=dist_path)

Expand Down
1 change: 0 additions & 1 deletion pythran/tests/test_ndarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from pythran.typing import NDArray, Tuple, List

import numpy
from distutils.version import LooseVersion

import unittest

Expand Down
6 changes: 3 additions & 3 deletions pythran/tests/test_numpy_fft.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from pythran.tests import TestEnv
import numpy
from pythran.typing import NDArray
from distutils.version import LooseVersion
from packaging.version import Version


@TestEnv.module
Expand Down Expand Up @@ -131,15 +131,15 @@ def test_fftn_11b(self):

# Various norms

@unittest.skipIf(LooseVersion(numpy.__version__) <'1.20', "introduced in 1.20")
@unittest.skipIf(Version(numpy.__version__) <'1.20', "introduced in 1.20")
def test_fftn_12(self):
self.run_test("def test_fftn_12(x): from numpy.fft import fftn ; return fftn(x, (6,), norm='backward')",
numpy.arange(0,8), test_fftn_12=[NDArray[int,:]])
def test_fftn_13(self):
self.run_test("def test_fftn_13(x): from numpy.fft import fftn ; return fftn(x, (8,), norm='ortho')",
numpy.arange(0,8.), test_fftn_13=[NDArray[float,:]])

@unittest.skipIf(LooseVersion(numpy.__version__) <'1.20', "introduced in 1.20")
@unittest.skipIf(Version(numpy.__version__) <'1.20', "introduced in 1.20")
def test_fftn_14(self):
self.run_test("def test_fftn_14(x): from numpy.fft import fftn ; return fftn(x, (10,), norm='forward')",
numpy.arange(0, 8.) + 1.j, test_fftn_14=[NDArray[complex,:]])
Expand Down
2 changes: 1 addition & 1 deletion pythran/tests/test_openmp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import unittest
from distutils.errors import CompileError
from setuptools.errors import CompileError
from pythran.tests import TestFromDir
import os
import pythran
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from distutils.core import setup, Extension
from setuptools import setup, Extension
from pythran.dist import PythranExtension, PythranBuildExt

setup(name = 'demo2',
Expand Down
6 changes: 3 additions & 3 deletions pythran/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
from pythran.utils import cxxid
import pythran.frontend as frontend

from distutils.errors import CompileError
from distutils import sysconfig
from distutils.core import setup
from setuptools.errors import CompileError
from setuptools import setup

from tempfile import mkdtemp, NamedTemporaryFile
import gast as ast
import importlib
import logging
import os.path
import shutil
import sysconfig
import glob
import hashlib
from functools import reduce
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ ply>=3.4
gast~=0.5.0
numpy
beniget~=0.4.0
setuptools>=60.10.0
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@
# It appears old versions of setuptools are not supported, see
# https://github.com/serge-sans-paille/pythran/issues/489

from distutils.version import LooseVersion
MinimalSetuptoolsVersion = LooseVersion("12.0.5")
if LooseVersion(setuptools.__version__) < MinimalSetuptoolsVersion:
MinimalSetuptoolsVersionMajor = 13
if int(setuptools.__version__.split('.')[0]) < MinimalSetuptoolsVersionMajor:
msg = "Setuptools version is {}, but must be at least {}".format(
setuptools.__version__,
MinimalSetuptoolsVersion)
Expand Down

0 comments on commit 0fe855f

Please sign in to comment.