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