Skip to content

Commit

Permalink
manylinux build PEP600
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Kraft committed Dec 17, 2021
1 parent 566bbbc commit 5c7380d
Show file tree
Hide file tree
Showing 8 changed files with 243 additions and 155 deletions.
3 changes: 1 addition & 2 deletions cmf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
from .timetools import StopWatch, datetime_to_cmf, timerange


__version__ = '2.0.0b5'
__compiletime__ = 'Mon Aug 30 17:45:30 2021'
__version__ = '2.0.0b6'

from .cmf_core import connect_cells_with_flux as __ccwf

Expand Down
2 changes: 1 addition & 1 deletion cmf/cmf_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,6 @@ def __format__(self, fmt):

# Register Time in _cmf_core:
_cmf_core.Time_swigregister(Time)
__compiledate__ = cvar.__compiledate__
Pi = cvar.Pi

class Date(object):
Expand Down Expand Up @@ -2012,6 +2011,7 @@ def __init__(self, *args):
global_water_balance = _swig_new_instance_method(_cmf_core.node_list_global_water_balance)
water_balance = _swig_new_instance_method(_cmf_core.node_list_water_balance)
conc = _swig_new_instance_method(_cmf_core.node_list_conc)
set_solute_source = _swig_new_instance_method(_cmf_core.node_list_set_solute_source)
get_fluxes_to = _swig_new_instance_method(_cmf_core.node_list_get_fluxes_to)
get_fluxes3d_to = _swig_new_instance_method(_cmf_core.node_list_get_fluxes3d_to)
get_fluxes3d = _swig_new_instance_method(_cmf_core.node_list_get_fluxes3d)
Expand Down
262 changes: 161 additions & 101 deletions cmf/cmf_core_src/cmf_wrap.cpp

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion cmf/cmf_core_src/math/real.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ typedef double real;
const real REAL_MAX = std::numeric_limits<real>::max();
#endif

const std::string __compiledate__ = std::string("cmf compiled ") + std::string(__DATE__) + " - " + std::string(__TIME__);

// Some helper functions
/// Returns the minimum of two values
Expand Down
76 changes: 28 additions & 48 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,6 @@
from distutils.command.build_py import build_py
import logging
logging.basicConfig(level=logging.DEBUG)
version = '2.0.0b5'

branchversion = version
try:
from pygit2 import Repository
head = Repository('.').head.shorthand
if head != 'master':
branchversion = version + '.' + head
except:
Repository = None

print('cmf', branchversion)



