Skip to content

Commit

Permalink
Use numpy's major.minor version instead of the ABI version (see previ…
Browse files Browse the repository at this point in the history
…ous commit)
  • Loading branch information
mstimberg committed Jan 25, 2018
1 parent b0e25ca commit 279f04d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 24 deletions.
18 changes: 0 additions & 18 deletions brian2/codegen/generators/base.py
Expand Up @@ -20,24 +20,6 @@
logger = get_logger(__name__)


def get_numpy_ABI_version():
# I don't see a way to get numpy's ABI version from Python,
# so we look it up in the numpy header file that we are using
# later...
header_name = os.path.join(numpy.get_include(), 'numpy', '_numpyconfig.h')
if os.path.exists(header_name):
with open(header_name, 'r') as f:
for line in f.readlines():
if line.startswith('#define NPY_ABI_VERSION'):
elements = line.split(' ')
if len(elements) == 3 and elements[2].startswith('0x'):
return elements[2]

# Something went wrong, we don't want to raise an error because
# it might be that we'll never actually use this information
return 'Unknown'


class CodeGenerator(object):
'''
Base class for all languages.
Expand Down
6 changes: 3 additions & 3 deletions brian2/codegen/runtime/cython_rt/extension_manager.py
Expand Up @@ -23,6 +23,7 @@
from distutils.core import Distribution, Extension
from distutils.command.build_ext import build_ext

import numpy
try:
import Cython
import Cython.Compiler as Cython_Compiler
Expand All @@ -32,7 +33,6 @@
Cython = None

from brian2.codegen.cpp_prefs import update_for_cross_compilation
from brian2.codegen.generators.base import get_numpy_ABI_version
from brian2.utils.logger import std_silent, get_logger
from brian2.utils.stringtools import deindent
from brian2.core.preferences import prefs
Expand All @@ -45,7 +45,6 @@
class CythonExtensionManager(object):
def __init__(self):
self._code_cache = {}
self.numpy_ABI_version = get_numpy_ABI_version()

def create_extension(self, code, force=False, name=None,
define_macros=None,
Expand Down Expand Up @@ -78,7 +77,8 @@ def create_extension(self, code, force=False, name=None,
raise IOError("Couldn't create Cython cache directory '%s', try setting the "
"cache directly with prefs.codegen.runtime.cython.cache_dir." % lib_dir)

key = code, sys.version_info, sys.executable, Cython.__version__, self.numpy_ABI_version
numpy_version = '.'.join(numpy.__version__.split('.')[:2]) # Only use major.minor version
key = code, sys.version_info, sys.executable, Cython.__version__, numpy_version

if force:
# Force a new module name by adding the current time to the
Expand Down
5 changes: 2 additions & 3 deletions brian2/codegen/runtime/weave_rt/weave_rt.py
Expand Up @@ -29,7 +29,6 @@
from ...codeobject import CodeObject, constant_or_scalar, sys_info
from ...templates import Templater
from ...generators.cpp_generator import CPPCodeGenerator
from ...generators.base import get_numpy_ABI_version
from ...targets import codegen_targets
from ...cpp_prefs import get_compiler_and_args, update_for_cross_compilation

Expand Down Expand Up @@ -77,7 +76,6 @@ class WeaveCodeObject(CodeObject):
'constant_or_scalar': constant_or_scalar})
generator_class = WeaveCodeGenerator
class_name = 'weave'
numpy_ABI_version = get_numpy_ABI_version()

def __init__(self, owner, code, variables, variable_indices,
template_name, template_source, name='weave_code_object*'):
Expand Down Expand Up @@ -119,6 +117,7 @@ def __init__(self, owner, code, variables, variable_indices,
self.runtime_library_dirs = list(prefs['codegen.cpp.runtime_library_dirs'])
self.libraries = list(prefs['codegen.cpp.libraries'])
self.headers = ['<algorithm>', '<limits>', '"stdint_compat.h"'] + prefs['codegen.cpp.headers']
self.numpy_version = '.'.join(numpy.__version__.split('.')[:2]) # Only use major.minor version
self.annotated_code = self.code.main+'''
/*
The following code is just compiler options for the call to weave.inline.
Expand All @@ -137,7 +136,7 @@ def __init__(self, owner, code, variables, variable_indices,
runtime_library_dirs: {self.runtime_library_dirs}
libraries: {self.libraries}
numpy ABI version: {self.numpy_ABI_version}
numpy version: {self.numpy_version}
*/
'''.format(self=self)

Expand Down

0 comments on commit 279f04d

Please sign in to comment.