Skip to content

Commit

Permalink
Use sys.prefix as default value for include/library_dir preferences
Browse files Browse the repository at this point in the history
This means the user can overwrite them by setting the preference.
Previously, the dirs were always appended (for Cython) or prepended
(for C++ standalone).
  • Loading branch information
mstimberg committed Sep 27, 2021
1 parent d6e3944 commit 7fd170b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 27 deletions.
30 changes: 21 additions & 9 deletions brian2/codegen/cpp_prefs.py
Expand Up @@ -111,6 +111,11 @@
else:
default_buildopts = ['-w']

if sys.platform == 'win32':
prefix_dir = os.path.join(sys.prefix, 'Library')
else:
prefix_dir = sys.prefix

# Preferences
prefs.register_preferences(
'codegen.cpp',
Expand Down Expand Up @@ -154,26 +159,33 @@
'''
),
include_dirs=BrianPreference(
default=[],
default=[os.path.join(prefix_dir, 'include')],
docs='''
Include directories to use. Note that ``$prefix/include`` will be
appended to the end automatically, where ``$prefix`` is Python's
site-specific directory prefix as returned by `sys.prefix`.
Include directories to use.
The default value is ``$prefix/include`` (or ``$prefix/Library/include``
on Windows), where ``$prefix`` is Python's site-specific directory
prefix as returned by `sys.prefix`. This will make compilation use
library files installed into a conda environment.
'''
),
library_dirs=BrianPreference(
default=[],
default=[os.path.join(prefix_dir, 'lib')],
docs='''
List of directories to search for C/C++ libraries at link time.
Note that ``$prefix/lib`` will be appended to the end automatically,
where ``$prefix`` is Python's site-specific directory prefix as returned
by `sys.prefix`.
The default value is ``$prefix/lib`` (or ``$prefix/Library/lib``
on Windows), where ``$prefix`` is Python's site-specific directory
prefix as returned by `sys.prefix`. This will make compilation use
library files installed into a conda environment.
'''
),
runtime_library_dirs=BrianPreference(
default=[],
default=[os.path.join(prefix_dir, 'lib')],
docs='''
List of directories to search for C/C++ libraries at run time.
The default value is ``$prefix/lib`` (or ``$prefix/Library/lib``
on Windows), where ``$prefix`` is Python's site-specific directory
prefix as returned by `sys.prefix`. This will make compilation use
library files installed into a conda environment.
'''
),
libraries=BrianPreference(
Expand Down
8 changes: 0 additions & 8 deletions brian2/codegen/runtime/cython_rt/cython_rt.py
Expand Up @@ -93,17 +93,9 @@ def __init__(self, owner, code, variables, variable_indices,
self.include_dirs = (list(prefs['codegen.cpp.include_dirs']) +
compiler_kwds.get('include_dirs', []))
self.include_dirs = list(prefs['codegen.cpp.include_dirs'])
if sys.platform == 'win32':
self.include_dirs += [os.path.join(sys.prefix, 'Library', 'include')]
else:
self.include_dirs += [os.path.join(sys.prefix, 'include')]

self.library_dirs = (list(prefs['codegen.cpp.library_dirs']) +
compiler_kwds.get('library_dirs', []))
if sys.platform == 'win32':
self.library_dirs += [os.path.join(sys.prefix, 'Library', 'lib')]
else:
self.library_dirs += [os.path.join(sys.prefix, 'lib')]

self.runtime_library_dirs = (list(prefs['codegen.cpp.runtime_library_dirs']),
compiler_kwds.get('runtime_library_dirs', []))
Expand Down
10 changes: 0 additions & 10 deletions brian2/devices/cpp_standalone/device.py
Expand Up @@ -205,18 +205,8 @@ def __init__(self):
self.define_macros = []
self.headers = []
self.include_dirs = ['brianlib/randomkit']
if sys.platform == 'win32':
self.include_dirs += [os.path.join(sys.prefix, 'Library', 'include')]
else:
self.include_dirs += [os.path.join(sys.prefix, 'include')]
self.library_dirs = ['brianlib/randomkit']
if sys.platform == 'win32':
self.library_dirs += [os.path.join(sys.prefix, 'Library', 'Lib')]
else:
self.library_dirs += [os.path.join(sys.prefix, 'lib')]
self.runtime_library_dirs = []
if sys.platform.startswith('linux'):
self.runtime_library_dirs += [os.path.join(sys.prefix, 'lib')]
self.run_environment_variables = {}
if sys.platform.startswith('darwin'):
if 'DYLD_LIBRARY_PATH' in os.environ:
Expand Down

0 comments on commit 7fd170b

Please sign in to comment.