From d646890e91b520098ccb932308697515de312b3f Mon Sep 17 00:00:00 2001 From: Till Hoffmann Date: Thu, 21 Sep 2023 15:55:41 -0400 Subject: [PATCH 1/5] Always run `compile_example` in `install_cmdstan` (fixes #703). --- cmdstanpy/install_cmdstan.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmdstanpy/install_cmdstan.py b/cmdstanpy/install_cmdstan.py index c3ba0a93..a658fcec 100644 --- a/cmdstanpy/install_cmdstan.py +++ b/cmdstanpy/install_cmdstan.py @@ -421,8 +421,6 @@ def install_version( clean_all(verbose) print('Rebuilding version {}'.format(cmdstan_version)) build(verbose, progress=progress, cores=cores) - print('Test model compilation') - compile_example(verbose) print('Installed {}'.format(cmdstan_version)) @@ -637,6 +635,8 @@ def run_install(args: Union[InteractiveSettings, InstallationSettings]) -> None: ) else: print('CmdStan version {} already installed'.format(args.version)) + print('Test model compilation') + compile_example(args.verbose) def parse_cmdline_args() -> Dict[str, Any]: From 25b5798a0339e3a0cfaf51be0d956c802ca38e15 Mon Sep 17 00:00:00 2001 From: Till Hoffmann Date: Thu, 21 Sep 2023 16:13:22 -0400 Subject: [PATCH 2/5] Fix working directory and unlink compiled example before test. --- cmdstanpy/install_cmdstan.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/cmdstanpy/install_cmdstan.py b/cmdstanpy/install_cmdstan.py index a658fcec..14e8ce33 100644 --- a/cmdstanpy/install_cmdstan.py +++ b/cmdstanpy/install_cmdstan.py @@ -349,12 +349,13 @@ def compile_example(verbose: bool = False) -> None: :param verbose: Boolean value; when ``True``, show output from make command. """ - cmd = [ - MAKE, - Path( - os.path.join('examples', 'bernoulli', 'bernoulli' + EXTENSION) - ).as_posix(), - ] + path = Path( + os.path.join('examples', 'bernoulli', 'bernoulli' + EXTENSION) + ) + if path.is_file(): + path.unlink() + + cmd = [MAKE, path.as_posix()] try: if verbose: do_command(cmd) @@ -635,8 +636,10 @@ def run_install(args: Union[InteractiveSettings, InstallationSettings]) -> None: ) else: print('CmdStan version {} already installed'.format(args.version)) - print('Test model compilation') - compile_example(args.verbose) + + with pushd(cmdstan_version): + print('Test model compilation') + compile_example(args.verbose) def parse_cmdline_args() -> Dict[str, Any]: From f9a3a14dbf7626f7c9e5ad9aa0949ac85a5d55be Mon Sep 17 00:00:00 2001 From: Till Hoffmann Date: Thu, 21 Sep 2023 16:33:22 -0400 Subject: [PATCH 3/5] Use `pathlib.Path` for example binary. --- cmdstanpy/install_cmdstan.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cmdstanpy/install_cmdstan.py b/cmdstanpy/install_cmdstan.py index 14e8ce33..a69735fd 100644 --- a/cmdstanpy/install_cmdstan.py +++ b/cmdstanpy/install_cmdstan.py @@ -349,9 +349,7 @@ def compile_example(verbose: bool = False) -> None: :param verbose: Boolean value; when ``True``, show output from make command. """ - path = Path( - os.path.join('examples', 'bernoulli', 'bernoulli' + EXTENSION) - ) + path = Path('examples', 'bernoulli', 'bernoulli').with_suffix(EXTENSION) if path.is_file(): path.unlink() From b2c682389d85f3545d650f959f86a2cb52c4ec2f Mon Sep 17 00:00:00 2001 From: Till Hoffmann Date: Thu, 21 Sep 2023 16:34:21 -0400 Subject: [PATCH 4/5] Check example binary exists after compilation. --- cmdstanpy/install_cmdstan.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmdstanpy/install_cmdstan.py b/cmdstanpy/install_cmdstan.py index a69735fd..d4b11d4e 100644 --- a/cmdstanpy/install_cmdstan.py +++ b/cmdstanpy/install_cmdstan.py @@ -363,6 +363,9 @@ def compile_example(verbose: bool = False) -> None: # pylint: disable=raise-missing-from raise CmdStanInstallError(f'Command "make clean-all" failed\n{e}') + if not path.is_file(): + raise CmdStanInstallError("Failed to generate example binary") + def rebuild_cmdstan( verbose: bool = False, progress: bool = True, cores: int = 1 From 28956398d593e1ba94c0b74010a4301d0288622b Mon Sep 17 00:00:00 2001 From: Till Hoffmann Date: Thu, 21 Sep 2023 16:51:27 -0400 Subject: [PATCH 5/5] Fix error message for failed example compilation. --- cmdstanpy/install_cmdstan.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmdstanpy/install_cmdstan.py b/cmdstanpy/install_cmdstan.py index d4b11d4e..bae6ac18 100644 --- a/cmdstanpy/install_cmdstan.py +++ b/cmdstanpy/install_cmdstan.py @@ -361,7 +361,7 @@ def compile_example(verbose: bool = False) -> None: do_command(cmd, fd_out=None) except RuntimeError as e: # pylint: disable=raise-missing-from - raise CmdStanInstallError(f'Command "make clean-all" failed\n{e}') + raise CmdStanInstallError(f'Command "{" ".join(cmd)}" failed:\n{e}') if not path.is_file(): raise CmdStanInstallError("Failed to generate example binary")