Skip to content

Repository files navigation

pothenon

pothenon is a dependency parser for Python functions and classes. Given a callable or class, it inspects the object's source code and resolves each external symbol it references to its originating Python package, including the package's version where available.

Installation

pip install pothenon

Usage

from pothenon import dependency_parser

Resolving dependencies of a user-defined function

When a function calls another function that is defined in the same (local) scope, pothenon reports that function together with its own dependencies:

import json
from math import sqrt

def add_one(x):
    return x + 1

def get_sqrt(x):
    return sqrt(x)

def my_operation(x):
    y = add_one(x)
    z = get_sqrt(y)
    return z

def dump_operation(x):
    y = my_operation(x)
    return json.dumps(y)

print(dependency_parser.get_full_source(dump_operation))
"""
import json

from math import sqrt

def get_sqrt(x):
    return sqrt(x)

def add_one(x):
    return x + 1

def my_operation(x):
    y = add_one(x)
    z = get_sqrt(y)
    return z

def dump_operation(x):
    y = my_operation(x)
    return json.dumps(y)
"""

API

dependency_parser.get_call_dependencies(func)

Analyses func and returns a CallDependencies dict mapping each external symbol name to a PackageInfo named tuple with the following fields:

Field Description
localname The name by which the symbol is referenced inside func
info A VersionInfo with module, qualname, and version
source_code Source code of the dependency (local callables only)
dependency Recursively resolved dependencies of the dependency
installation Conda/pip installation string for the package, if available

About

Find dependency of python functions

Resources

Code of conduct

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages