forked from CJ-Wright/cf-graph-countyfair
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_version.py
59 lines (55 loc) · 1.8 KB
/
update_version.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
from conda_forge_tick.utils import load_graph
from conda_forge_tick.update_upstream_versions import (
get_latest_version,
PyPI,
CRAN,
NPM,
ROSDistro,
RawURL,
Github,
)
import random
import json
sources = (PyPI(), CRAN(), NPM(), ROSDistro(), RawURL(), Github())
print("Reading graph")
gx = load_graph()
_all_nodes = [t for t in gx.nodes.items()]
random.shuffle(_all_nodes)
# Inspection the graph object and node update:
print(f"Number of nodes: {len(gx.nodes)}")
Node_count = 0
to_update = {}
to_update["nodes"] = []
for node, node_attrs in _all_nodes:
# checking each node
with node_attrs["payload"] as attrs:
# verify the actual situation of the package;
actual_ver = str(attrs.get("version"))
if attrs.get("bad") or attrs.get("archived"):
print(
f"# {Node_count:<5} - {node:<30} - ver: {actual_ver:<10} - bad/archived"
)
Node_count += 1
continue
# New verison request
try:
new_version = get_latest_version(node, attrs, sources)
except Exception as e:
try:
se = repr(e)
except Exception as ee:
se = "Bad exception string: {}".format(ee)
print(f"Warning: Error getting upstream version of {node}: {se}")
if new_version == actual_ver:
# Not a good way to check this though...
Node_count += 1
continue
else:
print(
f"# {Node_count:<5} - {node:<30} - ver: {attrs.get('version'):<10} - new ver: {new_version}"
)
to_update["nodes"].append({"id": str(node), "version": str(new_version)})
Node_count += 1
# Writing out file
with open("new_version.json", "w") as outfile:
json.dump(to_update, outfile)