4343 version string from the specified URI, in order to fill out the reported
4444 :attr:`~buildstream.source.SourceInfo.version_guess`.
4545
46- The URI will be *searched* using this regular expression, and is allowed to
47- yield a number of *groups*. For example the value ``(\\ d+)_(\\ d+)_(\\ d+)`` would
48- report 3 *groups* if 3 numerical values separated by underscores were found in
49- the URI.
50-
51- The default value for ``version-guess-pattern`` is ``\\ d+\\ .\\ d+(?:\\ .\\ d+)?``.
46+ This is done using the :func:`utils.guess_version() <buildstream.utils.guess_version>`
47+ utility function, please refer to that function documentation to understand how
48+ the guessing mechanics works, and what kind of string you should provide here.
5249
5350 .. note:
5451
@@ -140,7 +137,7 @@ def translate_url(
140137for which it reports the sha256 checksum of the remote file content as the *version*.
141138
142139An attempt to guess the version based on the remote filename will be made
143- for the reporting of the *guess_version *. Control over how the guess is made
140+ for the reporting of the *version_guess *. Control over how the guess is made
144141or overridden is explained above in the
145142:ref:`built-in functionality documentation <core_downloadable_source_builtins>`.
146143"""
@@ -268,7 +265,6 @@ class DownloadableFileSource(Source):
268265 COMMON_CONFIG_KEYS = Source .COMMON_CONFIG_KEYS + ["url" , "ref" , "version-guess-pattern" , "version" ]
269266
270267 __default_mirror_file = None
271- __default_guess_pattern = re .compile (r"\d+\.\d+(?:\.\d+)?" )
272268
273269 def configure (self , node ):
274270 self .original_url = node .get_str ("url" )
@@ -281,9 +277,8 @@ def configure(self, node):
281277 self ._mirror_dir = os .path .join (self .get_mirror_directory (), utils .url_directory_name (self .original_url ))
282278
283279 self ._guess_pattern_string = node .get_str ("version-guess-pattern" , None )
284- if self ._guess_pattern_string is None :
285- self ._guess_pattern = self .__default_guess_pattern
286- else :
280+ self ._guess_pattern = None
281+ if self ._guess_pattern_string is not None :
287282 self ._guess_pattern = re .compile (self ._guess_pattern_string )
288283
289284 self ._version = node .get_str ("version" , None )
@@ -298,7 +293,7 @@ def get_unique_key(self):
298293 # attributes which affect SourceInfo generation.
299294 if self ._version is not None :
300295 unique_key .append (self ._version )
301- elif self ._guess_pattern is not self . __default_guess_pattern :
296+ elif self ._guess_pattern_string is not None :
302297 unique_key .append (self ._guess_pattern_string )
303298
304299 return unique_key
@@ -352,16 +347,9 @@ def fetch(self): # pylint: disable=arguments-differ
352347 )
353348
354349 def collect_source_info (self ):
355- if self ._version is None :
356- version_match = self ._guess_pattern .search (self .original_url )
357- if not version_match :
358- version_guess = None
359- elif self ._guess_pattern .groups == 0 :
360- version_guess = version_match .group (0 )
361- else :
362- version_guess = "." .join (version_match .groups ())
363- else :
364- version_guess = self ._version
350+ version_guess = self ._version
351+ if version_guess is None :
352+ version_guess = utils .guess_version (self .original_url , pattern = self ._guess_pattern )
365353
366354 return [
367355 self .create_source_info (
0 commit comments