Metadata-Version: 2.4
Name: pothenon
Version: 0.0.3
Summary: pothenon - dependency parser for python functions
Project-URL: Homepage, https://pyiron.org/
Project-URL: Documentation, https://pothenon.readthedocs.io
Project-URL: Repository, https://github.com/pyiron/pothenon
Author-email: Sam Waseda <waseda@mpie.de>
License: BSD 3-Clause License
        
        Copyright (c) 2024, Max-Planck-Institut für Nachhaltige Materialien GmbH - Computational Materials Design (CM) Department
        All rights reserved.
        
        Redistribution and use in source and binary forms, with or without
        modification, are permitted provided that the following conditions are met:
        
        * Redistributions of source code must retain the above copyright notice, this
          list of conditions and the following disclaimer.
        
        * Redistributions in binary form must reproduce the above copyright notice,
          this list of conditions and the following disclaimer in the documentation
          and/or other materials provided with the distribution.
        
        * Neither the name of the copyright holder nor the names of its
          contributors may be used to endorse or promote products derived from
          this software without specific prior written permission.
        
        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
        AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
        DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
        FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
        SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
        CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
        OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
        OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
License-File: LICENSE
Keywords: pyiron
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering
Requires-Python: <3.14,>=3.11
Requires-Dist: gitpython<3.2.0,>=3.1.50
Requires-Dist: pyiron-snippets<1.5.0,>=1.2.1
Description-Content-Type: text/markdown

# 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

```bash
pip install pothenon
```

## Usage

```python
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:

```python
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 |

### `dependency_parser.split_by_version_availability(call_dependencies)`

Partitions a `CallDependencies` dict into two dicts: one for dependencies that have a version
string and one for those that do not.
