Metadata-Version: 2.1
Name: no-toplevel-code
Version: 1.0.0
Summary: Wrap and unwrap code to allow for modules without top-level code
Home-page: https://github.com/kavigupta/no-toplevel-code
Author: Kavi Gupta
Author-email: kavig+no_toplevel_code@mit.edu
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Operating System :: OS Independent
Requires-Python: >=3.9
Description-Content-Type: text/markdown


# no_toplevel_code

Package to wrap a piece of python code in a function and function call, to avoid running code at the top level of a script.

## Example

E.g., if you have a script that looks like this:

```python
import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0, 2*np.pi, 100)
y = np.sin(x)

plt.plot(x, y)
plt.show()
```

no_toplevel_code converts it to this:
    
```python
import numpy as np
import matplotlib.pyplot as plt

def _main():
    x = np.linspace(0, 2*np.pi, 100)
    y = np.sin(x)

    plt.plot(x, y)
    plt.show()

_main()
```

## Interface

This package provides two functions: `wrap_code` and `unwrap_code` as well as their equivalent functions
    `wrap_ast` and `unwrap_ast`. The former functions take a string as input, while the latter functions
    take an AST (Abstract Syntax Tree) as input.
