aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/set_version.py
blob: 6a644894a9061c7b37d5d050ddb3da0cdc1c82ec (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""Script to set the version number wherever it's needed before a release."""

from __future__ import unicode_literals, print_function
import io
import os
import re
import sys
import glob


def sed_like_thing(pattern, repl, path):
    """Like re.sub but applies to a file instead of a string."""

    with io.open(path, 'r', encoding='utf8') as inf:
        data = inf.read()

    data = re.sub(pattern, repl, data)

    with io.open(path, 'w+', encoding='utf8') as outf:
        outf.write(data)

if __name__ == "__main__":
    inpf = raw_input if sys.version_info[0] == 2 else input
    version = inpf("New version number (in format X.Y.Z): ").strip()

    for doc in glob.glob(os.path.join("docs/*.txt")):
        sed_like_thing(":Version: .*", ":Version: {0}".format(version), doc)

    sed_like_thing("version='.+'", "version='{0}'".format(version), 'setup.py')
    sed_like_thing("version = '.+'", "version = '{0}'".format(version), os.path.join('docs', 'sphinx', 'conf.py'))
    sed_like_thing("release = '.+'", "release = '{0}'".format(version), os.path.join('docs', 'sphinx', 'conf.py'))
    sed_like_thing('__version__ = ".*"', '__version__ = "{0}"'.format(version), os.path.join('nikola', '__init__.py'))
    sed_like_thing('New in master', 'New in v{0}'.format(version), 'CHANGES.txt')
    os.system("help2man -h help -N --version-string='{0}' nikola > {1}".format(version, os.path.join('docs', 'man', 'nikola.1')))