versioninfo.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import io
  2. import os
  3. import re
  4. import sys
  5. __LXML_VERSION = None
  6. def version():
  7. global __LXML_VERSION
  8. if __LXML_VERSION is None:
  9. with open(os.path.join(get_base_dir(), 'src', 'lxml', '__init__.py')) as f:
  10. __LXML_VERSION = re.search(r'__version__\s*=\s*"([^"]+)"', f.read(250)).group(1)
  11. assert __LXML_VERSION
  12. return __LXML_VERSION
  13. def branch_version():
  14. return version()[:3]
  15. def is_pre_release():
  16. version_string = version()
  17. return "a" in version_string or "b" in version_string
  18. def dev_status():
  19. _version = version()
  20. if 'a' in _version:
  21. return 'Development Status :: 3 - Alpha'
  22. elif 'b' in _version or 'c' in _version:
  23. return 'Development Status :: 4 - Beta'
  24. else:
  25. return 'Development Status :: 5 - Production/Stable'
  26. def changes():
  27. """Extract part of changelog pertaining to version.
  28. """
  29. _version = version()
  30. with io.open(os.path.join(get_base_dir(), "CHANGES.txt"), 'r', encoding='utf8') as f:
  31. lines = []
  32. for line in f:
  33. if line.startswith('====='):
  34. if len(lines) > 1:
  35. break
  36. if lines:
  37. lines.append(line)
  38. elif line.startswith(_version):
  39. lines.append(line)
  40. return ''.join(lines[:-1])
  41. def create_version_h():
  42. """Create lxml-version.h
  43. """
  44. lxml_version = version()
  45. # make sure we have a triple part version number
  46. parts = lxml_version.split('-')
  47. while parts[0].count('.') < 2:
  48. parts[0] += '.0'
  49. lxml_version = '-'.join(parts).replace('a', '.alpha').replace('b', '.beta')
  50. file_path = os.path.join(get_base_dir(), 'src', 'lxml', 'includes', 'lxml-version.h')
  51. # Avoid changing file timestamp if content didn't change.
  52. if os.path.isfile(file_path):
  53. with open(file_path, 'r') as version_h:
  54. if ('"%s"' % lxml_version) in version_h.read(100):
  55. return
  56. with open(file_path, 'w') as version_h:
  57. version_h.write('''\
  58. #ifndef LXML_VERSION_STRING
  59. #define LXML_VERSION_STRING "%s"
  60. #endif
  61. ''' % lxml_version)
  62. def get_base_dir():
  63. return os.path.abspath(os.path.dirname(sys.argv[0]))