1010import platform
1111import sys
1212import shutil
13+ from pathlib import Path
1314
1415import numpy
1516
1920
2021DAKOTA_EXEC = shutil .which ("dakota" )
2122if not DAKOTA_EXEC :
22- exit (' Unable to find dakota executable.' )
23+ sys . exit (" Unable to find dakota executable." )
2324
2425
2526def get_default_boost_python ():
@@ -34,42 +35,49 @@ def get_numpy_include():
3435def find_dakota_paths ():
3536 """Assuming standard prefix-based install."""
3637 dakota_install = os .path .dirname (os .path .dirname (DAKOTA_EXEC ))
37- dakota_bin = os .path .join (dakota_install , ' bin' )
38- dakota_include = os .path .join (dakota_install , ' include' )
39- dakota_lib = os .path .join (dakota_install , ' lib' )
40- eigen_include = os .path .join (dakota_include , ' eigen3' )
38+ dakota_bin = os .path .join (dakota_install , " bin" )
39+ dakota_include = os .path .join (dakota_install , " include" )
40+ dakota_lib = os .path .join (dakota_install , " lib" )
41+ eigen_include = os .path .join (dakota_include , " eigen3" )
4142 req = (dakota_bin , dakota_include , dakota_lib )
4243 if not all (map (os .path .exists , req )):
43- exit ("Can't find %s or %s or %s, bummer" % req )
44+ sys . exit ("Can't find %s or %s or %s, bummer" % req )
4445 return dakota_install , dakota_bin , dakota_include , dakota_lib , eigen_include
4546
4647
4748def read_dakota_macros (install_path ):
4849 """Read make macros from `install_path`/include/Makefile.export.Dakota."""
4950 dakota_macros = {}
50- with open (os .path .join (install_path , 'include' ,
51- 'Makefile.export.Dakota' ), 'r' ) as inp :
51+ with open (
52+ os .path .join (install_path , "include" , "Makefile.export.Dakota" ), "r"
53+ ) as inp :
5254 for line in inp :
5355 line = line .strip ()
54- if not line or line .startswith ('#' ):
56+ if not line or line .startswith ("#" ):
5557 continue
56- name , _ , value = line .partition ('=' )
58+ name , _ , value = line .partition ("=" )
5759 dakota_macros [name .strip ()] = value .strip ().split ()
5860 return dakota_macros
5961
6062
6163def get_dakota_libs (macros ):
62- """Drop '-l' from Dakota_LIBRARIES if necessary."""
63- libs = macros ['Dakota_LIBRARIES' ]
64- libs = [name [2 :] if name .startswith ('-l' ) else name for name in libs ]
64+ """Drop '-l' from Dakota_LIBRARIES if necessary.
65+
66+ Also strip CMake namespace prefixes
67+ (e.g. 'TeuchosCore::teuchoscore' -> 'teuchoscore')
68+ """
69+ libs = macros ["Dakota_LIBRARIES" ]
70+ libs = [name [2 :] if name .startswith ("-l" ) else name for name in libs ]
71+ libs = [name .split ("::" )[- 1 ] if "::" in name else name for name in libs ]
6572 return libs
6673
6774
6875def get_define_macros (macros ):
6976 """Drop '-D' from Dakota_DEFINES."""
70- define_macros = [(name [2 :], None ) for name in macros [' Dakota_DEFINES' ]]
77+ define_macros = [(name [2 :], None ) for name in macros [" Dakota_DEFINES" ]]
7178 return define_macros
7279
80+
7381def get_boost_inc_lib ():
7482 """BOOST_ROOT is expected to be set if a certain boost build is required.
7583
@@ -79,35 +87,36 @@ def get_boost_inc_lib():
7987
8088 """
8189
82- boost_root = os .getenv (' BOOST_ROOT' , None )
90+ boost_root = os .getenv (" BOOST_ROOT" , None )
8391
8492 boost_inc_dir = None
8593 boost_lib_dir = None
8694 if boost_root :
87- boost_inc_dir = os .path .join (boost_root , ' include' )
88- boost_lib_dir = os .path .join (boost_root , ' lib' )
95+ boost_inc_dir = os .path .join (boost_root , " include" )
96+ boost_lib_dir = os .path .join (boost_root , " lib" )
8997
90- boost_python = os .getenv (' BOOST_PYTHON' , get_default_boost_python ())
98+ boost_python = os .getenv (" BOOST_PYTHON" , get_default_boost_python ())
9199
92100 if not boost_lib_dir :
93101 return boost_inc_dir , None , None , boost_python
94102
95- return boost_inc_dir , boost_lib_dir , boost_lib_dir + '64' , boost_python
103+ return boost_inc_dir , boost_lib_dir , boost_lib_dir + "64" , boost_python
96104
97105
98106def get_macros_include_library ():
99107 """Get the dakota macros, include and library dirs."""
100- dakota_install , dakota_bin , dakota_include , dakota_lib , eigen_include = find_dakota_paths ()
108+ dakota_install , dakota_bin , dakota_include , dakota_lib , eigen_include = (
109+ find_dakota_paths ()
110+ )
101111 dakota_macros = read_dakota_macros (dakota_install )
102112
103113 inc = [dakota_include , eigen_include , get_numpy_include ()]
104114 lib = [dakota_lib , dakota_bin ]
105115 return dakota_macros , inc , lib
106116
107- def get_carolina_extension ():
108- """Setup everything and make an Extension for Carolina!
109117
110- """
118+ def get_carolina_extension ():
119+ """Setup everything and make an Extension for Carolina!"""
111120
112121 dakota_macros , include_dirs , library_dirs = get_macros_include_library ()
113122
@@ -118,12 +127,16 @@ def get_carolina_extension():
118127 library_dirs .append (boost_lib )
119128 library_dirs .append (boost_lib64 )
120129
130+ sources = ["src/dakface.cpp" , "src/dakota_python_binding.cpp" ]
121131
122- sources = ['src/dakface.cpp' , 'src/dakota_python_binding.cpp' ]
123-
124-
125- external_libs = ['boost_regex' , 'boost_filesystem' , 'boost_serialization' ,
126- 'boost_system' , 'boost_program_options' , boost_python ]
132+ external_libs = [
133+ "boost_regex" ,
134+ "boost_filesystem" ,
135+ "boost_serialization" ,
136+ "boost_system" ,
137+ "boost_program_options" ,
138+ boost_python ,
139+ ]
127140
128141 print (boost_python )
129142
@@ -134,19 +147,21 @@ def get_carolina_extension():
134147
135148 if "Darwin" in platform .system ():
136149 # Reserve header space for install_name_tool rewrites by delocate
137- extra_link_args = [' -Wl,-headerpad_max_install_names' ]
150+ extra_link_args = [" -Wl,-headerpad_max_install_names" ]
138151 else :
139- extra_link_args = ['-Wl,-z,origin' ]
140-
141- carolina = Extension (name = 'carolina' ,
142- sources = sources ,
143- include_dirs = include_dirs ,
144- define_macros = define_macros ,
145- extra_link_args = extra_link_args ,
146- extra_compile_args = ['-std=c++17' ],
147- library_dirs = library_dirs ,
148- libraries = libraries ,
149- language = 'c++' )
152+ extra_link_args = ["-Wl,-z,origin" ]
153+
154+ carolina = Extension (
155+ name = "carolina" ,
156+ sources = sources ,
157+ include_dirs = include_dirs ,
158+ define_macros = define_macros ,
159+ extra_link_args = extra_link_args ,
160+ extra_compile_args = ["-std=c++17" ],
161+ library_dirs = library_dirs ,
162+ libraries = libraries ,
163+ language = "c++" ,
164+ )
150165 return carolina
151166
152167
@@ -155,8 +170,8 @@ def get_carolina_extension():
155170setup (
156171 name = "carolina" ,
157172 description = "A Python wrapper for DAKOTA" ,
158- long_description = open ( ' README.md' ). read ( ),
159- long_description_content_type = ' text/markdown' ,
173+ long_description = Path ( " README.md" ). read_text ( encoding = "utf-8" ),
174+ long_description_content_type = " text/markdown" ,
160175 py_modules = ["dakota" ],
161176 ext_modules = [CAROLINA ],
162177 package_dir = {"" : "src" },
0 commit comments