0

In legacy system, We have created init module which load information and used by various module(import statement). It's big module which consume more memory and process longer time and some of information is not needed or not used till now. There is two propose solution.

  1. Can we determine in Python who is using this module.Fox Example LoadData.py ( init Module) contain 100 data member A.py
    import LoadData b = LoadData.name

    B.py import LoadData b = LoadData.width

    In above example, A.py using name and B.py is using width and rest information is not required (98 data member is not required). is there anyway which help us to determine usage of LoadData module along with usage of data member.

  2. In simple, we need to traverse A.py and B.py and find manually to identify usage of object.

I am trying to implement first solution as I have more than 1000 module and it will be painful to determine by traversing each module. I am open to any tool which can integrate into python

1 Answer 1

1

Your question is quite broad, so I can't give you an exact answer. However, what I would generally do here is to run a linter like flake8 over the whole codebase to show you where you have unused imports and if you have references in your files to things that you haven't imported. It won't tell you if a whole file is never imported by anything, but if you remove all unused imports, you can then search your codebase for imports of a particular module and if none are found, you can (relatively) safely delete that module.

You can integrate tools like flake8 with most good text editors, so that they highlight mistakes in real time.

As you're trying to work with legacy code, you'll more than likely have many errors when you run the tool, as it looks out for style issues as well as the kinds of import/usage issues that youre mention. I would recommend fixing these as a matter of principle (as they they are non-functional in nature), and then making sure that you run flake8 as part of your continuous integration to avoid regressions. You can, however, disable particular warnings with command-line arguments, which might help you stage things.

Another thing you can start to do, though it will take a little longer to yield results, is write and run unit tests with code coverage switched on, so you can see areas of your codebase that are never executed. With a large and legacy project, however, this might be tough going! It will, however, help you gain better insight into the attribute usage you mention in point 1. Because Python is very dynamic, static analysis can only go so far in giving you information about atttribute usage.

Also, make sure you are using a version control tool (such as git) so that you can track any changes and revert them if you go wrong.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your input but it can be valid issue also. Like I have class which contain 100 data member but we have used only 10 and need to remove 90 data member and need to check complete code base

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.