swig = False
openmp = False
Expand All @@ -63,7 +49,7 @@ def __init__(self, includepath, libpath, *libs, build_script=None, build_always=
self.build_always = build_always

def __repr__(self):
return self.libs[0] + ' - library'
return self.libs[0] + '-library'

def as_win32(self):
checked_libs = []
Expand All @@ -77,19 +63,27 @@ def as_win32(self):
return [self.libpath], reversed(checked_libs), []

def as_posix(self):
# Move static libraries to extra_objects (with path) to ensure static linking in posix systems
if os.path.exists(self.libpath):
libpath = self.libpath
elif os.path.exists(self.libpath + '64'):
libpath = self.libpath + '64'
else:
raise FileNotFoundError("Can't find static library directory" + self.libpath)
def get_posix_path_to_lib(libname):
def lib_to_path(libpath, libname):
p = libpath + '/' + f'lib{libname}.a'
if os.path.exists(p):
return p
else:
return None

def raise_if_none(path_to_lib):
if path_to_lib:
return path_to_lib
else:
raise FileNotFoundError(f"Can't find static library {libname} in {self.libpath}[64]")

return raise_if_none(
lib_to_path(self.libpath, libname) or
lib_to_path(self.libpath + '64', libname)
)

libfiles = ['{}/lib{}.a'.format(libpath, l) for l in self.libs]
for lf in libfiles:
if not os.path.exists(lf):
raise FileNotFoundError("Can't find static library " + lf)
return [], [], libfiles
# Move static libraries to extra_objects (with path) to ensure static linking in posix systems
return [], [], [get_posix_path_to_lib(l) for l in self.libs]

def exists(self):
try:
Expand Down Expand Up @@ -255,20 +249,9 @@ def updateversion():
Doxyfile: set PROJECT_NUMBER
"""
logging.debug('updateversion()')

try:
module_code = open('cmf/__init__.py').readlines()
except IOError:
pass
else:
fout = open('cmf/__init__.py', 'w')
for line in module_code:
if line.startswith('__version__'):
fout.write("__version__ = '{}'\n".format(branchversion))
elif line.startswith('__compiletime__'):
fout.write("__compiletime__ = '{}'\n".format(time.ctime()))
else:
fout.write(line)
with open('cmf/__init__.py') as initfile:
t = initfile.read()
version = re.search('__version__ ?= ?\'(.*?)\'', t).group(1)
try:
doxycode = open('tools/Doxyfile').readlines()
except IOError:
Expand All @@ -280,7 +263,7 @@ def updateversion():
fout.write("PROJECT_NUMBER = {}\n".format(version))
else:
fout.write(line)

return version

def pop_arg(arg):
"""
Expand Down Expand Up @@ -394,14 +377,11 @@ def make_cmf_core():

# Get the source files
cmf_files = [] # get_source_files()
if not any('cmf_core' in sl.libs for sl in static_libraries):
print('search source files')
cmf_files += get_source_files()

if swig:
# Adding cmf.i when build_ext should perform the swig call
cmf_files.append("cmf/cmf_core_src/cmf.i")
swig_opts = ['-c++', '-w512', '-w511', '-O', '-keyword', '-castmode', '-modern']
swig_opts = ['-c++', '-w512', '-w511', '-O', '-keyword', '-castmode']

else:
# Else use what we have there
Expand All @@ -422,7 +402,7 @@ def make_cmf_core():


if __name__ == '__main__':
updateversion()
version = updateversion()
openmp = not pop_arg('noopenmp')
swig = pop_arg('swig')
debug = not pop_arg('nodebug')
Expand All @@ -448,7 +428,7 @@ def make_cmf_core():
ext_modules=ext,
packages=['cmf', 'cmf.draw', 'cmf.geometry'],
python_requires='>=3.7',
install_requires='numpy>=1.11.1',
install_requires=['numpy>=1.11.1', 'cmake>3.1.0'],
keywords='hydrology catchment simulation toolbox',
author='Philipp Kraft',
author_email="philipp.kraft@umwelt.uni-giessen.de",
Expand Down
2 changes: 1 addition & 1 deletion tools/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = cmf
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 2.0.0b5
PROJECT_NUMBER = 2.0.0b6

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
50 changes: 50 additions & 0 deletions tools/docker-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash

# This file should be used in a manylinux container to build several binaries
set -e -u -x

function repair_wheel {
wheel="$1"
if ! auditwheel show "$wheel"; then
echo "Skipping non-platform wheel $wheel"
else
auditwheel repair "$wheel" --plat "$PLAT" -w /io/wheelhouse/
fi
}


export CFLAGS="-fPIC"
export CXXFLAGS="-fPIC"
CMFDIR=/io/cmf
TOOLDIR=$CMFDIR/tools

# Install solvers
SOLVERBUILDDIR=$CMFDIR/build/extern
rm -rf $SOLVERBUILDDIR
cmake -S ${TOOLDIR} -B ${SOLVERBUILDDIR} -DCMAKE_BUILD_TYPE=Release
make -C ${SOLVERBUILDDIR}

# build cmf_core
CMFBUILDDIR=$CMFDIR/build/cmf_core
rm -rf $CMFBUILDDIR
CMFSOURCEDIR=$CMFDIR/cmf/cmf_core_src
cmake -S $CMFSOURCEDIR -B $CMFBUILDDIR -DCMAKE_BUILD_TYPE=Release
make -C $CMFBUILDDIR
make install -C $CMFBUILDDIR

# Compile wheels
for PYBIN in /opt/python/*/bin; do
"${PYBIN}/pip" install -r $CMFDIR/requirements.txt
"${PYBIN}/python" bdist_wheel
done

# Bundle external shared libraries into the wheels
for whl in dist/*.whl; do
repair_wheel "$whl"
done

# Install packages and test
for PYBIN in /opt/python/*/bin/; do
"${PYBIN}/pip" install python-manylinux-demo --no-index -f /io/wheelhouse
(cd "$HOME"; "${PYBIN}/nosetests" pymanylinuxdemo)
done
2 changes: 1 addition & 1 deletion tools/install_solvers.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
export CLAGS="-fPIC"
export CFLAGS="-fPIC"
export CXXFLAGS="-fPIC"

CWD=$PWD
Expand Down

0 comments on commit 5c7380d

Please sign in to comment.