@@ -182,74 +182,74 @@ def cmdstan_path() -> str:
182182 return cmdstan
183183
184184
185- def cmdstan_version_before ( major : int , minor : int ) -> bool :
185+ def cmdstan_version ( ) -> Optional [ Tuple [ int , ...]] :
186186 """
187- Check that CmdStan version is less than Major.minor version.
188- Parses version string out of CmdStan makefile variable CMDSTAN_VERSION .
187+ Parses version string out of CmdStan makefile variable CMDSTAN_VERSION,
188+ returns Tuple(Major, minor) .
189189
190- If CmdStan installation is found but cannot parse version from makefile
191- logs warning and returns False . Lenient behavoir required for CI tests,
192- per comment here :
190+ If CmdStan installation is not found or cannot parse version from makefile
191+ logs warning and returns None . Lenient behavoir required for CI tests,
192+ per comment:
193193 https://github.com/stan-dev/cmdstanpy/pull/321#issuecomment-733817554
194-
195- :param major: Major version number
196- :param minor: Minor version number
197-
198- :return: True if version at or above major.minor, else False.
199194 """
200195 try :
201196 makefile = os .path .join (cmdstan_path (), 'makefile' )
202197 except ValueError :
203- get_logger ().info (
204- 'No CmdStan installation found, '
205- 'cannot assert version is less than %d.%d.' ,
206- major ,
207- minor ,
208- )
209- return False
198+ get_logger ().info ('No CmdStan installation found.' )
199+ return None
210200
211201 if not os .path .exists (makefile ):
212202 get_logger ().info (
213- 'CmdStan installation %s missing makefile, '
214- 'cannot assert version is less than %d.%d.' ,
203+ 'CmdStan installation %s missing makefile, cannot get version.' ,
215204 cmdstan_path (),
216- major ,
217- minor ,
218205 )
219- return False
206+ return None
220207
221208 with open (makefile , 'r' ) as fd :
222209 contents = fd .read ()
223210
224211 start_idx = contents .find ('CMDSTAN_VERSION := ' )
225212 if start_idx < 0 :
226213 get_logger ().info (
227- 'Cannot parse version from makefile: %s,'
228- 'cannot assert version is less than %d.%d.' ,
214+ 'Cannot parse version from makefile: %s.' ,
229215 makefile ,
230- major ,
231- minor ,
232216 )
233- return False
217+ return None
234218
235219 start_idx += len ('CMDSTAN_VERSION := ' )
236220 end_idx = contents .find ('\n ' , start_idx )
237221
238222 version = contents [start_idx :end_idx ]
239- if version is None or len (version ) < 3 or len (version .split ('.' )) < 2 :
223+ splits = version .split ('.' )
224+ if len (splits ) != 3 :
240225 get_logger ().info (
241- 'Cannot parse version from makefile: %s,'
242- 'cannot assert version is less than %d.%d.' ,
243- makefile ,
244- major ,
245- minor ,
226+ 'Cannot parse version, expected "<major>.<minor>.<patch>", '
227+ 'found: "%s".' ,
228+ version ,
246229 )
247- return False
230+ return None
231+ return tuple (int (x ) for x in splits [0 :2 ])
248232
249- splits = version .split ('.' )
250- cur_major = int (splits [0 ])
251- cur_minor = int (splits [1 ])
252- if cur_major < major or (cur_major == major and cur_minor < minor ):
233+
234+ def cmdstan_version_before (major : int , minor : int ) -> bool :
235+ """
236+ Check that CmdStan version is less than Major.minor version.
237+
238+ :param major: Major version number
239+ :param minor: Minor version number
240+
241+
242+ :return: True if version at or above major.minor, else False.
243+ """
244+ cur_version = cmdstan_version ()
245+ if cur_version is None :
246+ get_logger ().info (
247+ 'Cannot determine whether version is before %d.%d.' , major , minor
248+ )
249+ return False
250+ if cur_version [0 ] < major or (
251+ cur_version [0 ] == major and cur_version [1 ] < minor
252+ ):
253253 return True
254254 return False
255255
0 commit comments