88import platform
99import shutil
1010import subprocess
11- from copy import copy
1211from datetime import datetime
1312from pathlib import Path
1413from typing import Any , Iterable , Optional , Union
3736 'warn-pedantic' ,
3837]
3938
40- # TODO(2.0): remove
41- STANC_DEPRECATED_OPTS = {
42- 'allow_undefined' : 'allow-undefined' ,
43- 'include_paths' : 'include-paths' ,
44- }
4539
4640STANC_IGNORE_OPTS = [
4741 'debug-lex' ,
6761OptionalPath = Union [str , os .PathLike , None ]
6862
6963
70- # TODO(2.0): can remove add function and other logic
7164class CompilerOptions :
7265 """
7366 User-specified flags for stanc and C++ compiler.
@@ -151,24 +144,6 @@ def validate_stanc_opts(self) -> None:
151144 paths = None
152145 has_o_flag = False
153146
154- for deprecated , replacement in STANC_DEPRECATED_OPTS .items ():
155- if deprecated in self ._stanc_options :
156- if replacement :
157- get_logger ().warning (
158- 'compiler option "%s" is deprecated, use "%s" instead' ,
159- deprecated ,
160- replacement ,
161- )
162- self ._stanc_options [replacement ] = copy (
163- self ._stanc_options [deprecated ]
164- )
165- del self ._stanc_options [deprecated ]
166- else :
167- get_logger ().warning (
168- 'compiler option "%s" is deprecated and should '
169- 'not be used' ,
170- deprecated ,
171- )
172147 for key , val in self ._stanc_options .items ():
173148 if key in STANC_IGNORE_OPTS :
174149 get_logger ().info ('ignoring compiler option: %s' , key )
@@ -267,37 +242,6 @@ def validate_user_header(self) -> None:
267242
268243 self ._cpp_options ['USER_HEADER' ] = self ._user_header
269244
270- def add (self , new_opts : "CompilerOptions" ) -> None : # noqa: disable=Q000
271- """Adds options to existing set of compiler options."""
272- if new_opts .stanc_options is not None :
273- if self ._stanc_options is None :
274- self ._stanc_options = new_opts .stanc_options
275- else :
276- for key , val in new_opts .stanc_options .items ():
277- if key == 'include-paths' :
278- if isinstance (val , Iterable ) and not isinstance (
279- val , str
280- ):
281- for path in val :
282- self .add_include_path (str (path ))
283- else :
284- self .add_include_path (str (val ))
285- else :
286- self ._stanc_options [key ] = val
287- if new_opts .cpp_options is not None :
288- for key , val in new_opts .cpp_options .items ():
289- self ._cpp_options [key ] = val
290- if new_opts ._user_header != '' and self ._user_header == '' :
291- self ._user_header = new_opts ._user_header
292-
293- def add_include_path (self , path : str ) -> None :
294- """Adds include path to existing set of compiler options."""
295- path = os .path .abspath (os .path .expanduser (path ))
296- if 'include-paths' not in self ._stanc_options :
297- self ._stanc_options ['include-paths' ] = [path ]
298- elif path not in self ._stanc_options ['include-paths' ]:
299- self ._stanc_options ['include-paths' ].append (path )
300-
301245 def compose_stanc (self , filename_in_msg : Optional [str ]) -> list [str ]:
302246 opts = []
303247
@@ -343,7 +287,8 @@ def compose(self, filename_in_msg: Optional[str] = None) -> list[str]:
343287
344288
345289def src_info (
346- stan_file : str , compiler_options : CompilerOptions
290+ stan_file : str ,
291+ stanc_options : Optional [dict [str , Any ]] = None ,
347292) -> dict [str , Any ]:
348293 """
349294 Get source info for Stan program file.
@@ -354,7 +299,7 @@ def src_info(
354299 cmd = (
355300 [stanc_path ()]
356301 # handle include-paths, allow-undefined etc
357- + compiler_options .compose_stanc (None )
302+ + CompilerOptions ( stanc_options = stanc_options ) .compose_stanc (None )
358303 + ['--info' , str (stan_file )]
359304 )
360305 proc = subprocess .run (cmd , capture_output = True , text = True , check = False )
@@ -412,7 +357,9 @@ def compile_stan_file(
412357 exe_time = os .path .getmtime (exe_target )
413358 included_files = [src ]
414359 included_files .extend (
415- src_info (str (src ), compiler_options ).get ('included_files' , [])
360+ src_info (str (src ), compiler_options .stanc_options ).get (
361+ 'included_files' , []
362+ )
416363 )
417364 out_of_date = any (
418365 os .path .getmtime (included_file ) > exe_time
0 commit comments