/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to profile_imports.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2018-11-16 19:38:57 UTC
  • mfrom: (7143.16.21 even-more-cleanups)
  • Revision ID: breezy.the.bot@gmail.com-20181116193857-bs5oma2655sp55qu
Fix another dozen flake8 errors.

Merged from https://code.launchpad.net/~jelmer/brz/even-more-cleanups/+merge/358931

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
        _total_stack[_parent_stack[-1]].append(this_stack)
44
44
    _total_stack[this_stack] = []
45
45
    _parent_stack.append(this_stack)
46
 
    _info[this_stack] = [len(_parent_stack)-1, frame_name, frame_lineno, scope_name]
 
46
    _info[this_stack] = [len(_parent_stack) - 1, frame_name, frame_lineno,
 
47
                         scope_name]
47
48
 
48
49
    return this_stack
49
50
 
60
61
 
61
62
def log_stack_info(out_file, sorted=True, hide_fast=True):
62
63
    # Find all of the roots with import = 0
63
 
    out_file.write('%5s %5s %-40s @ %s:%s\n'
 
64
    out_file.write(
 
65
        '%5s %5s %-40s @ %s:%s\n'
64
66
        % ('cum', 'local', 'name', 'file', 'line'))
65
 
    todo = [(value[-1], key) for key,value in _info.items() if value[0] == 0]
 
67
    todo = [(value[-1], key) for key, value in _info.items() if value[0] == 0]
66
68
 
67
69
    if sorted:
68
70
        todo.sort()
86
88
 
87
89
        # indent, cum_time, mod_time, name,
88
90
        # scope_name, frame_name, frame_lineno
89
 
        out_file.write('%5.1f %5.1f %-40s @ %s:%d\n'
90
 
            % (info[-1]*1000., mod_time*1000.,
91
 
               ('+'*info[0] + cur[1]),
92
 
               info[1], info[2]))
 
91
        out_file.write(
 
92
            '%5.1f %5.1f %-40s @ %s:%d\n' % (
 
93
                info[-1] * 1000., mod_time * 1000.,
 
94
                ('+' * info[0] + cur[1]), info[1], info[2]))
93
95
 
94
96
        if sorted:
95
97
            c_times.sort()
149
151
        # Do the import
150
152
        return _real_import(name, globals, locals, fromlist, level=level)
151
153
    finally:
152
 
        tload = _timer()-tstart
 
154
        tload = _timer() - tstart
153
155
        stack_finish(this, tload)
154
156
 
155
157
 
156
158
def _repr_regexp(pattern, max_len=30):
157
159
    """Present regexp pattern for logging, truncating if over max_len."""
158
160
    if len(pattern) > max_len:
159
 
        return repr(pattern[:max_len-3]) + "..."
 
161
        return repr(pattern[:max_len - 3]) + "..."
160
162
    return repr(pattern)
161
163
 
162
164
 
177
179
        frame = sys._getframe(5)
178
180
        frame_name = frame.f_globals.get('__name__', '<unknown>')
179
181
    frame_lineno = frame.f_lineno
180
 
    this = stack_add(extra+_repr_regexp(args[0]), frame_name, frame_lineno)
 
182
    this = stack_add(extra + _repr_regexp(args[0]), frame_name, frame_lineno)
181
183
 
182
184
    tstart = _timer()
183
185
    try: