Content-Length: 579868 | pFad | http://github.com/python/pyperformance/commit/caf63ec5a3e8809dc8cb015236565d2efb6a12d4

65 Fix Manifest Group (#235) · python/pyperformance@caf63ec · GitHub
Skip to content

Commit caf63ec

Browse files
Fix Manifest Group (#235)
This addresses several of the problems noted in #234. Notably: * disallow groups named "all" * disallow duplicate group names, even if in different included manifests * disallow benchmarks named "all" * disallow duplicate benchmark names * clean up the "list_groups" command * fix how group resolution falls back to the tags
1 parent d1cb311 commit caf63ec

File tree

3 files changed

+60
-32
lines changed

3 files changed

+60
-32
lines changed

pyperformance/_manifest.py

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,12 @@ def benchmarks(self):
9696
@property
9797
def groups(self):
9898
names = self._custom_groups()
99-
if not names:
100-
names = set(self._get_tags())
10199
return names | {'all', 'default'}
102100

101+
@property
102+
def tags(self):
103+
return set(self._get_tags())
104+
103105
@property
104106
def filename(self):
105107
return self._raw_filename
@@ -117,25 +119,26 @@ def _add_section_for_file(self, filename, section, data, resolve, seen):
117119
if resolve is None and filename == DEFAULT_MANIFEST:
118120
resolve = resolve_default_benchmark
119121

120-
seen_key = (section, data[0]) if section == "group" else section
121-
if seen_key in seen:
122-
# For now each section_key can only show up once.
123-
raise NotImplementedError((seen_key, data))
124-
seen.add(seen_key)
125-
126-
if section == 'includes':
127-
pass
128-
elif section == 'benchmarks':
129-
entries = ((s, m, filename) for s, m in data)
130-
self._add_benchmarks(entries, resolve)
131-
elif section == 'groups':
132-
for name in data:
133-
self._add_group(name, None)
134-
elif section == 'group':
122+
if section == 'group':
135123
name, entries = data
136124
self._add_group(name, entries)
137125
else:
138-
raise NotImplementedError((section, data))
126+
# All sections with an identifier have already been handled.
127+
if section in seen:
128+
# For now each section_key can only show up once.
129+
raise NotImplementedError((section, data))
130+
seen.add(section)
131+
132+
if section == 'includes':
133+
pass
134+
elif section == 'benchmarks':
135+
entries = ((s, m, filename) for s, m in data)
136+
self._add_benchmarks(entries, resolve)
137+
elif section == 'groups':
138+
for name in data:
139+
self._add_group(name, None)
140+
else:
141+
raise NotImplementedError((section, data))
139142

140143
def _add_benchmarks(self, entries, resolve):
141144
for spec, metafile, filename in entries:
@@ -145,6 +148,8 @@ def _add_benchmarks(self, entries, resolve):
145148
def _add_benchmark(self, spec, metafile, resolve, filename):
146149
if spec.name in self._raw_groups:
147150
raise ValueError(f'a group and a benchmark have the same name ({spec.name})')
151+
if spec.name == 'all':
152+
raise ValueError('a benchmark named "all" is not allowed ("all" is reserved for selecting the full set of declared benchmarks)')
148153
if metafile:
149154
if filename:
150155
localdir = os.path.dirname(filename)
@@ -156,6 +161,8 @@ def _add_benchmark(self, spec, metafile, resolve, filename):
156161
self._raw_benchmarks.append((spec, metafile, filename))
157162
if resolve is not None:
158163
bench = resolve(bench)
164+
if bench.name in self._byname:
165+
raise ValueError(f'a benchmark named {bench.name} was already declared')
159166
self._byname[bench.name] = bench
160167
self._groups = None # Force re-resolution.
161168
self._tags = None # Force re-resolution.
@@ -164,18 +171,15 @@ def _add_group(self, name, entries):
164171
if name in self._byname:
165172
raise ValueError(f'a group and a benchmark have the same name ({name})')
166173
if name == 'all':
167-
# XXX Emit a warning?
168-
return
169-
if entries:
170-
raw = self._raw_groups.get(name)
171-
if raw is None:
172-
raw = self._raw_groups[name] = list(entries) if entries else None
173-
elif entries is not None:
174-
raw.extend(entries)
175-
elif name in self._raw_groups:
176-
return
177-
else:
174+
raise ValueError('a group named "all" is not allowed ("all" is reserved for selecting the full set of declared benchmarks)')
175+
if entries is None:
176+
if name in self._raw_groups:
177+
return
178178
self._raw_groups[name] = None
179+
elif name in self._raw_groups and self._raw_groups[name] is not None:
180+
raise ValueError(f'a group named {name} was already defined')
181+
else:
182+
self._raw_groups[name] = list(entries) if entries else []
179183
self._groups = None # Force re-resolution.
180184

181185
def _custom_groups(self):
@@ -218,7 +222,7 @@ def resolve_group(self, name, *, fail=True):
218222
groups = self._resolve_groups()
219223
benchmarks = groups.get(name)
220224
if not benchmarks:
221-
if name in (set(self._raw_groups) - {'default'}):
225+
if name not in self._raw_groups:
222226
benchmarks = self._get_tags().get(name, ())
223227
elif fail:
224228
raise KeyError(name)

pyperformance/cli.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ def parse_args():
108108
'list_groups', help='List benchmark groups of the running Python')
109109
cmds.append(cmd)
110110
cmd.add_argument("--manifest", help="benchmark manifest file to use")
111+
cmd.add_argument("--tags", action="store_true")
112+
cmd.add_argument("--no-tags", dest="tags", action="store_false")
113+
cmd.set_defaults(tags=True)
111114

112115
# compile
113116
cmd = subparsers.add_parser(
@@ -302,7 +305,7 @@ def _main():
302305
cmd_list(options, benchmarks)
303306
elif options.action == 'list_groups':
304307
manifest = _manifest_from_options(options)
305-
cmd_list_groups(manifest)
308+
cmd_list_groups(manifest, showtags=options.tags)
306309
else:
307310
parser.print_help()
308311
sys.exit(1)

pyperformance/commands.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def cmd_list(options, benchmarks):
1111
print("Total: %s benchmarks" % len(benchmarks))
1212

1313

14-
def cmd_list_groups(manifest):
14+
def cmd_list_groups(manifest, *, showtags=True):
1515
all_benchmarks = set(manifest.benchmarks)
1616

1717
groups = sorted(manifest.groups - {'all', 'default'})
@@ -28,6 +28,27 @@ def cmd_list_groups(manifest):
2828
print("- %s" % spec.name)
2929
print()
3030

31+
if showtags:
32+
print("=============================")
33+
print()
34+
print("tags:")
35+
print()
36+
tags = sorted(manifest.tags or ())
37+
if not tags:
38+
print("(no tags)")
39+
else:
40+
for tag in tags:
41+
specs = list(manifest.resolve_group(tag))
42+
known = set(specs) & all_benchmarks
43+
if not known:
44+
# skip empty groups
45+
continue
46+
47+
print("%s (%s):" % (tag, len(specs)))
48+
for spec in sorted(specs):
49+
print("- %s" % spec.name)
50+
print()
51+
3152

3253
def cmd_venv_create(options, root, python, benchmarks):
3354
from . import _pythoninfo, _venv

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/python/pyperformance/commit/caf63ec5a3e8809dc8cb015236565d2efb6a12d4

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy