Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to build without distutils #98

Merged
merged 2 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
--- CHANGELOG ---

--- Assimulo-3.5.2 ---
* Allow to build without distutils for Python>=3.12 support

--- Assimulo-3.5.1 ---
* Fixed build with sundials 7.x
* Added "std=legacy" as default fortran compile flag.
Expand Down
60 changes: 26 additions & 34 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,16 @@
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
from numpy.distutils.fcompiler import intel
have_nd = True
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 @@ -62,30 +71,13 @@ 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:
revision = "unknown"
logging.debug('Source from svn revision {}'.format(revision[:-1])) # exclude newline

#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 +140,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
intel.IntelVisualFCompiler.get_flags=fortran_compiler_flags

self.platform = 'linux'
if 'win' in sys.platform:
Expand Down Expand Up @@ -486,6 +478,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 +655,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 @@ -706,17 +701,14 @@ def fortran_extensionlists(self):
"""

version_txt = os.path.join('assimulo', 'version.txt')
if revision == "":
revision = "unknown"
with open(version_txt, 'w') as f:
f.write(VERSION + '\n')
f.write("r" + revision)

license_info=[place+os.sep+pck+os.sep+'LICENSE_{}'.format(pck.upper())
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
Loading