Skip to content

EyreFree/EFPodsAnalyzer

Repository files navigation

EFPodsAnalyzer is a Python script that is used to help us sort out the CoaoaPods library dependency relationship. It can generate clear Pods dependency graph with only one command, which will help us in dependency sorting / component cleaning.

中文介绍

Preview

The more the Pods library is, the more complex the library is, the more it is used to get the tool, for example, the modularized item; conversely, if the project dependency is very few and the dependency relation is very simple, there is no need for this tool. The dependency graph of a project of our company is as follows, looks like a shit:

Requirements

  • Python 2.7

Installation

PyPI

If you have pip installed on your device, you can install the latest version of this tool directly with the following commands:

sudo pip install efpodsanalyzer --upgrade

Manual

Download this project, or execute the following commands to Clone this project:

git clone [email protected]:EyreFree/EFPodsAnalyzer.git

Usage

PyPI

  1. First, ensure that your project has been operated on pod install and successfully generated the Pods directory;
  2. Install efpodsanalyzer on your device with pip;
  3. Classify the dependent libraries according to the specific circumstances of the projects to be analyzed, and give the regex of each category separately, then write the rules to the EFPAConfig.json file under the directory which contains the target Podfile;
  4. Execute the following commands for the generation of the dependency graph:
sudo efpodsanalyzer [Target Podfile file path]
  1. You can check the output of the terminal. If you see the following log, you can open the generated file index.html in the path with your browser:
Dependency graph generated: .../EFPADiagram/index.html

If there is any error, please deal with the corresponding error information, or you can make a PR or an Issue.

Manual

  1. First, ensure that your project has been operated on pod install and successfully generated the Pods directory;
  2. The content of this tool has been fully downloaded to the local area;
  3. Classify the dependent libraries according to the specific circumstances of the projects to be analyzed, and give the regex of each category separately, then write the rules to the EFPAConfig.json file under the directory which contains the target Podfile;
  4. Execute the following commands for the generation of the dependency graph:
python [EFPodsAnalyzer.py file path] [Target Podfile file path]
  1. You can check the output of the terminal. If you see the following log, you can open the generated file index.html in the path with your browser:
Dependency graph generated: .../EFPADiagram/index.html

If there is any error, please deal with the corresponding error information, or you can make a PR or an Issue.

Example

Here we take Coding's open source iOS client as an example to show you the complete use of this tool:

  1. First, install efpodsanalyzer on your device with pip.
  2. Then download the Coding iOS project to local, and perform pod install operation;
  3. Because the dependency of the Coding client is basically not classified, which is all the third party library. Therefore, for demonstration purposes, I divide it into three categories: the library with the beginning of 'M', the library ending with 'Kit' and the others. The EFPAConfig.json is as follows(You can also click here to see the sample file online):
{
    "config": {
        "categories": ["M-prefixed Libraries", "Library ending with Kit", "Other"],
        "categoryRegexes": ["^M.*", ".*(Kit)$", ".*"]
    }
}
  1. The command to generate diagram is as follows:
sudo efpodsanalyzer /Users/eyrefree/Documents/iOS_GitHub/Coding-iOS/Podfile
  1. The final dependency graph is generated as follows, you can also view it online:

  • Clicking on the top class name can control the display and hiding of the class;
  • The mouse can be suspended on the node to display the node name;
  • The mouse can be suspended on the line between two nodes to display the relationship of them.

Another style circular, as follows, you can view it online too:

Todo

  • Determine whether the dependency needs to be removed, according to the header file reference;
  • Determine whether the dependency needs to be removed, depending on the class dependency;
  • More style of diagrams.

Other

  1. The view of dependency graph is based on ECharts and xml2json, thanks for their work!
  2. Code of this tool can be packaged / released using the following commands. People who needs to build a custom version can make some self exploration(Under the root directory of this project):
rm -rf dist/*;
python setup.py sdist bdist_wheel;
twine upload dist/efpodsanalyzer*;

Author

EyreFree, [email protected]

License

EFPodsAnalyzer is available under the GPLv3 license. See the LICENSE file for more info.