-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.py
132 lines (100 loc) · 3.38 KB
/
deploy.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import os
import sys
import json
import subprocess
from gitz import git
# Ensure Rez is reachable
try:
subprocess.check_output(["rez-build", "-h"])
except OSError:
print("Rez not found. Is rez bin in $PATH ?")
sys.exit(1)
# GitHub repository inventory
with open("inventory.json", "r") as inventory:
pkg_repos = json.load(inventory)
# Cache installed package family names
try:
installed_packages = set(
subprocess.check_output(
["rez-search"],
universal_newlines=True,
stderr=subprocess.DEVNULL,
).split()
)
except subprocess.CalledProcessError:
installed_packages = set()
def is_installed(name):
return name in installed_packages
def bind_os(release=False):
if is_installed("os"):
return
if release:
subprocess.check_call(["rez-bind", "--release", "os"])
else:
subprocess.check_call(["rez-bind", "os"])
installed_packages.add("os")
def install_rez(release=False):
if is_installed("rez"):
return
if release:
subprocess.check_call(["rez-release"], cwd="rezpkg")
else:
subprocess.check_call(["rez-build", "--install"], cwd="rezpkg")
installed_packages.add("rez")
def git_build(data, release=False):
name = data["rez_name"]
if is_installed(name):
# This deploy script currently meant for fresh install, not for
# version update. So no versions check.
print("Rez package %s exists, skipping." % name)
return
def _git_build(build_options):
git.build(data["clone_url"],
clone_dst="build/%s" % data["name"],
install=True,
release=release,
build_options=build_options)
print("Installing %s .." % name)
setups_json = "setups/%s.json" % name
if os.path.isfile(setups_json):
# The requirement was listed by `rez-context --so`
with open(setups_json, "r") as fp:
setups = json.load(fp)
print(" has setups...")
for arg in setups:
for dep_pkg in arg["requires"]:
git_build(pkg_repos[dep_pkg], release)
_git_build(build_options=arg["options"])
else:
_git_build(build_options=None)
installed_packages.add(name)
def deploy_package(names, release=False):
# Installing essential packages
# os, arch, platform
bind_os(release)
# rez itself as package
install_rez(release)
# default, for packages that has no variants
git_build(pkg_repos["default"], release)
# rezutil, for building other rez packages
git_build(pkg_repos["rezutil"], release)
# rezcore, for building other rez packages
git_build(pkg_repos["rezcore"], release)
# python
git_build(pkg_repos["python"], release)
# pipz, for pypi packages
git_build(pkg_repos["pipz"], release)
# Installing demand packages
for data in [pkg_repos[n] for n in names]:
git_build(data, release)
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("packages", nargs="*",
help="Package names to deploy.")
parser.add_argument("--release", action="store_true",
help="Deploy to package releasing location.")
opt = parser.parse_args()
deploy_package(opt.packages, opt.release)
print("=" * 30)
print("SUCCESS!\n")