forked from AnacondaRecipes/repodata-hotfixes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pro.py
172 lines (140 loc) · 4.8 KB
/
pro.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function, unicode_literals
from collections import defaultdict
import json
import os
from os.path import join, dirname, isfile, isdir
import sys
import requests
CHANNEL_NAME = "pro"
CHANNEL_ALIAS = "https://repo.anaconda.com/pkgs"
SUBDIRS = (
"noarch",
"linux-32",
"linux-64",
"linux-aarch64",
"linux-armv6l",
"linux-armv7l",
"linux-ppc64le",
"osx-64",
"win-32",
"win-64",
)
REMOVALS = {
"linux-64": (
),
"osx-64": (
),
"win-32": (
),
"win-64": (
),
}
EXTERNAL_DEPENDENCIES = {
"argparse": "python:argparse",
"bitarray": "python:bitarray",
"boost": "python:boost",
"boto": "python:boto",
"cffi": "python:cffi",
"jupyter": "python:jupyter",
"libgfortran": "global:libgfortran",
"libpostgres": "global:libpostgres",
"libpq": "global:libpq",
"libthrift": "global:libthrift",
"llvmlite": "python:llvmlite",
"llvmpy": "python:llvmpy",
"mongo-driver": "global:mongo-driver",
"nose": "python:nose",
"numba": "python:numba",
"numbapro_cudalib": "python:numbapro_cudalib",
"openssl": "global:openssl",
"ordereddict": "python:ordereddict",
"pandas": "python:pandas",
"pcre": "global:pcre",
"readline": "global:readline",
"six": "python:six",
"snakeviz": "python:snakeviz",
"sqlite": "global:sqlite",
"system": "global:system",
"thrift": "python:thrift",
"unixodbc": "global:unixodbc",
"zlib": "global:zlib",
}
NAMESPACE_IN_NAME_SET = {
}
NAMESPACE_OVERRIDES = {
"mkl": "global",
}
def _patch_repodata(repodata, subdir):
index = repodata["packages"]
instructions = {
"patch_instructions_version": 1,
"packages": defaultdict(dict),
"revoke": [],
"remove": [],
}
instructions["remove"].extend(REMOVALS.get(subdir, ()))
if subdir == "noarch":
instructions["external_dependencies"] = EXTERNAL_DEPENDENCIES
def rename_dependency(fn, record, old_name, new_name):
depends = record["depends"]
dep_idx = next(
(q for q, dep in enumerate(depends) if dep.split(' ')[0] == old_name),
None
)
if dep_idx:
parts = depends[dep_idx].split(" ")
remainder = (" " + " ".join(parts[1:])) if len(parts) > 1 else ""
depends[dep_idx] = new_name + remainder
instructions["packages"][fn]['depends'] = depends
for fn, record in index.items():
record_name = record["name"]
if record_name in NAMESPACE_IN_NAME_SET and not record.get('namespace_in_name'):
# set the namespace_in_name field
instructions["packages"][fn]['namespace_in_name'] = True
if NAMESPACE_OVERRIDES.get(record_name):
# explicitly set namespace
instructions["packages"][fn]['namespace'] = NAMESPACE_OVERRIDES[record_name]
return instructions
def _extract_and_remove_vc_feature(record):
features = record.get('features', '').split()
vc_features = tuple(f for f in features if f.startswith('vc'))
if not vc_features:
return None
non_vc_features = tuple(f for f in features if f not in vc_features)
vc_version = int(vc_features[0][2:]) # throw away all but the first
if non_vc_features:
record['features'] = ' '.join(non_vc_features)
else:
del record['features']
return vc_version
def do_hotfixes(base_dir):
# Step 1. Collect initial repodata for all subdirs.
repodatas = {}
for subdir in SUBDIRS:
repodata_path = join(base_dir, subdir, 'repodata-clone.json')
if isfile(repodata_path):
with open(repodata_path) as fh:
repodatas[subdir] = json.load(fh)
else:
repodata_url = "/".join((CHANNEL_ALIAS, CHANNEL_NAME, subdir, "repodata.json"))
response = requests.get(repodata_url)
response.raise_for_status()
repodatas[subdir] = response.json()
if not isdir(dirname(repodata_path)):
os.makedirs(dirname(repodata_path))
with open(repodata_path, 'w') as fh:
json.dump(repodatas[subdir], fh, indent=2, sort_keys=True, separators=(',', ': '))
# Step 2. Create all patch instructions.
patch_instructions = {}
for subdir in SUBDIRS:
instructions = _patch_repodata(repodatas[subdir], subdir)
patch_instructions_path = join(base_dir, subdir, "patch_instructions.json")
with open(patch_instructions_path, 'w') as fh:
json.dump(instructions, fh, indent=2, sort_keys=True, separators=(',', ': '))
patch_instructions[subdir] = instructions
def main():
base_dir = join(dirname(__file__), CHANNEL_NAME)
do_hotfixes(base_dir)
if __name__ == "__main__":
sys.exit(main())