⚠️ Notes
Forked from https://github.com/vitsalis/pycg
Changes: See https://github.com/deeplime-io/PyCG/tree/onecode
Essentially added code tracks the order of the calls and the code associated to it. It is used by OneCode to properly interpret code based on the excellent PyCG.
Why a new PyPi package? Well, the not-so-great PyPi doesn't allow to have forked public repositories as part of the dependencies. Nice right?
PyCG - Practical Python Call Graphs
PyCG generates call graphs for Python code using static analysis. It efficiently supports
- Higher order functions
- Twisted class inheritance schemes
- Automatic discovery of imported modules for further analysis
- Nested definitions
You can read the full methodology as well as a complete evaluation on the ICSE 2021 paper.
You can cite PyCG as follows. Vitalis Salis, Thodoris Sotiropoulos, Panos Louridas, Diomidis Spinellis and Dimitris Mitropoulos. PyCG: Practical Call Graph Generation in Python. In 43rd International Conference on Software Engineering, ICSE '21, 25–28 May 2021.
PyCG is archived. Due to limited availability, no further development improvements are planned. Happy to help anyone that wants to create a fork to continue development.
Installation
PyCG is implemented in Python3 and requires Python 3.10–3.14. It also has no dependencies. Simply:
pip install onecode-pycg
Usage
~ >>> pycg -h
usage: __main__.py [-h] [--package PACKAGE] [--product PRODUCT]
[--forge FORGE] [--version VERSION] [--timestamp TIMESTAMP]
[--max-iter MAX_ITER] [--operation {call-graph,key-error}]
[--as-graph-output AS_GRAPH_OUTPUT] [-o OUTPUT]
[entry_point ...]
positional arguments:
entry_point Entry points to be processed
optional arguments:
-h, --help show this help message and exit
--package PACKAGE Package containing the code to be analyzed
--max-iter MAX_ITER Maximum number of iterations through source code. If not specified a fix-point iteration will be performed.
--operation {call-graph,key-error}
Operation to perform. Choose call-graph for call graph generation (default) or key-error for key error detection on dictionaries.
--as-graph-output AS_GRAPH_OUTPUT
Output for the assignment graph
-o OUTPUT, --output OUTPUT
Output path
Call Graph Output
Simple JSON format
The call edges are in the form of an adjacency list where an edge (src, dst)
is represented as an entry of dst in the list assigned to key src:
{
"node1": ["node2", "node3"],
"node2": ["node3"],
"node3": []
}
FASTEN Format
Dropped - not useful for OneCode and requires porting of pkg_resources
For an up-to-date description of the FASTEN format refer to the FASTEN wiki.
Key Errors Output
We are currently experimenting on identifying potential invalid dictionary accesses on Python dictionaries (key errors). The output format for key errors is a list of dictionaries containing:
- The file name in which the key error was identified
- The line number inside the file
- The namespace of the accessed dictionary
- The key used to access the dictionary
[{
"filename": "mod.py",
"lineno": 2,
"namespace": "mod.<dict1>",
"key": "key2"
},
{
"filename": "mod.py",
"lineno": 8,
"namespace": "mod.<dict1>",
"key": "nokey"
}]
Examples
All the entry points are known and we want the simple JSON format
~ >>> pycg --package pkg_root pkg_root/module1.py pkg_root/subpackage/module2.py -o cg.json
All entry points are not known and we want the simple JSON format
~ >>> pycg --package django $(find django -type f -name "*.py") -o django.json
Running Tests
From the root directory, first install the mock package:
pip3 install mock
Τhen, simply run the tests by executing:
make test
Metadata
Release files for onecode-pycg 1.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| onecode_pycg-1.2.1.tar.gz | 54.2 kB | Without provenance | Details for onecode_pycg-1.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| onecode_pycg-1.2.1-py3-none-any.whl | Python 3 | none | any | Details for onecode_pycg-1.2.1-py3-none-any.whl |
Total release size: 111.1 kB
Release files / onecode_pycg-1.2.1.tar.gz
| Download URL | onecode_pycg-1.2.1.tar.gz |
|---|---|
| Size | 54.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7ddfd444e57fc6129e4c39eb0b68e26b3af958cb1e630564cb83a0f68ef90a33
|
|
BLAKE2b-256 checksum How to use checksums |
83436a5510d379dcb7bcd21b50b2007dc0784da01723d2152b1e6d5748877afc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Pop!_OS","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / onecode_pycg-1.2.1-py3-none-any.whl
| Download URL | onecode_pycg-1.2.1-py3-none-any.whl |
|---|---|
| Size | 56.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
aa0db8be04cc8abea907add69b32370c1cd55350d7f56b8a3f902cbfbb58fc8c
|
|
BLAKE2b-256 checksum How to use checksums |
6b67ef2f502a0a987a44e4261d5c6b5e170a1d2f7260523c3089071bb4d2c927
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Pop!_OS","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for onecode-pycg 1.2.1
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.