Skip to content

Commit a59cca6

Browse files
committed
Fix location setting after install_cmdstan()
1 parent 3fe0469 commit a59cca6

File tree

4 files changed

+28
-12
lines changed

4 files changed

+28
-12
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@ jobs:
9696
run: |
9797
install_cmdstan -h
9898
install_cxx_toolchain -h
99-
python -m cmdstanpy.install_cmdstan --version ${{ needs.get-cmdstan-version.outputs.version }}
99+
python -c "import cmdstanpy; cmdstanpy.install_cmdstan(version='${{ needs.get-cmdstan-version.outputs.version }}', cores=2)"
100100
101101
- name: Install CmdStan (Windows)
102102
if: matrix.os == 'windows-latest'
103103
run: |
104104
install_cmdstan -h
105105
install_cxx_toolchain -h
106-
python -m cmdstanpy.install_cmdstan --compiler --version ${{ needs.get-cmdstan-version.outputs.version }}
106+
python -m cmdstanpy.install_cmdstan --compiler --version ${{ needs.get-cmdstan-version.outputs.version }} --cores 2
107107
108108
- name: Run tests
109109
run: |

cmdstanpy/install_cmdstan.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77
example model ``bernoulli.stan``.
88
99
Optional command line arguments:
10+
-i, --interactive: flag, when specified ignore other arguments and
11+
ask user for settings on STDIN
1012
-v, --version <release> : version, defaults to latest release version
1113
-d, --dir <path> : install directory, defaults to '$HOME/.cmdstan
1214
--overwrite: flag, when specified re-installs existing version
1315
--progress: flag, when specified show progress bar for CmdStan download
1416
--verbose: flag, when specified prints output from CmdStan build process
17+
--cores: int, number of cores to use when building, defaults to 1
1518
-c, --compiler : flag, add C++ compiler to path (Windows only)
1619
"""
1720
import argparse

cmdstanpy/utils.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,14 @@ def validate_cmdstan_path(path: str) -> None:
151151
"""
152152
if not os.path.isdir(path):
153153
raise ValueError(f'No CmdStan directory, path {path} does not exist.')
154+
if not os.path.isfile(os.path.join(path, "makefile")):
155+
raise ValueError(
156+
'CmdStan folder does not contain "makefile". '
157+
f'Are you sure this is the correct path: {path}?'
158+
)
154159
if not os.path.exists(os.path.join(path, 'bin', 'stanc' + EXTENSION)):
155160
raise ValueError(
156-
'CmdStan installataion missing binaries. '
161+
f'CmdStan installataion missing binaries in {path}/bin. '
157162
'Re-install cmdstan by running command "install_cmdstan '
158163
'--overwrite", or Python code "import cmdstanpy; '
159164
'cmdstanpy.install_cmdstan(overwrite=True)"'
@@ -299,7 +304,7 @@ def cxx_toolchain_path(
299304
if os.path.exists(os.path.join(toolchain_root, 'mingw64')):
300305
compiler_path = os.path.join(
301306
toolchain_root,
302-
'mingw64' if (sys.maxsize > 2**32) else 'mingw32',
307+
'mingw64' if (sys.maxsize > 2 ** 32) else 'mingw32',
303308
'bin',
304309
)
305310
if os.path.exists(compiler_path):
@@ -323,7 +328,7 @@ def cxx_toolchain_path(
323328
elif os.path.exists(os.path.join(toolchain_root, 'mingw_64')):
324329
compiler_path = os.path.join(
325330
toolchain_root,
326-
'mingw_64' if (sys.maxsize > 2**32) else 'mingw_32',
331+
'mingw_64' if (sys.maxsize > 2 ** 32) else 'mingw_32',
327332
'bin',
328333
)
329334
if os.path.exists(compiler_path):
@@ -375,7 +380,7 @@ def cxx_toolchain_path(
375380
if version not in ('35', '3.5', '3'):
376381
compiler_path = os.path.join(
377382
toolchain_root,
378-
'mingw64' if (sys.maxsize > 2**32) else 'mingw32',
383+
'mingw64' if (sys.maxsize > 2 ** 32) else 'mingw32',
379384
'bin',
380385
)
381386
if os.path.exists(compiler_path):
@@ -400,7 +405,7 @@ def cxx_toolchain_path(
400405
else:
401406
compiler_path = os.path.join(
402407
toolchain_root,
403-
'mingw_64' if (sys.maxsize > 2**32) else 'mingw_32',
408+
'mingw_64' if (sys.maxsize > 2 ** 32) else 'mingw_32',
404409
'bin',
405410
)
406411
if os.path.exists(compiler_path):
@@ -1361,7 +1366,7 @@ def install_cmdstan(
13611366
logger.warning('CmdStan installation failed.\n%s', str(e))
13621367
return False
13631368

1364-
set_cmdstan_path(args.dir)
1369+
set_cmdstan_path(os.path.join(args.dir, f"cmdstan-{args.version}"))
13651370

13661371
return True
13671372

test/test_utils.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import json
77
import logging
88
import os
9+
import pathlib
910
import platform
1011
import random
1112
import shutil
@@ -137,18 +138,25 @@ def test_validate_path(self):
137138
path_foo = os.path.abspath(os.path.join('releases', 'foo'))
138139
with self.assertRaisesRegex(ValueError, 'No CmdStan directory'):
139140
validate_cmdstan_path(path_foo)
141+
142+
with self.assertRaisesRegex(
143+
ValueError, ".*Are you sure this is the correct path.*"
144+
):
145+
set_cmdstan_path(str(DATAFILES_PATH))
146+
140147
folder_name = ''.join(
141148
random.choice(string.ascii_letters) for _ in range(10)
142149
)
143150
while os.path.exists(folder_name):
144151
folder_name = ''.join(
145152
random.choice(string.ascii_letters) for _ in range(10)
146153
)
147-
os.makedirs(folder_name)
148-
path_test = os.path.abspath(folder_name)
154+
folder = pathlib.Path(folder_name)
155+
folder.mkdir(parents=True)
156+
(folder / "makefile").touch()
149157
with self.assertRaisesRegex(ValueError, 'missing binaries'):
150-
validate_cmdstan_path(path_test)
151-
shutil.rmtree(folder_name)
158+
validate_cmdstan_path(str(folder.absolute()))
159+
shutil.rmtree(folder)
152160

153161
def test_validate_dir(self):
154162
with tempfile.TemporaryDirectory(

0 commit comments

Comments
 (0)