-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstatus
More file actions
executable file
·228 lines (191 loc) · 6.16 KB
/
status
File metadata and controls
executable file
·228 lines (191 loc) · 6.16 KB
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/usr/bin/env python
# Copyright 2017-2018 TensorHub, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import absolute_import
from __future__ import division
import os
import re
import subprocess
import sys
here = os.path.dirname(__file__)
guild_peer = os.path.join(here, "..", "guild")
if os.path.exists(guild_peer):
sys.path.append(guild_peer)
from guild import cli
from guild import guildfile
class Pkg(object):
def __init__(self):
self.local_pkg = None
self.local_extra = []
self.release = None
self.issues = []
def add_local_pkg(self, local_pkg):
if self.local_pkg is None:
self.local_pkg = local_pkg
else:
self.local_extra.append(local_pkg)
@property
def name(self):
if self.local_pkg:
return self.local_pkg.name
else:
assert self.release
return self.release.name
@property
def local_version(self):
if self.local_pkg:
return self.local_pkg.version
else:
return ""
@property
def release_version(self):
if self.release:
return self.release.version
else:
return ""
@property
def models(self):
if self.local_pkg:
return self.local_pkg.guildfile.models
else:
return {}
class Release(object):
def __init__(self, name, version):
self.name = name
self.version = version
class Issues(object):
def __init__(self):
self.issues = []
def add(self, pkg, issue):
try:
i0 = self.issues.index(issue)
except ValueError:
i0 = len(self.issues)
self.issues.append(issue)
pkg.issues.append(i0 + 1)
def __nonzero__(self):
return bool(self.issues)
def __iter__(self):
for i in range(len(self.issues)):
yield i + 1, self.issues[i]
def main():
local_pkgs = _iter_local_pkgs()
releases = _iter_releases()
pkgs = {}
issues = Issues()
_apply_local_pkgs(local_pkgs, pkgs)
_apply_releases(releases, pkgs)
_check_pkgs(pkgs, issues)
formatted, cols = _format_table_data(pkgs, issues)
header = { col: col for col in cols}
cli.table([header] + formatted, cols)
if issues:
cli.out()
for i, issue in issues:
cli.out(cli.style("[%i] " % i, fg="red"), nl=False)
cli.out(issue)
def _iter_releases():
out = subprocess.check_output(["pip", "search", "gpkg"])
for line in out.split("\n"):
m = re.match(r"(.+?) \((.+?)\)", line)
if m and m.group(1).startswith("gpkg."):
yield m.group(1)[5:], m.group(2)
def _iter_local_pkgs():
skip_dirs = [
re.compile(r".git$"),
re.compile(r"build$"),
re.compile(r"dist$"),
re.compile(r"\.egg-info$"),
]
for root, dirs, files in os.walk(here):
_remove_dirs(dirs, skip_dirs)
if "guild.yml" in files:
gf = guildfile.from_dir(root)
if gf.package:
yield gf.package
def _remove_dirs(dirs, to_remove):
for pattern in to_remove:
for dir in list(dirs):
if pattern.match(dir):
dirs.remove(dir)
def _apply_local_pkgs(local_pkgs, pkgs):
for local_pkg in local_pkgs:
pkg = pkgs.setdefault(local_pkg.name, Pkg())
pkg.add_local_pkg(local_pkg)
def _apply_releases(releases, pkgs):
releases = list(releases)
for rel in releases:
name, version = rel
pkg = pkgs.setdefault(name, Pkg())
assert pkg.release is None, pkg.release
pkg.release = Release(name, version)
def _check_pkgs(pkgs, issues):
for pkg in pkgs.values():
_check_multiple_packages(pkg, issues)
_check_missing_local(pkg, issues)
_check_release_version(pkg, issues)
_check_build(pkg, issues)
_check_readme(pkg, issues)
def _check_multiple_packages(pkg, issues):
if pkg.local_extra:
dirs = [_local_pkg_dir(local_pkg) for local_pkg in pkg.local_extra]
issues.add(pkg, "multiple packages: %s" % ", ".join(dirs))
def _check_missing_local(pkg, issues):
if pkg.release and not pkg.local_pkg:
issues.add(pkg, "missing local package")
def _check_release_version(pkg, issues):
if (pkg.local_pkg and pkg.release and
pkg.local_pkg.version != pkg.release.version):
issues.add(pkg, "version mismatch")
def _check_build(pkg, issues):
if pkg.local_pkg:
if not os.path.exists(_local_pkg_file(pkg.local_pkg, "Makefile")):
issues.add(pkg, "missing Makefile")
def _check_readme(pkg, issues):
if pkg.local_pkg:
if not os.path.exists(_local_pkg_file(pkg.local_pkg, "README.md")):
issues.add(pkg, "missing README.md")
def _local_pkg_dir(local_pkg):
return os.path.relpath(local_pkg.guildfile.dir)
def _local_pkg_file(local_pkg, file):
return os.path.join(_local_pkg_dir(local_pkg), file)
def _format_table_data(data, issues):
rows = [
_format_pkg_row(data[name])
for name in sorted(data)
]
cols = [
"package",
"local version",
"released version",
"models",
"issues",
]
return rows, cols
def _format_pkg_row(pkg):
return {
"package": pkg.name,
"local version": pkg.local_version,
"released version": pkg.release_version,
"models": len(pkg.models),
"issues": _format_pkg_issues(pkg),
}
def _format_pkg_issues(pkg):
if pkg.issues:
list_str = ",".join([str(i) for i in sorted(pkg.issues)])
return cli.style("[%s]" % list_str, fg="red")
else:
return ""
if __name__ == "__main__":
main()