Commit Graph

20 Commits

Author SHA1 Message Date
Jun Wu
f1c575a099 flake8: enable F821 check
Summary:
This check is useful and detects real errors (ex. fbconduit).  Unfortunately
`arc lint` will run it with both py2 and py3 so a lot of py2 builtins will
still be warned.

I didn't find a clean way to disable py3 check. So this diff tries to fix them.
For `xrange`, the change was done by a script:

```
import sys
import redbaron

headertypes = {'comment', 'endl', 'from_import', 'import', 'string',
               'assignment', 'atomtrailers'}

xrangefix = '''try:
    xrange(0)
except NameError:
    xrange = range

'''

def isxrange(x):
    try:
        return x[0].value == 'xrange'
    except Exception:
        return False

def main(argv):
    for i, path in enumerate(argv):
        print('(%d/%d) scanning %s' % (i + 1, len(argv), path))
        content = open(path).read()
        try:
            red = redbaron.RedBaron(content)
        except Exception:
            print('  warning: failed to parse')
            continue
        hasxrange = red.find('atomtrailersnode', value=isxrange)
        hasxrangefix = 'xrange = range' in content
        if hasxrangefix or not hasxrange:
            print('  no need to change')
            continue

        # find a place to insert the compatibility  statement
        changed = False
        for node in red:
            if node.type in headertypes:
                continue
            # node.insert_before is an easier API, but it has bugs changing
            # other "finally" and "except" positions. So do the insert
            # manually.
            # # node.insert_before(xrangefix)
            line = node.absolute_bounding_box.top_left.line - 1
            lines = content.splitlines(1)
            content = ''.join(lines[:line]) + xrangefix + ''.join(lines[line:])
            changed = True
            break

        if changed:
            # "content" is faster than "red.dumps()"
            open(path, 'w').write(content)
            print('  updated')

if __name__ == "__main__":
    sys.exit(main(sys.argv[1:]))
```

For other py2 builtins that do not have a py3 equivalent, some `# noqa`
were added as a workaround for now.

Reviewed By: DurhamG

Differential Revision: D6934535

fbshipit-source-id: 546b62830af144bc8b46788d2e0fd00496838939
2018-04-13 21:51:09 -07:00
Jun Wu
2946a1c198 codemod: use single blank line
Summary: This makes test-check-code cleaner.

Reviewed By: ryanmce

Differential Revision: D6937934

fbshipit-source-id: 8f92bc32f75b9792ac67db77bb3a8756b37fa941
2018-04-13 21:51:08 -07:00
Gregory Szorc
742b6fa534 lsprof: use print function 2016-01-02 11:40:53 -08:00
Gregory Szorc
be59b3aff6 lsprof: support PyPy (issue4573)
PyPy's _lsprof module doesn't export a "profiler_entry" symbol. This
patch treats the symbol as optional and falls back to verifying the
attribute is present on the first entry in the collected data as
part of validation.

There is a chance not every entry will contain the requested sort
attribute. But, this patch does unbust lsprof on PyPy for the hg
commands I've tested, so I assume it is sufficient. It's certainly
better than the ImportError we encountered before.

As part of the import refactor, I snuck in the addition of
absolute_import.
2015-11-21 23:26:22 -08:00
Mads Kiilerich
dcbf8a9bfc profiling: replace '+' markup of nested lines with indentation
The display of nested lines for hg --profile was very non-obvious and made it
look like sort didn't work.

The '+' immediately before CallCount was not related to the CallCount and did
not mean plus in any integer sense.

The '+' before module looked like a part of the module name and not like ascii
art.

Instead we now indent the subordinate module names to clearly show the
structure.
2013-02-08 22:54:48 +01:00
Bryan O'Sullivan
509438662e lsprof: report units correctly 2012-05-30 13:57:41 -07:00
Matt Mackall
000c79b7ce profile: add undocumented config options for profiler output 2012-03-15 15:59:26 -05:00
Augie Fackler
7c6e3bd922 lsprof: use getattr instead of hasattr 2011-07-25 15:41:46 -05:00
Martin Geisler
534ae9133c lsprof: remove #!-line from non-executable script
It triggered an rpmlint error, reported by Neal Becker.
2010-10-25 23:46:26 +02:00
Benoit Boissinot
4371f512b2 fix spaces/identation issues 2010-02-05 18:50:08 +01:00
Dirkjan Ochtman
8bd1e15bc5 merge with crew-stable 2009-08-05 17:21:29 +02:00
Dirkjan Ochtman
27d1598185 lsprof: make profile not die when imported modules changes (issue1774) 2009-08-05 14:58:30 +02:00
Alejandro Santos
1ef2fb42a7 compat: use 'key' argument instead of 'cmp' when sorting a list 2009-07-05 11:02:00 +02:00
Peter Arrenbrecht
19591b6a8c cleanup: drop unused assignments 2009-03-23 13:13:06 +01:00
Dirkjan Ochtman
574603a8c0 use dict.iteritems() rather than dict.items()
This should be faster and more future-proof. Calls where the result is to be
sorted using util.sort() have been left unchanged. Calls to .items() on
configparser objects have been left as-is, too.
2009-01-12 09:16:03 +01:00
Peter Ruibal
30a2036f9e use Exception(args)-style raising consistently (py3k compatibility) 2008-09-08 13:07:00 +02:00
Joel Rosdahl
4f8012378a Remove unused imports 2008-03-06 22:23:41 +01:00
Dirkjan Ochtman
ac2a5adcee updating lsprof.py from remote repository 2008-02-01 10:31:09 +01:00
Vadim Gelfer
fc206d2a40 do not try to package lsprof if not available. 2006-06-23 19:20:22 -07:00
Vadim Gelfer
8861256257 add --lsprof option. 3x faster than --profile, more useful output.
results include calls to c code and nested calls.

requires python 2.5 or lsprof installed from svn at
http://codespeak.net/svn/user/arigo/hack/misc/lsprof/
2006-06-09 12:05:17 -07:00