Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find which module imported another module

Tags:

haxe

I need to find out why some module gets included into compilation.

There is some class that should not be included and I think there are some unused imports or bad architecture that requires unnecessary imports. Is there a way to find which modules import some module, which modules import these modules that include this module, and so on, tracking that down to main class of application?

like image 844
romamik Avatar asked Nov 09 '18 11:11

romamik


People also ask

Can a module import another module?

Such a file is called a module; definitions from a module can be imported into other modules or into the main module (the collection of variables that you have access to in a script executed at the top level and in calculator mode).

How do you check if a module is already imported in Python?

Use: if "sys" not in dir(): print("sys not imported!")

How do I find out where a module is located?

You can manually go and check the PYTHONPATH variable contents to find the directories from where these built in modules are being imported. Running "python -v"from the command line tells you what is being imported and from where. This is useful if you want to know the location of built in modules.

What is __ module __ in Python?

A module in Python is a file (ending in .py ) that contains a set of definitions (variables and functions) that you can use when they are imported. Modules are considered as objects, just as everything else is in Python. Many methods can operate on modules.


2 Answers

You could use -D dump-dependencies for this, in which case the compiler will generate two files that can be used to follow the dependency graph in both directions:

  • dump/<target>/.dependants.dump
  • dump/<target>/.dependencies.dump

There is also a handy online tool created by Mark Knol that helps a lot with analyzing these files. To answer the question "what does Array depend on?", you can just upload the two files and enter "array" into the search field:

Conveniently, the results are also clickable.

like image 120
Gama11 Avatar answered Oct 12 '22 20:10

Gama11


I've just came up with very simple idea: just delete this file and there will be compilation errors in places where this module is imported.

like image 35
romamik Avatar answered Oct 12 '22 22:10

romamik