Python Rope: how to find all missing imports and errors in all refactorings of all modules

I try to find all missing import statements and errors for each module and its modules.

Is there a special tool for what I'm trying to do?

The code I wrote, but it seems really awful and maybe something like this already exists:

import os
def find_missing_imports(walk):
    for items in walk:
        d = items[0]
        f_list = items[1]
        for f in f_list:
            module = f[:-3]
            # posix_path
            module_path = d.lstrip('.').replace('/','.').lstrip('.')
            try:
                __import__(module_path, fromlist=[module])
            except IndentationError, e:
                #print(f,e)
                pass
            except NameError, e:
                print(d,f,e)
                pass
            except Exception, e:
                print(f,e)
                pass

walk = [[root,files] for root,dirs,files in os.walk('.') for fn in files if  fn.endswith('.py')]
find_missing_imports(walk)

Outputs:

.[snip]
('./Sky_Group_Inventory_Scanner-wxpython/display_image/Dialogs', 'ImageSelectionFrame.py', NameError("name 'wx' is not defined",))
('./Sky_Group_Inventory_Scanner-wxpython/display_image/Dialogs', 'ItemSpecificsDialog.py', NameError("name 'wx' is not defined",))
('./Sky_Group_Inventory_Scanner-wxpython/display_image/Dialogs', 'ReturnCorrectWatchTitle.py', NameError("name 'wx' is not defined",))
.[snip]

My project before refactoring was a mess, but kind of useful, now it's broken after refactoring.

After reading the "Pragmatic Programmer" based on the sentences of my initial codereview post:

I was looking for the source code:

/usr/local/lib/python2.7/dist-packages/rope

ROPE . Ninja-IDE, , .

, , , .

.

enter image description here

, .

before

, , , .

:

pylint -E /path/to/module

+4
1

pip install pylint

/:

pylint /path/to/module > pylint_output

:

  • undefined -variable < - , .
  • line-too-long
  • superfluous-parens
  • bad-whitespace
  • -defined-outside-init
  • missing-docstring
  • wide-except
  • unused-argument
  • unused-import
  • unused-variable
  • no-self-use
  • no-member
  • fixme
  • noecessary-pass
  • too-many-statements
  • --
  • missing-final-newline
  • too-many-instance-attributes
  • redefined-builtin
  • --
  • -no-member
  • -
  • super-on-old-class
  • bare-except
  • undefined -loop-variable
  • too-many-return-statements
  • --
  • star-args
  • indexing-exception
  • redefined-external-name
  • -on-old-class
  • -
  • no-name-in-module
  • global-variable- undefined
  • bad-except-order
  • -

, pylint , :

************* Module module_name.sub_module.class_name.method_name
R: line_no, column: Issue description 'some_name' (issue-type)
C: line_no, column: Issue description 'some_name' (issue-type)
W: line_no, column: Issue description 'some_name' (issue-type)
E: line_no, column: Issue description 'some_name' (issue-type)
F: line_no, column: Issue description 'some_name' (issue-type)
************* Module module_name.sub_module.class_name.method_name
R: line_no, column: Issue description 'some_name' (issue-type)
C: line_no, column: Issue description 'some_name' (issue-type)
W: line_no, column: Issue description 'some_name' (issue-type)
E: line_no, column: Issue description 'some_name' (issue-type)
F: line_no, column: Issue description 'some_name' (issue-type)    
  • [R] efactor " "
  • [C]
  • [W]
  • [E] rror (.., , )
  • [F] atal ,

, (undefined -variable) , . pylint -E /path/to/module undefined - .

+4

Source: https://habr.com/ru/post/1540457/


All Articles