Skip to content

Commit 2d7f280

Browse files
committed
Simplify
1 parent eae3612 commit 2d7f280

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

cmdstanpy/utils.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,6 @@ 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-
)
159154
if not os.path.exists(os.path.join(path, 'bin', 'stanc' + EXTENSION)):
160155
raise ValueError(
161156
f'CmdStan installataion missing binaries in {path}/bin. '
@@ -223,6 +218,13 @@ def cmdstan_version() -> Optional[Tuple[int, ...]]:
223218
get_logger().debug("%s", e)
224219
return None
225220

221+
if not os.path.exists(makefile):
222+
get_logger().info(
223+
'CmdStan installation %s missing makefile, cannot get version.',
224+
cmdstan_path(),
225+
)
226+
return None
227+
226228
with open(makefile, 'r') as fd:
227229
contents = fd.read()
228230

test/test_utils.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,6 @@ def test_validate_path(self):
138138
with self.assertRaisesRegex(ValueError, 'No CmdStan directory'):
139139
validate_cmdstan_path(path_foo)
140140

141-
with self.assertRaisesRegex(
142-
ValueError, ".*Are you sure this is the correct path.*"
143-
):
144-
set_cmdstan_path(str(DATAFILES_PATH))
145-
146141
folder_name = ''.join(
147142
random.choice(string.ascii_letters) for _ in range(10)
148143
)
@@ -153,6 +148,7 @@ def test_validate_path(self):
153148
folder = pathlib.Path(folder_name)
154149
folder.mkdir(parents=True)
155150
(folder / "makefile").touch()
151+
156152
with self.assertRaisesRegex(ValueError, 'missing binaries'):
157153
validate_cmdstan_path(str(folder.absolute()))
158154
shutil.rmtree(folder)
@@ -216,16 +212,17 @@ def test_cmdstan_version(self):
216212
'found: "dont_need_no_mmp".'
217213
)
218214
with LogCapture() as log:
219-
logging.getLogger()
220215
cmdstan_version()
221216
log.check_present(('cmdstanpy', 'INFO', expect))
222217

223218
fake_makefile.unlink()
224-
expect = StringComparison('.*does not contain "makefile".*')
219+
expect = (
220+
'CmdStan installation {} missing makefile, '
221+
'cannot get version.'.format(fake_path)
222+
)
225223
with LogCapture() as log:
226-
logging.getLogger()
227224
cmdstan_version()
228-
log.check_present(('cmdstanpy', 'DEBUG', expect))
225+
log.check_present(('cmdstanpy', 'INFO', expect))
229226
cmdstan_path()
230227

231228

0 commit comments

Comments
 (0)