__init__.py 1.97 KB
Newer Older
1
2
3
4
5
6
7

import json
import os.path
import subprocess
import sys


8
def setup_if_needed(this_release):
9
    build_path = os.path.join(os.environ["PWD"], "_build")
10

11
12
13
14
15
16
17
18
19
    # Check whether we are on the same version of eHive
    is_same = False
    release_holder = os.path.join(build_path, "LAST_BUILD")
    if os.path.isfile(release_holder):
        with open(release_holder, "r") as fh:
            previous_release = fh.read()
        if previous_release == this_release:
            is_same = True

20
21
22
    # Install packages and setup environment
    on_rtd = os.environ.get("READTHEDOCS", None) == "True"
    if on_rtd:
23
24
        if not is_same:
            subprocess.check_call(["./rtd_upgrade.sh"], stdout=sys.stdout, stderr=sys.stderr)
25
26
27
28
29
        upgrade_path = os.environ["HOME"]
        deb_install_path = os.path.join(upgrade_path, "packages")
        os.environ["PERL5LIB"] = os.path.pathsep.join(os.path.join(deb_install_path, _) for _ in ["usr/share/perl5/", "usr/lib/x86_64-linux-gnu/perl5/5.22/", "usr/lib/x86_64-linux-gnu/perl5/5.22/auto/"])
        os.environ["PATH"] = os.path.join(deb_install_path, "usr/bin") + os.path.pathsep + os.environ["PATH"]
        os.environ["ENSEMBL_CVS_ROOT_DIR"] = upgrade_path
30
31
32
33
    else:
        os.environ["ENSEMBL_CVS_ROOT_DIR"]   # Will raise an error if missing
    os.environ["EHIVE_ROOT_DIR"] = os.path.join(os.environ["PWD"], os.path.pardir)
    os.environ["PERL5LIB"] = os.path.join(os.environ["EHIVE_ROOT_DIR"], "modules") + os.path.pathsep + os.environ["PERL5LIB"]
34
35

    # Doxygen
36
    mkdoxygen_path = os.path.join(os.environ["EHIVE_ROOT_DIR"], "scripts", "dev", "make_doxygen.pl")
37
    # Only run doxygen if it's missing
38
    doxygen_target = os.path.join(build_path, "doxygen")
39
    if (on_rtd and not is_same) or any(not os.path.exists(os.path.join(doxygen_target, _)) for _ in ["perl", "python3", "java"]):
40
41
        subprocess.check_call([mkdoxygen_path, doxygen_target])

42
43
44
    with open(release_holder, "w") as fh:
        print >> fh, this_release,

45
    return doxygen_target
46