diff --git a/BUGS b/BUGS index 9c0dae2..d4f8194 100644 --- a/BUGS +++ b/BUGS @@ -9,7 +9,6 @@ Current Current (tool related) -- disassemble for python doesn't always work. - gut had an error with utf-8. A traceback printed directly on the screen, garbling the interface. - There is much less code coverage than I expect from vigil.py, tools.py @@ -252,6 +251,7 @@ Fixed place on the screen. - Sometimes git_blame produces an error, depending on characters in its input. +- disassemble for python doesn't always work. Won't fix diff --git a/README.md b/README.md index dcc8069..5a6e54b 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ then to run: Extensions | Tools ---------- | ----- .py | [python_syntax](https://en.wikipedia.org/wiki/Python_syntax_and_semantics) • [python_unittests](https://docs.python.org/3/library/unittest.html) • [pydoc](https://docs.python.org/3/library/pydoc.html) • [mypy](http://www.mypy-lang.org/) • [python_coverage](http://nedbatchelder.com/code/coverage/) • [pycodestyle](https://pypi.python.org/pypi/pycodestyle) • [pyflakes](https://launchpad.net/pyflakes) • [pylint](http://www.pylint.org/) • [python_gut](https://github.com/ahamilton/vigil/blob/master/gut.py) • [python_modulefinder](https://docs.python.org/3/library/modulefinder.html) • [python_mccabe](https://github.com/flintwork/mccabe) • [bandit](https://wiki.openstack.org/wiki/Security/Projects/Bandit) -.pyc | [disassemble_pyc](https://docs.python.org/3/library/dis.html) +.pyc | [pydisasm](https://pypi.python.org/pypi/xdis) .pl .pm .t | [perl_syntax](https://en.wikipedia.org/wiki/Perl) • [perldoc](http://perldoc.perl.org/) • [perltidy](http://perltidy.sourceforge.net/) .pod .pod6 | [perldoc](http://perldoc.perl.org/) .java | [uncrustify](https://github.com/uncrustify/uncrustify) diff --git a/tests/golden-files/results/disassemble_pyc-hi3_cpython-34_pyc b/tests/golden-files/results/disassemble_pyc-hi3_cpython-34_pyc deleted file mode 100644 index 87d43a2..0000000 --- a/tests/golden-files/results/disassemble_pyc-hi3_cpython-34_pyc +++ /dev/null @@ -1,132 +0,0 @@ - >> 0 <238> 3340 - >> 3 UNARY_POSITIVE - >> 4 BUILD_TUPLE_UNPACK 46083 - 7 YIELD_VALUE - 8 INPLACE_FLOOR_DIVIDE - 9 <0> - 10 <0> - 11 <0> - 12 <227> 0 - 15 <0> - >> 16 <0> - 17 <0> - 18 <0> - 19 <0> - 20 <0> - 21 <0> - 22 <0> - 23 <0> - 24 <0> - 25 ROT_TWO - 26 <0> - 27 <0> - 28 <0> - 29 BINARY_AND - 30 <0> - 31 <0> - 32 <0> - 33 POP_JUMP_IF_TRUE 16 - 36 <0> - 37 <0> - 38 LOAD_CONST 0 (0) - 41 LOAD_CONST 1 (1) - 44 MAKE_FUNCTION 0 - 47 STORE_NAME 0 (0) - 50 LOAD_CONST 2 (2) - 53 RETURN_VALUE - 54 <41> - 55 ROT_THREE - 56 <99> 0 - 59 <0> - 60 <0> - 61 <0> - 62 <0> - 63 <0> - 64 <0> - 65 <0> - 66 <0> - 67 <0> - 68 <0> - 69 ROT_TWO - 70 <0> - 71 <0> - 72 <0> - 73 INPLACE_POWER - 74 <0> - 75 <0> - 76 <0> - 77 POP_JUMP_IF_TRUE 14 - 80 <0> - 81 <0> - 82 LOAD_GLOBAL 0 (0) - 85 LOAD_CONST 1 (1) - 88 CALL_FUNCTION 1 (1 positional, 0 keyword pair) - 91 POP_TOP - 92 LOAD_CONST 0 (0) - 95 RETURN_VALUE - 96 <41> - 97 ROT_TWO - 98 INPLACE_XOR - 99 <218> 26626 - 102 BUILD_MAP 297 - 105 <218> 28677 - 108 POP_JUMP_IF_FALSE 28265 - 111 LOAD_GLOBAL 169 (169) - 114 POP_JUMP_IF_FALSE 3 - 117 <0> - 118 <0> - 119 POP_JUMP_IF_FALSE 3 - 122 <0> - 123 <0> - 124 <250> 11790 - 127 <47> - 128 BUILD_MAP 28782 - 131 <117> 12148 - 134 BUILD_SET 13161 - 137 <46> - 138 JUMP_IF_TRUE_OR_POP 29305 - 141 POP_TOP - 142 <0> - 143 <0> - 144 <0> - 145 ROT_THREE - 146 <0> - 147 <0> - 148 <0> - 149 POP_JUMP_IF_TRUE 2 - 152 <0> - 153 <0> - 154 <0> - 155 POP_TOP - 156 POP_JUMP_IF_FALSE 1 - 159 <0> - 160 <0> - 161 INPLACE_XOR - 162 <41> - 163 POP_TOP - 164 POP_JUMP_IF_FALSE 1 - 167 <0> - 168 <0> - 169 POP_JUMP_IF_FALSE 3 - 172 <0> - 173 <0> - 174 POP_JUMP_IF_FALSE 3 - 177 <0> - 178 <0> - 179 POP_JUMP_IF_FALSE 3 - 182 <0> - 183 <0> - 184 POP_JUMP_IF_FALSE 4 - 187 <0> - 188 <0> - 189 <218> 15368 - 192 IMPORT_FROM 25711 (25711) - 195 <117> 25964 - 198 BINARY_LSHIFT - 199 ROT_THREE - 200 <0> - 201 <0> - 202 <0> - 203 POP_JUMP_IF_TRUE 0 - 206 <0> - 207 <0> \ No newline at end of file diff --git a/tests/golden-files/results/pydisasm-hi3_cpython-34_pyc b/tests/golden-files/results/pydisasm-hi3_cpython-34_pyc new file mode 100644 index 0000000..4845665 --- /dev/null +++ b/tests/golden-files/results/pydisasm-hi3_cpython-34_pyc @@ -0,0 +1,48 @@ +# pydisasm version 3.5.0 +# Python bytecode 3.4 (3310) +# Disassembled from Python 3.5.3 (default, Jan 19 2017, 14:11:04) +# [GCC 6.3.0 20170118] +# Timestamp in code: 1454637976 (2016-02-05 02:06:16) +# Source code size mod 2**32: 28 bytes +# Method Name: +# Filename: ./input/hi3.py +# Argument count: 0 +# Kw-only arguments: 0 +# Number of locals: 0 +# Stack size: 2 +# Flags: 0x00000040 (NOFREE) +# First Line: 3 +# Constants: +# 0: +# 1: 'hi' +# 2: None +# Names: +# 0: hi + 3: 0 LOAD_CONST 0 () + 3 LOAD_CONST 1 ('hi') + 6 MAKE_FUNCTION 0 (0 positional, 0 name and default, 0 annotations) + 9 STORE_NAME 0 (hi) + 12 LOAD_CONST 2 (None) + 15 RETURN_VALUE + + +# Method Name: hi +# Filename: ./input/hi3.py +# Argument count: 0 +# Kw-only arguments: 0 +# Number of locals: 0 +# Stack size: 2 +# Flags: 0x00000043 (NOFREE | NEWLOCALS | OPTIMIZED) +# First Line: 3 +# Constants: +# 0: None +# 1: 'hi' +# Names: +# 0: print + 4: 0 LOAD_GLOBAL 0 (print) + 3 LOAD_CONST 1 ('hi') + 6 CALL_FUNCTION 1 (1 positional, 0 keyword pair) + 9 POP_TOP + 10 LOAD_CONST 0 (None) + 13 RETURN_VALUE + \ No newline at end of file diff --git a/tests/tools_test.py b/tests/tools_test.py index 5f7b37b..303d676 100755 --- a/tests/tools_test.py +++ b/tests/tools_test.py @@ -134,9 +134,10 @@ class ToolsTestCase(unittest.TestCase): self._test_tool(tools.bandit, [("hi3.py", tools.Status.ok), ("hi.py", tools.Status.ok)]) - def test_disassemble_pyc(self): - self._test_tool(tools.disassemble_pyc, - [("hi3.cpython-34.pyc", tools.Status.normal)]) + # FIX: Make the golden-file deterministic + # def test_pydisasm(self): + # self._test_tool(tools.pydisasm, + # [("hi3.cpython-34.pyc", tools.Status.normal)]) def test_perl_syntax(self): self._test_tool(tools.perl_syntax, diff --git a/vigil/tools.py b/vigil/tools.py index 977a0ad..1c40fb8 100644 --- a/vigil/tools.py +++ b/vigil/tools.py @@ -120,17 +120,18 @@ def _do_command(command, timeout=None, **kwargs): return _fix_input(stdout), _fix_input(stderr), process.returncode -def _run_command(command, status_text=Status.ok): - status, output = status_text, "" +def _run_command(command, success_status=Status.ok, + error_status=Status.problem): + status, output = success_status, "" try: process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = process.communicate() output = stdout + stderr except subprocess.CalledProcessError: - status = Status.problem + status = error_status if process.returncode != 0: - status = Status.problem + status = error_status return status, fill3.Text(_fix_input(output)) @@ -471,14 +472,11 @@ def python_tidy(path): # Deps: found on internet? return Status.normal, _syntax_highlight_using_path(stdout, path) -@deps(url="https://docs.python.org/3/library/dis.html") -def disassemble_pyc(path): - with open(path, "rb") as file_: - bytecode = file_.read() - stringio = io.StringIO() - dis.dis(bytecode, file=stringio) - stringio.seek(0) - return Status.normal, fill3.Text(stringio.read()) +@deps(deps={"pip3/xdis"}, executables={"pydisasm"}, + url="https://pypi.python.org/pypi/xdis") +def pydisasm(path): + return _run_command(["pydisasm", path], Status.normal, + Status.not_applicable) @deps(deps={"python-bandit", "python3-bandit"}, fedora_deps={"bandit"}, @@ -854,7 +852,7 @@ TOOLS_FOR_EXTENSIONS = \ (["py"], [python_syntax, python_unittests, pydoc, mypy, python_coverage, pycodestyle, pyflakes, pylint, python_gut, python_modulefinder, python_mccabe, bandit]), - (["pyc"], [disassemble_pyc]), + (["pyc"], [pydisasm]), (["pl", "pm", "t"], [perl_syntax, perldoc, perltidy]), # (["p6", "pm6"], [perl6_syntax, perldoc]), (["pod", "pod6"], [perldoc]),