Skip to content

Commit

Permalink
Allow to build without distutils
Browse files Browse the repository at this point in the history
  • Loading branch information
jschueller committed May 19, 2024
1 parent 45b1d7e commit 9055e15
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,21 @@
import sys
import os
import shutil
from subprocess import Popen, PIPE
import ctypes.util
import argparse
from os.path import isfile, join
import numpy as np
import numpy.distutils.core as ndc
try:
from numpy.distutils.core import setup
import numpy.distutils as nd
have_nd = True
from numpy.distutils.fcompiler import intel
except ImportError:
from setuptools import setup
have_nd = False
import Cython
from Cython.Build import cythonize

def str2bool(v):
return v.lower() in ("yes", "true", "t", "1")
Expand Down Expand Up @@ -63,7 +73,6 @@ def remove_prefix(name, prefix):
logging.basicConfig(level=getattr(logging,args[0].log),format='%(levelname)s:%(message)s',filename=args[0].log_file)
logging.debug('setup.py called with the following optional args\n %s\n argument parsing completed.',vars(args[0]))
try:
from subprocess import Popen, PIPE
_p = Popen(["svnversion", "."], stdout=PIPE)
revision = _p.communicate()[0].decode('ascii')
except Exception:
Expand All @@ -72,20 +81,10 @@ def remove_prefix(name, prefix):

#If prefix is set, we want to allow installation in a directory that is not on PYTHONPATH
#and this is only possible with distutils, not setuptools
if not args[0].prefix:
import setuptools
import numpy.distutils as nd

try:
from Cython.Distutils import build_ext
from Cython.Build import cythonize
except ImportError:
msg="Please upgrade to a newer Cython version, >= 3"
logging.error(msg)
raise Exception(msg)
if args[0].prefix is not None and not have_nd:
raise ValueError("Cannot handle prefix argument without distutils")

#Verify Cython version
import Cython
cython_version = Cython.__version__.split(".")
if not cython_version[0] >= '3':
msg="Please upgrade to a newer Cython version, >= 3"
Expand Down Expand Up @@ -148,20 +147,20 @@ def __init__(self,args, thirdparty_methods):
self.sundials_with_msvc = False
self.msvcSLU = False

if self.no_mvscr:
if self.no_mvscr and have_nd:
# prevent the MSVCR* being added to the DLLs passed to the linker
def msvc_runtime_library_mod():
return None
nd.misc_util.msvc_runtime_library = msvc_runtime_library_mod
logging.debug('numpy.distutils.misc_util.msvc_runtime_library overwritten.')
# prevent Fortran to link dynamically
# Are there any additional flags needed for e.g. MKL, see https://software.intel.com/en-us/articles/intel-mkl-link-line-advisor
def fortran_compiler_flags(self):
opt = ['/nologo', '/MT', '/nbs', '/names:lowercase', '/assume:underscore']
return opt
from numpy.distutils.fcompiler import intel
nd.fcompiler.intel.IntelVisualFCompiler.get_flags=fortran_compiler_flags

if have_nd:
# prevent Fortran to link dynamically
# Are there any additional flags needed for e.g. MKL, see https://software.intel.com/en-us/articles/intel-mkl-link-line-advisor
def fortran_compiler_flags(self):
opt = ['/nologo', '/MT', '/nbs', '/names:lowercase', '/assume:underscore']
return opt
nd.fcompiler.intel.IntelVisualFCompiler.get_flags=fortran_compiler_flags

self.platform = 'linux'
if 'win' in sys.platform:
Expand Down Expand Up @@ -486,6 +485,8 @@ def cython_extensionlists(self):
include_path=[".", "assimulo", os.path.join("assimulo", "solvers")],
force = True,
compiler_directives={'language_level' : "3str"},)
for ext in ext_list:
ext.include_dirs += [np.get_include()]

# SUNDIALS
if self.with_SUNDIALS:
Expand Down Expand Up @@ -661,7 +662,8 @@ def fortran_extensionlists(self):
change_dir = False

ext_list = prepare.cython_extensionlists()
ext_list += prepare.fortran_extensionlists()
if have_nd:
ext_list += prepare.fortran_extensionlists()

# distutils part

Expand Down Expand Up @@ -716,7 +718,7 @@ def fortran_extensionlists(self):
for pck in thirdparty_methods for place in ['thirdparty','lib']]
logging.debug(license_info)

ndc.setup(name=NAME,
setup(name=NAME,
version=VERSION,
license=LICENSE,
description=DESCRIPTION,
Expand Down

0 comments on commit 9055e15

Please sign in to comment.