update-python-libraries: skip replacing 'rev' when set to variable

It's common for fetchFromGitHub to have `rev = version;`, in which
it will inherit the version. So no replacement is required.

authored by

Jonathan Ringer and committed by
Jonathan Ringer
b316efff ce0a9077

+13 -3
+13 -3
pkgs/development/interpreters/python/update-python-libraries/update-python-libraries.py
··· 350 350 text = _replace_value('hash', sri_hash, text) 351 351 352 352 if fetcher == 'fetchFromGitHub': 353 - text = _replace_value('rev', f"{prefix}${{version}}", text) 354 - # incase there's no prefix, just rewrite without interpolation 355 - text = text.replace('"${version}";', 'version;') 353 + # in the case of fetchFromGitHub, it's common to see `rev = version;` 354 + # in which no string value is meant to be substituted. 355 + # Verify that the attribute is set to a variable 356 + regex = '(rev\s+=\s+([_a-zA-Z][_a-zA-Z0-9\.]*);)' 357 + regex = re.compile(regex) 358 + value = regex.findall(text) 359 + n = len(value) 360 + 361 + if n == 0: 362 + # value is set to a string, e.g. `rev = "v${version}";` 363 + text = _replace_value('rev', f"{prefix}${{version}}", text) 364 + # incase there's no prefix, just rewrite without interpolation 365 + text = text.replace('"${version}";', 'version;') 356 366 357 367 with open(path, 'w') as f: 358 368 f.write(text)