reconnect moved files to git repo
This commit is contained in:
@ -0,0 +1,114 @@
|
||||
"""
|
||||
Utilities useful during the build -- adapted from sklearn.
|
||||
"""
|
||||
# author: Andy Mueller, Gael Varoquaux
|
||||
# license: BSD
|
||||
|
||||
from numpy.distutils.system_info import get_info
|
||||
from distutils.version import LooseVersion
|
||||
|
||||
import os
|
||||
import contextlib
|
||||
|
||||
from .pre_build_helpers import basic_check_build
|
||||
|
||||
DEFAULT_ROOT = 'pmdarima'
|
||||
CYTHON_MIN_VERSION = '0.28.5' # 28 since 3.5 uses 28, not 29
|
||||
|
||||
|
||||
def get_blas_info():
|
||||
def atlas_not_found(blas_info_):
|
||||
def_macros = blas_info.get('define_macros', [])
|
||||
for x in def_macros:
|
||||
if x[0] == "NO_ATLAS_INFO":
|
||||
# if x[1] != 1 we should have lapack
|
||||
# how do we do that now?
|
||||
return True
|
||||
if x[0] == "ATLAS_INFO":
|
||||
if "None" in x[1]:
|
||||
# this one turned up on FreeBSD
|
||||
return True
|
||||
return False
|
||||
|
||||
blas_info = get_info('blas_opt', 0)
|
||||
if (not blas_info) or atlas_not_found(blas_info):
|
||||
cblas_libs = ['cblas']
|
||||
blas_info.pop('libraries', None)
|
||||
else:
|
||||
cblas_libs = blas_info.pop('libraries', [])
|
||||
|
||||
return cblas_libs, blas_info
|
||||
|
||||
|
||||
def _check_cython_version():
|
||||
message = 'Please install Cython with a version >= {0} in order ' \
|
||||
'to build a pmdarima distribution from source.' \
|
||||
.format(CYTHON_MIN_VERSION)
|
||||
try:
|
||||
import Cython
|
||||
except ModuleNotFoundError:
|
||||
# Re-raise with more informative error message instead:
|
||||
raise ModuleNotFoundError(message)
|
||||
|
||||
if LooseVersion(Cython.__version__) < CYTHON_MIN_VERSION:
|
||||
message += (' The current version of Cython is {} installed in {}.'
|
||||
.format(Cython.__version__, Cython.__path__))
|
||||
raise ValueError(message)
|
||||
|
||||
|
||||
def cythonize_extensions(top_path, config):
|
||||
"""Check that a recent Cython is available and cythonize extensions"""
|
||||
_check_cython_version()
|
||||
from Cython.Build import cythonize
|
||||
|
||||
# Fast fail before cythonization if compiler fails compiling basic test
|
||||
# code even without OpenMP
|
||||
basic_check_build()
|
||||
|
||||
# check simple compilation with OpenMP. If it fails scikit-learn will be
|
||||
# built without OpenMP and the test test_openmp_supported in the test suite
|
||||
# will fail.
|
||||
# `check_openmp_support` compiles a small test program to see if the
|
||||
# compilers are properly configured to build with OpenMP. This is expensive
|
||||
# and we only want to call this function once.
|
||||
# The result of this check is cached as a private attribute on the sklearn
|
||||
# module (only at build-time) to be used twice:
|
||||
# - First to set the value of SKLEARN_OPENMP_PARALLELISM_ENABLED, the
|
||||
# cython build-time variable passed to the cythonize() call.
|
||||
# - Then in the build_ext subclass defined in the top-level setup.py file
|
||||
# to actually build the compiled extensions with OpenMP flags if needed.
|
||||
|
||||
n_jobs = 1
|
||||
with contextlib.suppress(ImportError):
|
||||
import joblib
|
||||
if LooseVersion(joblib.__version__) > LooseVersion("0.13.0"):
|
||||
# earlier joblib versions don't account for CPU affinity
|
||||
# constraints, and may over-estimate the number of available
|
||||
# CPU particularly in CI (cf loky#114)
|
||||
n_jobs = joblib.cpu_count()
|
||||
|
||||
config.ext_modules = cythonize(
|
||||
config.ext_modules,
|
||||
nthreads=n_jobs,
|
||||
compiler_directives={'language_level': 3})
|
||||
|
||||
|
||||
def gen_from_templates(templates, top_path):
|
||||
"""Generate cython files from a list of templates"""
|
||||
# Lazy import because cython is not a runtime dependency.
|
||||
from Cython import Tempita
|
||||
|
||||
for template in templates:
|
||||
outfile = template.replace('.tp', '')
|
||||
|
||||
# if the template is not updated, no need to output the cython file
|
||||
if not (os.path.exists(outfile) and
|
||||
os.stat(template).st_mtime < os.stat(outfile).st_mtime):
|
||||
|
||||
with open(template, "r") as f:
|
||||
tmpl = f.read()
|
||||
|
||||
tmpl_ = Tempita.sub(tmpl)
|
||||
|
||||
with open(outfile, "w") as f:
|
||||
f.write(tmpl_)
|
||||
Binary file not shown.
Binary file not shown.
@ -0,0 +1,77 @@
|
||||
"""
|
||||
Helpers to check build environment before actual build of pmdarima
|
||||
|
||||
Adapted from: https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/_build_utils/pre_build_helpers.py
|
||||
""" # noqa
|
||||
|
||||
import os
|
||||
import sys
|
||||
import glob
|
||||
import tempfile
|
||||
import textwrap
|
||||
import subprocess
|
||||
|
||||
from distutils.sysconfig import customize_compiler
|
||||
from numpy.distutils.ccompiler import new_compiler
|
||||
|
||||
|
||||
def compile_test_program(code, extra_preargs=[], extra_postargs=[]):
|
||||
"""Check that some C code can be compiled and run"""
|
||||
ccompiler = new_compiler()
|
||||
customize_compiler(ccompiler)
|
||||
|
||||
# extra_(pre/post)args can be a callable to make it possible to get its
|
||||
# value from the compiler
|
||||
if callable(extra_preargs):
|
||||
extra_preargs = extra_preargs(ccompiler)
|
||||
if callable(extra_postargs):
|
||||
extra_postargs = extra_postargs(ccompiler)
|
||||
|
||||
start_dir = os.path.abspath('.')
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
try:
|
||||
os.chdir(tmp_dir)
|
||||
|
||||
# Write test program
|
||||
with open('test_program.c', 'w') as f:
|
||||
f.write(code)
|
||||
|
||||
os.mkdir('objects')
|
||||
|
||||
# Compile, test program
|
||||
ccompiler.compile(['test_program.c'], output_dir='objects',
|
||||
extra_postargs=extra_postargs)
|
||||
|
||||
# Link test program
|
||||
objects = glob.glob(
|
||||
os.path.join('objects', '*' + ccompiler.obj_extension))
|
||||
ccompiler.link_executable(objects, 'test_program',
|
||||
extra_preargs=extra_preargs,
|
||||
extra_postargs=extra_postargs)
|
||||
|
||||
if "PYTHON_CROSSENV" not in os.environ:
|
||||
# Run test program if not cross compiling
|
||||
# will raise a CalledProcessError if return code was non-zero
|
||||
output = subprocess.check_output('./test_program')
|
||||
output = output.decode(sys.stdout.encoding or 'utf-8').splitlines() # noqa
|
||||
else:
|
||||
output = []
|
||||
except Exception:
|
||||
raise
|
||||
finally:
|
||||
os.chdir(start_dir)
|
||||
|
||||
return output
|
||||
|
||||
|
||||
def basic_check_build():
|
||||
"""Check basic compilation and linking of C code"""
|
||||
code = textwrap.dedent(
|
||||
"""\
|
||||
#include <stdio.h>
|
||||
int main(void) {
|
||||
return 0;
|
||||
}
|
||||
""")
|
||||
compile_test_program(code)
|
||||
@ -0,0 +1 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
Binary file not shown.
Reference in New Issue
Block a user