##// END OF EJS Templates
config: gather the path to edit through rcutil...
config: gather the path to edit through rcutil Using the common logic helps to reduce potential error when it changes

File last commit:

r49730:6000f5b2 default
r53324:8c509a70 default
Show More
check-perf-code.py
92 lines | 2.6 KiB | text/x-python | PythonLexer
/ tests / check-perf-code.py
Gregory Szorc
global: use python3 in shebangs...
r46434 #!/usr/bin/env python3
FUJIWARA Katsunori
tests: introduce check-perf-code.py to add extra checks on perf.py...
r29570 #
# check-perf-code - (historical) portability checker for contrib/perf.py
import os
import sys
# write static check patterns here
perfpypats = [
Augie Fackler
formatting: blacken the codebase...
r43346 [
(
r'(branchmap|repoview|repoviewutil)\.subsettable',
"use getbranchmapsubsettable() for early Mercurial",
),
(
r'\.(vfs|svfs|opener|sopener)',
"use getvfs()/getsvfs() for early Mercurial",
),
(
r'ui\.configint',
"use getint() instead of ui.configint() for early Mercurial",
),
],
# warnings
[],
FUJIWARA Katsunori
tests: introduce check-perf-code.py to add extra checks on perf.py...
r29570 ]
Augie Fackler
formatting: blacken the codebase...
r43346
FUJIWARA Katsunori
tests: check importing modules in perf.py for historical portability...
r29571 def modulewhitelist(names):
Augie Fackler
formatting: blacken the codebase...
r43346 replacement = [
('.py', ''),
('.c', ''), # trim suffix
('mercurial%s' % '/', ''), # trim "mercurial/" path
]
Martin von Zweigbergk
cleanup: use set literals...
r32291 ignored = {'__init__'}
FUJIWARA Katsunori
tests: check importing modules in perf.py for historical portability...
r29571 modules = {}
# convert from file name to module name, and count # of appearances
for name in names:
name = name.strip()
for old, new in replacement:
name = name.replace(old, new)
if name not in ignored:
modules[name] = modules.get(name, 0) + 1
# list up module names, which appear multiple times
whitelist = []
for name, count in modules.items():
if count > 1:
whitelist.append(name)
return whitelist
Augie Fackler
formatting: blacken the codebase...
r43346
FUJIWARA Katsunori
tests: introduce check-perf-code.py to add extra checks on perf.py...
r29570 if __name__ == "__main__":
FUJIWARA Katsunori
tests: check importing modules in perf.py for historical portability...
r29571 # in this case, it is assumed that result of "hg files" at
# multiple revisions is given via stdin
whitelist = modulewhitelist(sys.stdin)
assert whitelist, "module whitelist is empty"
# build up module whitelist check from file names given at runtime
perfpypats[0].append(
# this matching pattern assumes importing modules from
# "mercurial" package in the current style below, for simplicity
#
# from mercurial import (
# foo,
# bar,
# baz
# )
Augie Fackler
formatting: blacken the codebase...
r43346 (
(
r'from mercurial import [(][a-z0-9, \n#]*\n(?! *%s,|^[ #]*\n|[)])'
% ',| *'.join(whitelist)
),
"import newer module separately in try clause for early Mercurial",
)
)
FUJIWARA Katsunori
tests: check importing modules in perf.py for historical portability...
r29571
FUJIWARA Katsunori
tests: introduce check-perf-code.py to add extra checks on perf.py...
r29570 # import contrib/check-code.py as checkcode
assert 'RUNTESTDIR' in os.environ, "use check-perf-code.py in *.t script"
contribpath = os.path.join(os.environ['RUNTESTDIR'], '..', 'contrib')
sys.path.insert(0, contribpath)
checkcode = __import__('check-code')
# register perf.py specific entry with "checks" in check-code.py
Augie Fackler
formatting: blacken the codebase...
r43346 checkcode.checks.append(
('perf.py', r'contrib/perf.py$', '', checkcode.pyfilters, perfpypats)
)
FUJIWARA Katsunori
tests: introduce check-perf-code.py to add extra checks on perf.py...
r29570
sys.exit(checkcode.main())