020-python-version.patch 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. --- a/pygnulib/functions.py
  2. +++ b/pygnulib/functions.py
  3. @@ -16,6 +16,8 @@
  4. from __future__ import annotations
  5. import os.path
  6. +import re
  7. +import subprocess as sp
  8. from .constants import substart
  9. from .GLConfig import GLConfig
  10. @@ -50,3 +52,15 @@ def rewrite_file_name(file_name: str, co
  11. else: # file is not a special file
  12. result = file_name
  13. return os.path.normpath(result)
  14. +
  15. +def get_version(app: str) -> str:
  16. + result = sp.run([app, '--version'], capture_output=True, text=True)
  17. + version = re.sub(r".*[v ]([0-9])", r"\1", result.stdout)
  18. + version_lines = [line for line in version.splitlines() if re.search(r"^[0-9]", line)]
  19. + version = '\n'.join(version_lines) + "\n"
  20. + version = re.sub(r"[^.a-z0-9-\n].*", r"", version)
  21. + version = re.sub(r"^([0-9]*)[a-z-].*", r"\1", version, 1)
  22. + version = re.sub(r"\.0*([1-9])", r".\1", version)
  23. + version_lines = [line for line in version.splitlines() if line.strip()]
  24. + version = ''.join(version_lines[0]) + "\n"
  25. + return version.strip()
  26. --- a/pygnulib/GLImport.py
  27. +++ b/pygnulib/GLImport.py
  28. @@ -40,6 +40,7 @@ from .constants import (
  29. rmtree,
  30. )
  31. from .functions import rewrite_file_name
  32. +from .functions import get_version
  33. from .GLError import GLError
  34. from .GLConfig import GLConfig
  35. from .GLModuleSystem import GLModuleTable
  36. @@ -125,7 +126,8 @@ class GLImport:
  37. for version in versions })
  38. self.config.setAutoconfVersion(version)
  39. if version < 2.64:
  40. - raise GLError(4, version)
  41. + # If the version of autoconf in use is high enough, do not error.
  42. + if float(get_version('autoconf')) < 2.64: raise GLError(4, version)
  43. # Get other cached variables.
  44. path = joinpath(self.config['m4base'], 'gnulib-cache.m4')