@@ -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 \t These 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
0 commit comments