Skip to content

Commit e16b94c

Browse files
committed
Try to fix rest of deprecated tests, add filename-in-msg
1 parent a0bfcd8 commit e16b94c

4 files changed

Lines changed: 13 additions & 8 deletions

File tree

cmdstanpy/compiler_opts.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,12 @@ def add_include_path(self, path: str) -> None:
275275
elif path not in self._stanc_options['include-paths']:
276276
self._stanc_options['include-paths'].append(path)
277277

278-
def compose_stanc(self) -> List[str]:
278+
def compose_stanc(self, filename_in_msg: Optional[str]) -> List[str]:
279279
opts = []
280+
281+
if filename_in_msg is not None:
282+
opts.append(f'--filename-in-msg={filename_in_msg}')
283+
280284
if self._stanc_options is not None and len(self._stanc_options) > 0:
281285
for key, val in self._stanc_options.items():
282286
if key == 'include-paths':
@@ -295,11 +299,11 @@ def compose_stanc(self) -> List[str]:
295299
opts.append(f'--{key}')
296300
return opts
297301

298-
def compose(self) -> List[str]:
302+
def compose(self, filename_in_msg: Optional[str]) -> List[str]:
299303
"""Format makefile options as list of strings."""
300304
opts = [
301305
'STANCFLAGS+=' + flag.replace(" ", "\\ ")
302-
for flag in self.compose_stanc()
306+
for flag in self.compose_stanc(filename_in_msg)
303307
]
304308
if self._cpp_options is not None and len(self._cpp_options) > 0:
305309
for key, val in self._cpp_options.items():

cmdstanpy/model.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ def src_info(self) -> Dict[str, Any]:
300300
cmd = (
301301
[os.path.join(cmdstan_path(), 'bin', 'stanc' + EXTENSION)]
302302
# handle include-paths, allow-undefined etc
303-
+ self._compiler_options.compose_stanc()
303+
+ self._compiler_options.compose_stanc(None)
304304
+ ['--info', str(self.stan_file)]
305305
)
306306
proc = subprocess.run(cmd, capture_output=True, text=True, check=False)
@@ -343,7 +343,7 @@ def format(
343343
cmd = (
344344
[os.path.join(cmdstan_path(), 'bin', 'stanc' + EXTENSION)]
345345
# handle include-paths, allow-undefined etc
346-
+ self._compiler_options.compose_stanc()
346+
+ self._compiler_options.compose_stanc(None)
347347
+ [str(self.stan_file)]
348348
)
349349

@@ -528,7 +528,7 @@ def compile(
528528
)
529529
cmd = [make]
530530
if self._compiler_options is not None:
531-
cmd.extend(self._compiler_options.compose())
531+
cmd.extend(self._compiler_options.compose(self._stan_file))
532532
cmd.append(Path(exe_file).as_posix())
533533

534534
sout = io.StringIO()

test/data/bernoulli_include.stan

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ functions {
33
}
44
data {
55
int<lower=0> N;
6-
int<lower=0,upper=1> y[N];
6+
array[N] int<lower=0,upper=1> y;
77
}
88
parameters {
99
real<lower=0,upper=1> theta;

test/data/path with space/bernoulli_path_with_space.stan

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ data {
55
parameters {
66
real<lower=0, upper=1> theta;
77
}
8+
;
89
model {
910
theta ~ beta(1, 1);
10-
for (n in 1 : N)
11+
for (n in 1 : N)
1112
y[n] ~ bernoulli(theta);
1213
}
1314

0 commit comments

Comments
 (0)