Metadata-Version: 2.4
Name: manasplice
Version: 0.1.3a2
Summary: Python restructuring for splitting functions, generated facades, and early semantic OOP conversion.
Author: VirtualShowdown
License: MIT
License-File: LICENSE
Requires-Python: >=3.12
Requires-Dist: colorama>=0.4.6
Requires-Dist: libcst>=1.8.6
Description-Content-Type: text/markdown

![image](media/icons/manasplit_tp.png)

 # ManaSplice

 ManaSplice is a small paradigm linter for Python restructuring. It can configure a target paradigm for a project, scan for code that can move toward that paradigm, apply safe rewrites, and ignore folders that should stay outside the rule.

 It creates a `modules/` package next to the source file, moves the function there, and rewrites the source module to import it back in.

## What it does

- Sets the project paradigm with `paradigm OOP`, then applies the configured rewrite across the project.
- Creates layered/domain architecture boundaries with `paradigm layered`.
- Runs the configured paradigm linter with `run`.
- Ignores a folder with `ignore --path path/to/folder`, which writes a `.msignore` file there.
- Splits one top-level function with `splitfunc`.
- Splits every top-level function in a file, or every top-level function in each Python file in a directory, with `splitall`.
- Adds a generated static-method namespace plus top-level forwarding wrappers with `paradigm OOP <file>`.
- Starts a semantic procedural-to-OOP conversion with project-level `paradigm OOP` or explicit `paradigm OOP --semantic`, which creates an instantiable class, converts selected functions into instance methods, infers constructor state from module-level values used by those functions, and keeps compatibility wrappers through a default instance.
- Adds functional convenience helpers and a `FUNCTIONAL_API` mapping with `paradigm functional`.
- Adds an event dispatch facade with `paradigm event-driven`.
- Reverses ManaSplice-generated static OOP wrappers back toward procedural code with `paradigm procedural`.
- Checks whether a split is safe, and shows the planned changes without writing files, with `check`.
- Emits JSON plans with `--json` for automation.
- Copies the imports and top-level definitions the extracted function needs.
- Maintains `modules/__init__.py` so rewritten files can use a single merged import line.

## Semantic paradigm work

ManaSplice is intended to work like a paradigm linter: the configured paradigm is the standard, and `manasplice run` scans code for safe rewrites toward that standard. The first semantic path is OOP. It can convert compatible procedural modules into an instance-oriented class by:

- turning selected top-level functions into instance methods;
- rewriting calls between selected functions to `self.method(...)`;
- inferring constructor parameters from module-level state read by those functions;
- rewriting those state reads to `self.<attribute>`;
- inferring record-style owner classes from functions such as `cart_add_item(cart, item)` and rewriting dictionary-field access such as `cart["items"]` to `self.items`;
- leaving top-level function wrappers that call a generated default instance for compatibility.

This is still conservative. ManaSplice skips decorated functions, overloads, dynamic code execution, eager module-initialization references, and functions using `global` statements. The current semantic mode does not yet infer rich domain object boundaries, inheritance/composition, layered architecture, pure immutable functional pipelines, domain events, event buses, bounded contexts, services, repositories, or controllers.

## Paradigm linter workflow

```bash
manasplice paradigm OOP
manasplice paradigm layered
manasplice run
manasplice run --check
manasplice ignore --path legacy
```

`paradigm OOP` writes `[tool.manasplice]` settings to `pyproject.toml` and applies the OOP rule across the project. `paradigm layered` writes the layered target and creates bounded-context scaffolding under `contexts/` plus shared `event_bus.py` and `pipeline.py` primitives. `run` reuses the configured target. `run --check` reports what would change without writing files. A `.msignore` file makes ManaSplice skip that folder and everything below it.

The layered target generates explicit places for rich domain entities, aggregate inheritance, service composition, repositories, controllers, domain events, an event bus, immutable pipeline composition, and bounded contexts. It is an enforcement scaffold today; migrating arbitrary existing code into those layers is still incremental.

Layered mode also lints architecture drift. It reports domain/application/infrastructure/presentation dependency-direction violations, rejects cross-context imports between bounded contexts, and keeps shared code independent from contexts. Application services depend on repository ports, while infrastructure provides repository implementations.

>[!WARNING]
This project is very early in development. It is meant to simplify mechanical restructuring tasks, but ManaSplice can still touch large parts of a codebase.

>[!CAUTION]
Although there are measures to prevent issues, please be sure to use git and commit before using ManaSplice to prevent potentially unexpected behavior.

## Quick example

Starting point:

```python
import math


def area(radius: float) -> float:
    return math.pi * radius * radius


def greet(name: str) -> str:
    return f"Hello, {name}!"
```

Run:

```bash
uv run manasplice splitfunc main.area
```

Result:

```python
import math
from modules import area


def greet(name: str) -> str:
    return f"Hello, {name}!"
```

```python
"""Auto-generated by ManaSplice from main.py."""

import math


def area(radius: float) -> float:
    return math.pi * radius * radius
```

## Installation

For using in a project:

```bash
uv add manasplice
```

or

```bash
pip install manasplice
```

For local development in this repo:

```bash
uv sync
```

To run the CLI without installing it globally:

```bash
uv run manasplice --help
```

> [!NOTE] 
For further documentation please read the wiki: [ManaSplice wiki](https://github.com/VirtualShowdown/ManaSplice/wiki)

## Development

Run tests with:

```bash
uv run python -m pytest tests --basetemp .pytest_tmp
uv run ruff check src tests
uv run mypy
```

>[!NOTE] CONTRIBUTION
> <b>
> Feel free to give feedback and/or suggest changes. This is just meant to be a helpful tool for larger projects made for fun.
> </b>
