spcomp_util.py 536 B

12345678910111213141516
  1. #!/usr/bin/python3
  2. import subprocess
  3. import io
  4. def extract_version(spcomp):
  5. """
  6. Extract version string from caption in SourcePawn compiler into a tuple.
  7. The string is hardcoded in `setcaption(void)` in `sourcepawn/compiler/parser.cpp`
  8. """
  9. p = subprocess.Popen([spcomp], stdout=subprocess.PIPE)
  10. caption = io.TextIOWrapper(p.stdout, encoding="utf-8").readline()
  11. # extracts last element from output in format "SourcePawn Compiler major.minor.rev.patch"
  12. *_, version = caption.split()
  13. return tuple(map(int, version.split('.')))