Analyze source code dependencies and call trees in Neo4j.
Project description
code_analysis
Analyze source code dependencies and call trees in Neo4j.
Free software: MIT license
Documentation: https://code-analysis.readthedocs.io.
Features
This project provides generators for Cypher code for import into Neo4J from call tree and package dependencies. Some of these generators rely on external tools to provide their ingoing data.
Static calltrees of Java code can be created with java-callgraph, which can be found on GitHub: https://github.com/gousiosg/java-callgraph.
Dependencies of Java packages can be determined using JDepend, which can also be found on GitHub: https://github.com/clarkware/jdepend.
Python dependencies are determined using the compiler and AST (Abstract Syntax Tree) with a tool provided in this project.
Generating Cypher for a Java call tree
Create the call tree using java-callgraph and save it into a file, e.g., java_call_tree_input.txt. Run:
java_call_tree java_call_tree_input.txt > calltree-cypher.txt
calltree-cypher.txt contains two Cypher statements, one to insert all classes into a Neo4j database, and another to insert the call relations on method level. You can just copy each statement and paste it into the Neo4j browser.
The database schema looks like this::
(:Class)-[:uses]->(:Class) (:Method)-[:calls]->(:Method)
Generating Cypher code for Java dependencies
Create dependencies using JDepend and save it in a file, e.g., java_depend.txt.
Run following command::
java_dependencies java_depend.txt > java_depend.cypher
Now you can copy the Cypher statements stored in java_depend.cypher and paste it into the Neo4j browser.
The database schema looks like this::
(:Package)-[:depends_on]->(:Package)
To check for cycles you may run the query::
MATCH (p:Package)-[r1:depends_on]->(q:Package)-[r2:depends_on]->(p:Package) RETURN p, q, r1, r2
It helps to switch off the default setting, which shows all relations, in the browser settings.
Generating Cypher code for Python dependencies
Determination of dependencies and generation of Cypher code are done in one step in this case::
python_dependencies <path to your package> > python-deps.cypher
The tool compiles the code and walks the AST looking for import statements. Then it generates Cypher code modelling the relationships between the packages.
The database schema looks like this::
(:Package)-[:contains]->(:Module) (:Module)-[:uses]->(:Module)
Credits
This package was created with Cookiecutter and the stbraun/cookiecutter-pypackage project template based on audreyr/cookiecutter-pypackage.
History
0.1.0 (2021-04-04)
First release on PyPI.
0.1.3 (2021-04-05)
Documentation enhanced.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file code_analysis-0.1.5.tar.gz
.
File metadata
- Download URL: code_analysis-0.1.5.tar.gz
- Upload date:
- Size: 14.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fdb27b07371dd04387a49f8d9bef05fc08e59fc3e6371c42650154e9b0334946 |
|
MD5 | a393ee82057e1667356d307c87e59bfc |
|
BLAKE2b-256 | c5e8339390f41b060a990a29255375491c5370907aa3791717a359a28468cdf2 |
File details
Details for the file code_analysis-0.1.5-py2.py3-none-any.whl
.
File metadata
- Download URL: code_analysis-0.1.5-py2.py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08e8d949c48f63c838fda68f4dbef2ffeccf5ff252768821c5c2b0c2814673fe |
|
MD5 | 97c6c329436dfe119f71145b65130546 |
|
BLAKE2b-256 | b4129a4c8016adbf6d9654ff99f7c4fedd6a5af68735f6572a64d8e2e16d8f9e |