Skip to main content

code_analysis

https://img.shields.io/pypi/v/code_analysis.svg https://img.shields.io/travis/stbraun/code_analysis.svg Documentation Status

Analyze source code dependencies and call trees in Neo4j.

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.

Metadata

Release files for code-analysis 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for code-analysis 0.1.5
File Size Uploaded Provenance
code_analysis-0.1.5.tar.gz 14.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for code-analysis 0.1.5
File Interpreter ABI Platform
code_analysis-0.1.5-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 22.3 kB

Release files / code_analysis-0.1.5.tar.gz

Download URL code_analysis-0.1.5.tar.gz
Size 14.5 kB
Tags Source
SHA-256 checksum
How to use checksums
fdb27b07371dd04387a49f8d9bef05fc08e59fc3e6371c42650154e9b0334946
BLAKE2b-256 checksum
How to use checksums
c5e8339390f41b060a990a29255375491c5370907aa3791717a359a28468cdf2
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / code_analysis-0.1.5-py2.py3-none-any.whl

Download URL code_analysis-0.1.5-py2.py3-none-any.whl
Size 7.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
08e8d949c48f63c838fda68f4dbef2ffeccf5ff252768821c5c2b0c2814673fe
BLAKE2b-256 checksum
How to use checksums
b4129a4c8016adbf6d9654ff99f7c4fedd6a5af68735f6572a64d8e2e16d8f9e
Upload date
Uploaded using Trusted Publishing?
What is 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

Security for code-analysis 0.1.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page