Anyone know of a library/script that can scan source directories and detect circular imports?
Anyone know of a library/script that can scan source directories and detect circular imports?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I do not know any tool outright, but there are a couple of ways I can think of right now that will get you this data.
Make the Interpreter Work for You
For every module you have, create a stub module that imports it, and then run this module with
This only works if you do not rely on sys.path hackery and your modules do not have dangerous side effects when imported (both very dubious features FWIW). You will get the transitive import closure, but detecting circular imports with this should be straightforward.
Use logilab.astng
With logilab.astng,it is easy to extract all direct imports of your modules (look for nodes of type
logilab.astng.nodes.Fromandlogilab.astng.nodes.Import). Once you have the list of direct imports of all modules, create the import graphs and look for cycles.Again, this only works only if you do not use sys.path hacks.