Skip to main content

Python restructuring for splitting functions, generated facades, and early semantic OOP conversion.

Project description

image

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

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:

import math


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


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

Run:

uv run manasplice splitfunc main.area

Result:

import math
from modules import area


def greet(name: str) -> str:
    return f"Hello, {name}!"
"""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:

uv add manasplice

or

pip install manasplice

For local development in this repo:

uv sync

To run the CLI without installing it globally:

uv run manasplice --help

[!NOTE] For further documentation please read the wiki: ManaSplice wiki

Development

Run tests with:

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

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

manasplice-0.1.3a2.tar.gz (144.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

manasplice-0.1.3a2-py3-none-any.whl (53.6 kB view details)

Uploaded Python 3

File details

Details for the file manasplice-0.1.3a2.tar.gz.

File metadata

  • Download URL: manasplice-0.1.3a2.tar.gz
  • Upload date:
  • Size: 144.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for manasplice-0.1.3a2.tar.gz
Algorithm Hash digest
SHA256 f8e49603e56141cb29f82511b1aa26406b9596b7ab7666fcb8035bb0074f839d
MD5 f72155bf6e5f93ff67402c3a66a95a59
BLAKE2b-256 1bbf2fd330edc7185df09471d9bfda752f89cbd16612f72fe2e6046af235b562

See more details on using hashes here.

File details

Details for the file manasplice-0.1.3a2-py3-none-any.whl.

File metadata

  • Download URL: manasplice-0.1.3a2-py3-none-any.whl
  • Upload date:
  • Size: 53.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for manasplice-0.1.3a2-py3-none-any.whl
Algorithm Hash digest
SHA256 9c77e6ec754064e16e3f93b6faf5c49e61ce96cdb0ed306b476244a1447d60a6
MD5 df60fe3eb36e715d9fa250b7736c1bc0
BLAKE2b-256 8c3daf06c12c27b8d6359aa579f2a95abcf04c8121ee47ec86e0135641b71b52

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page