update_version.py 2.26 KB
Newer Older
Minjie Wang's avatar
Minjie Wang committed
1
2
3
4
5
6
7
8
9
10
"""
This is the global script that set the version information of DGL.
This script runs and update all the locations that related to versions
List of affected files:
- dgl-root/python/dgl/_ffi/libinfo.py
- dgl-root/include/dgl/runtime/c_runtime_api.h
- dgl-root/conda/dgl/meta.yaml
"""
import os
import re
11

Minjie Wang's avatar
Minjie Wang committed
12
13
14
# current version
# We use the version of the incoming release for code
# that is under development
Quan (Andy) Gan's avatar
Quan (Andy) Gan committed
15
16
17
18
# The environment variable DGL_PRERELEASE is the prerelase suffix
# (usually "aYYMMDD")
# The environment variable DGL_VERSION_SUFFIX is the local version label
# suffix for indicating CPU and CUDA versions as in PEP 440 (e.g. "+cu102")
19

20
__version__ = "2.2.1" + os.getenv("DGL_PRERELEASE", "")
21
22


Quan (Andy) Gan's avatar
Quan (Andy) Gan committed
23
__version__ += os.getenv("DGL_VERSION_SUFFIX", "")
24
print(__version__)
Minjie Wang's avatar
Minjie Wang committed
25
26

# Implementations
27
28


Minjie Wang's avatar
Minjie Wang committed
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
def update(file_name, pattern, repl):
    update = []
    hit_counter = 0
    need_update = False
    for l in open(file_name):
        result = re.findall(pattern, l)
        if result:
            assert len(result) == 1
            hit_counter += 1
            if result[0] != repl:
                l = re.sub(pattern, repl, l)
                need_update = True
                print("%s: %s->%s" % (file_name, result[0], repl))
            else:
                print("%s: version is already %s" % (file_name, repl))

        update.append(l)
    if hit_counter != 1:
        raise RuntimeError("Cannot find version in %s" % file_name)

    if need_update:
        with open(file_name, "w") as output_file:
            for l in update:
                output_file.write(l)


def main():
    curr_dir = os.path.dirname(os.path.abspath(os.path.expanduser(__file__)))
    proj_root = os.path.abspath(os.path.join(curr_dir, ".."))
    # python path
59
60
    update(
        os.path.join(proj_root, "python", "dgl", "_ffi", "libinfo.py"),
Quan (Andy) Gan's avatar
Quan (Andy) Gan committed
61
        r"(?<=__version__ = \")[.0-9a-z+_]+",
62
63
        __version__,
    )
Minjie Wang's avatar
Minjie Wang committed
64
    # C++ header
65
    update(
66
        os.path.join(proj_root, "include", "dgl", "runtime", "c_runtime_api.h"),
Quan (Andy) Gan's avatar
Quan (Andy) Gan committed
67
        '(?<=DGL_VERSION ")[.0-9a-z+_]+',
68
69
        __version__,
    )
Minjie Wang's avatar
Minjie Wang committed
70
71
    # conda
    for path in ["dgl"]:
72
73
        update(
            os.path.join(proj_root, "conda", path, "meta.yaml"),
74
            "(?<=version: )[.0-9a-z+_]+",
75
76
            __version__,
        )
Minjie Wang's avatar
Minjie Wang committed
77

78

Minjie Wang's avatar
Minjie Wang committed
79
80
if __name__ == "__main__":
    main()