Skip to content

Commit 0d978f5

Browse files
committed
Merge branch 'develop' of https://github.com/stan-dev/cmdstanpy into develop
2 parents 8217ad4 + c37063f commit 0d978f5

49 files changed

Lines changed: 2360 additions & 662 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cmdstanpy/install_cmdstan.py

Lines changed: 277 additions & 151 deletions
Large diffs are not rendered by default.

cmdstanpy/install_cxx_toolchain.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def get_toolchain_version(name: str, version: str) -> str:
258258
return toolchain_folder
259259

260260

261-
def main(args: Dict[str, Any]) -> None:
261+
def run_rtools_install(args: Dict[str, Any]) -> None:
262262
"""Main."""
263263
if platform.system() not in {'Windows'}:
264264
raise NotImplementedError(
@@ -361,7 +361,7 @@ def parse_cmdline_args() -> Dict[str, Any]:
361361

362362

363363
def __main__() -> None:
364-
main(parse_cmdline_args())
364+
run_rtools_install(parse_cmdline_args())
365365

366366

367367
if __name__ == '__main__':

cmdstanpy/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ def compile(
482482
src_time = os.path.getmtime(self._stan_file)
483483
exe_time = os.path.getmtime(exe_target)
484484
if exe_time > src_time and not force:
485-
get_logger().info('found newer exe file, not recompiling')
485+
get_logger().debug('found newer exe file, not recompiling')
486486
if self._exe_file is None: # called from constructor
487487
self._exe_file = exe_target
488488
return

cmdstanpy/utils.py

Lines changed: 56 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,10 @@ def validate_cmdstan_path(path: str) -> None:
153153
raise ValueError(f'No CmdStan directory, path {path} does not exist.')
154154
if not os.path.exists(os.path.join(path, 'bin', 'stanc' + EXTENSION)):
155155
raise ValueError(
156-
'CmdStan installataion missing binaries, run "install_cmdstan"'
156+
'CmdStan installataion missing binaries. '
157+
'Re-install cmdstan by running command "install_cmdstan '
158+
'--overwrite", or Python code "import cmdstanpy; '
159+
'cmdstanpy.install_cmdstan(overwrite=True)"'
157160
)
158161

159162

@@ -183,14 +186,14 @@ def cmdstan_path() -> str:
183186
cmdstan_dir = os.path.expanduser(os.path.join('~', _DOT_CMDSTAN))
184187
if not os.path.exists(cmdstan_dir):
185188
raise ValueError(
186-
'No CmdStan installation found, run "install_cmdstan" or'
187-
' (re)activate your conda environment!'
189+
'No CmdStan installation found, run command "install_cmdstan"'
190+
'or (re)activate your conda environment!'
188191
)
189192
latest_cmdstan = get_latest_cmdstan(cmdstan_dir)
190193
if latest_cmdstan is None:
191194
raise ValueError(
192-
'No CmdStan installation found, run "install_cmdstan" or'
193-
' (re)activate your conda environment!'
195+
'No CmdStan installation found, run command "install_cmdstan"'
196+
'or (re)activate your conda environment!'
194197
)
195198
cmdstan = os.path.join(cmdstan_dir, latest_cmdstan)
196199
os.environ['CMDSTAN'] = cmdstan
@@ -1273,14 +1276,16 @@ def install_cmdstan(
12731276
progress: bool = False,
12741277
verbose: bool = False,
12751278
cores: int = 1,
1279+
*,
1280+
interactive: bool = False,
12761281
) -> bool:
12771282
"""
12781283
Download and install a CmdStan release from GitHub. Downloads the release
12791284
tar.gz file to temporary storage. Retries GitHub requests in order
12801285
to allow for transient network outages. Builds CmdStan executables
12811286
and tests the compiler by building example model ``bernoulli.stan``.
12821287
1283-
:param version: CmdStan version string, e.g. "2.24.1".
1288+
:param version: CmdStan version string, e.g. "2.29.2".
12841289
Defaults to latest CmdStan release.
12851290
12861291
:param dir: Path to install directory. Defaults to hidden directory
@@ -1304,36 +1309,60 @@ def install_cmdstan(
13041309
:param cores: Integer, number of cores to use in the ``make`` command.
13051310
Default is 1 core.
13061311
1312+
:param interactive: Boolean value; if true, ignore all other arguments
1313+
to this function and run in an interactive mode, prompting the user
1314+
to provide the other information manually through the standard input.
1315+
1316+
This flag should only be used in interactive environments,
1317+
e.g. on the command line.
1318+
13071319
:return: Boolean value; ``True`` for success.
13081320
"""
13091321
logger = get_logger()
1310-
args = {
1311-
"version": version,
1312-
"overwrite": overwrite,
1313-
"verbose": verbose,
1314-
"compiler": compiler,
1315-
"progress": progress,
1316-
"dir": dir,
1317-
"cores": cores,
1318-
}
1319-
13201322
try:
1321-
from .install_cmdstan import main
1323+
from .install_cmdstan import (
1324+
InstallationSettings,
1325+
InteractiveSettings,
1326+
run_install,
1327+
)
1328+
1329+
args: Union[InstallationSettings, InteractiveSettings]
13221330

1323-
main(args)
1331+
if interactive:
1332+
if any(
1333+
[
1334+
version,
1335+
dir,
1336+
overwrite,
1337+
compiler,
1338+
progress,
1339+
verbose,
1340+
cores != 1,
1341+
]
1342+
):
1343+
logger.warning(
1344+
"Interactive installation requested but other arguments"
1345+
" were used.\n\tThese values will be ignored!"
1346+
)
1347+
args = InteractiveSettings()
1348+
else:
1349+
args = InstallationSettings(
1350+
version=version,
1351+
overwrite=overwrite,
1352+
verbose=verbose,
1353+
compiler=compiler,
1354+
progress=progress,
1355+
dir=dir,
1356+
cores=cores,
1357+
)
1358+
run_install(args)
13241359
# pylint: disable=broad-except
13251360
except Exception as e:
1326-
logger.warning('CmdStan installation failed.')
1327-
logger.warning(str(e))
1361+
logger.warning('CmdStan installation failed.\n%s', str(e))
13281362
return False
13291363

1330-
if dir is not None:
1331-
if version is not None:
1332-
set_cmdstan_path(os.path.join(dir, 'cmdstan-' + version))
1333-
else:
1334-
set_cmdstan_path(
1335-
os.path.join(dir, get_latest_cmdstan(dir)) # type: ignore
1336-
)
1364+
set_cmdstan_path(args.dir)
1365+
13371366
return True
13381367

13391368

docsrc/conf.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,3 +445,6 @@ def emit(self, record):
445445
r">>> |\.\.\. |\$ |In \[\d*\]: | {2,5}\.\.\.: | {5,8}: "
446446
)
447447
copybutton_prompt_is_regexp = True
448+
449+
# speed up build if editing the docs
450+
# nbsphinx_execute = 'never'

0 commit comments

Comments
 (0)