Skip to content

Commit

Permalink
Merge pull request #662 from stan-dev/fix/659-space-include-paths
Browse files Browse the repository at this point in the history
Fix: escape spaces in call to make
  • Loading branch information
WardBrian authored Mar 24, 2023
2 parents 087a765 + 0a3293c commit 10c2b46
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
5 changes: 4 additions & 1 deletion cmdstanpy/compiler_opts.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,10 @@ def compose_stanc(self) -> List[str]:

def compose(self) -> List[str]:
"""Format makefile options as list of strings."""
opts = ['STANCFLAGS+=' + flag for flag in self.compose_stanc()]
opts = [
'STANCFLAGS+=' + flag.replace(" ", "\\ ")
for flag in self.compose_stanc()
]
if self._cpp_options is not None and len(self._cpp_options) > 0:
for key, val in self._cpp_options.items():
opts.append(f'{key}={val}')
Expand Down
29 changes: 29 additions & 0 deletions test/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,35 @@ def test_model_compile_space() -> None:
assert exe_time == os.path.getmtime(model2.exe_file)


def test_model_includes_space() -> None:
"""Test model with include file in path with spaces."""
stan = os.path.join(DATAFILES_PATH, 'bernoulli_include.stan')
stan_divide = os.path.join(DATAFILES_PATH, 'divide_real_by_two.stan')

with tempfile.TemporaryDirectory(
prefix="cmdstanpy_testfolder_"
) as tmp_path:
path_with_space = os.path.join(tmp_path, "space in path")
os.makedirs(path_with_space, exist_ok=True)
bern_stan_new = os.path.join(path_with_space, os.path.split(stan)[1])
stan_divide_new = os.path.join(
path_with_space, os.path.split(stan_divide)[1]
)
shutil.copyfile(stan, bern_stan_new)
shutil.copyfile(stan_divide, stan_divide_new)

model = CmdStanModel(
stan_file=bern_stan_new,
stanc_options={'include-paths': path_with_space},
)
assert "space in path" in str(model.exe_file)

assert "space in path" in model.src_info()['included_files'][0]
assert (
"divide_real_by_two.stan" in model.src_info()['included_files'][0]
)


def test_model_includes_explicit() -> None:
if os.path.exists(BERN_EXE):
os.remove(BERN_EXE)
Expand Down

0 comments on commit 10c2b46

Please sign in to comment.