This repository was archived by the owner on Jun 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathcheck_versions
executable file
·131 lines (102 loc) · 3.23 KB
/
check_versions
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
#!/usr/bin/env python
import yaml
import json
import re
import requests
import sys
from databrickslabs_jupyterlab.utils import execute, print_error
def load_env(path):
with open(path, "r") as fd:
env = yaml.safe_load(fd)
return env
def load_extensions(path):
with open(path, "r") as fd:
env = fd.read().split("\n")
result = []
for e in env:
parts = e.split("@")
if len(parts) == 3:
result.append(("@%s" % parts[1], parts[2]))
elif len(parts) == 2:
result.append((parts[0], parts[1]))
return result
def extract(libs, delim=">|=|<"):
def normalize(l):
result = [el for el in l if el != ""]
return result + [""] if len(result) == 1 else result[:2]
return [normalize(re.split(delim, lib)) for lib in libs if not isinstance(lib, dict)]
def extract_pip(libs):
pip = [lib for lib in libs if isinstance(lib, dict) and lib.get("pip", None) is not None]
if len(pip) == 1:
pip = extract(pip[0]["pip"])
return pip
def get_pypi_version(lib):
response = requests.get("https://pypi.python.org/pypi/%s/json" % lib)
if response.status_code == 200:
return response.json()["info"]["version"]
def get_conda_version(lib, channels):
cmd = ["conda", "search"]
for c in channels:
cmd += ["-c", c]
cmd += [lib, "--info", "--json"]
result = execute(cmd)
if result["returncode"] != 0:
print_error(result["stderr"])
return None
else:
return json.loads(result["stdout"])[lib.replace("conda-forge::", "")][-1]
def get_npm_version(ext):
cmd = ["npm", "show", ext, "version"]
result = execute(cmd)
if result["returncode"] != 0:
print_error(result["stderr"])
return None
else:
return result["stdout"].strip()
def compare_conda(deps):
print("conda packages")
print("==============")
for lib, version in deps:
response = get_conda_version(lib, channels)
conda_version = response["version"]
if version == conda_version:
print("%s ok" % lib)
else:
print("%s (%s) => %s" % (lib, version, conda_version))
print()
def compare_pip(pips):
print("pip packages")
print("============")
for lib, version in pips:
pypi_version = get_pypi_version(lib)
if version == pypi_version:
print("%s ok" % lib)
else:
print("%s (%s) => %s" % (lib, version, pypi_version))
print()
def decode(text):
if isinstance(text, str):
return text
else:
return text.decode("utf-8", "replace")
def compare_ext(exts):
print("extensions")
print("==========")
for ext, version in exts:
npm_version = decode(get_npm_version(ext))
if version == npm_version:
print("%s ok" % ext)
else:
print("%s (%s) => %s" % (ext, version, npm_version))
print()
if len(sys.argv) < 2:
print("Usage: check_versions <env-file-name>")
else:
env = load_env(sys.argv[1])
channels = env["channels"]
deps = extract(env["dependencies"])
pips = extract_pip(env["dependencies"])
exts = load_extensions("labextensions.txt")
compare_conda(deps)
compare_pip(pips)
compare_ext(exts)