We already define local _sysstr() and _xrange() for compatibility, so
we should use those.
Also create a similar local _bytestr() corresponding to
pycompat.bytestr().
We already define local _sysstr() and _xrange() for compatibility, so
we should use those.
Also create a similar local _bytestr() corresponding to
pycompat.bytestr().
| Automatic diff as part of commit; lint not applicable. |
| Automatic diff as part of commit; unit tests not applicable. |
| Path | Packages | |||
|---|---|---|---|---|
| M | contrib/perf.py (12 lines) |
| Status | Author | Revision | |
|---|---|---|---|
| Closed | martinvonz | ||
| Closed | martinvonz | ||
| Closed | martinvonz |
| def identity(a): | def identity(a): | ||||
| return a | return a | ||||
| try: | try: | ||||
| from mercurial import pycompat | from mercurial import pycompat | ||||
| getargspec = pycompat.getargspec # added to module after 4.5 | getargspec = pycompat.getargspec # added to module after 4.5 | ||||
| _byteskwargs = pycompat.byteskwargs # since 4.1 (or fbc3f73dc802) | _byteskwargs = pycompat.byteskwargs # since 4.1 (or fbc3f73dc802) | ||||
| _sysstr = pycompat.sysstr # since 4.0 (or 2219f4f82ede) | _sysstr = pycompat.sysstr # since 4.0 (or 2219f4f82ede) | ||||
| _bytestr = pycompat.bytestr # since 4.2 (or b70407bd84d5) | |||||
| _xrange = pycompat.xrange # since 4.8 (or 7eba8f83129b) | _xrange = pycompat.xrange # since 4.8 (or 7eba8f83129b) | ||||
| fsencode = pycompat.fsencode # since 3.9 (or f4a5e0e86a7e) | fsencode = pycompat.fsencode # since 3.9 (or f4a5e0e86a7e) | ||||
| if pycompat.ispy3: | if pycompat.ispy3: | ||||
| _maxint = sys.maxsize # per py3 docs for replacing maxint | _maxint = sys.maxsize # per py3 docs for replacing maxint | ||||
| else: | else: | ||||
| _maxint = sys.maxint | _maxint = sys.maxint | ||||
| except (NameError, ImportError, AttributeError): | except (NameError, ImportError, AttributeError): | ||||
| import inspect | import inspect | ||||
| getargspec = inspect.getargspec | getargspec = inspect.getargspec | ||||
| _byteskwargs = identity | _byteskwargs = identity | ||||
| _bytestr = str | |||||
| fsencode = identity # no py3 support | fsencode = identity # no py3 support | ||||
| _maxint = sys.maxint # no py3 support | _maxint = sys.maxint # no py3 support | ||||
| _sysstr = lambda x: x # no py3 support | _sysstr = lambda x: x # no py3 support | ||||
| _xrange = xrange | _xrange = xrange | ||||
| try: | try: | ||||
| # 4.7+ | # 4.7+ | ||||
| queue = pycompat.queue.Queue | queue = pycompat.queue.Queue | ||||
| limits = [] | limits = [] | ||||
| for item in limitspec: | for item in limitspec: | ||||
| parts = item.split(b'-', 1) | parts = item.split(b'-', 1) | ||||
| if len(parts) < 2: | if len(parts) < 2: | ||||
| ui.warn((b'malformatted run limit entry, missing "-": %s\n' | ui.warn((b'malformatted run limit entry, missing "-": %s\n' | ||||
| % item)) | % item)) | ||||
| continue | continue | ||||
| try: | try: | ||||
| time_limit = float(pycompat.sysstr(parts[0])) | time_limit = float(_sysstr(parts[0])) | ||||
| except ValueError as e: | except ValueError as e: | ||||
| ui.warn((b'malformatted run limit entry, %s: %s\n' | ui.warn((b'malformatted run limit entry, %s: %s\n' | ||||
| % (pycompat.bytestr(e), item))) | % (_bytestr(e), item))) | ||||
| continue | continue | ||||
| try: | try: | ||||
| run_limit = int(pycompat.sysstr(parts[1])) | run_limit = int(_sysstr(parts[1])) | ||||
| except ValueError as e: | except ValueError as e: | ||||
| ui.warn((b'malformatted run limit entry, %s: %s\n' | ui.warn((b'malformatted run limit entry, %s: %s\n' | ||||
| % (pycompat.bytestr(e), item))) | % (_bytestr(e), item))) | ||||
| continue | continue | ||||
| limits.append((time_limit, run_limit)) | limits.append((time_limit, run_limit)) | ||||
| if not limits: | if not limits: | ||||
| limits = DEFAULTLIMITS | limits = DEFAULTLIMITS | ||||
| profiler = None | profiler = None | ||||
| if profiling is not None: | if profiling is not None: | ||||
| if ui.configbool(b"perf", b"profile-benchmark", False): | if ui.configbool(b"perf", b"profile-benchmark", False): | ||||
| def perfprogress(ui, topic=None, total=None, **opts): | def perfprogress(ui, topic=None, total=None, **opts): | ||||
| """printing of progress bars""" | """printing of progress bars""" | ||||
| opts = _byteskwargs(opts) | opts = _byteskwargs(opts) | ||||
| timer, fm = gettimer(ui, opts) | timer, fm = gettimer(ui, opts) | ||||
| def doprogress(): | def doprogress(): | ||||
| with ui.makeprogress(topic, total=total) as progress: | with ui.makeprogress(topic, total=total) as progress: | ||||
| for i in pycompat.xrange(total): | for i in _xrange(total): | ||||
| progress.increment() | progress.increment() | ||||
| timer(doprogress) | timer(doprogress) | ||||
| fm.end() | fm.end() | ||||