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.
  • 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>;
  • 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 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. run reuses that configured target. run --check reports what would change without writing files. A .msignore file makes ManaSplice skip that folder and everything below it.

[!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.3a1.tar.gz (135.7 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.3a1-py3-none-any.whl (45.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: manasplice-0.1.3a1.tar.gz
  • Upload date:
  • Size: 135.7 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.3a1.tar.gz
Algorithm Hash digest
SHA256 f21b39e0789c3c4a33e99280a510ed5111c3b7d0cc6edfa23ac79b77ce79d8a7
MD5 741ce5b5632a845ad3f28a83520b5ee8
BLAKE2b-256 bbd414bcad99db2a2ec9902242bac2931331eb376c1b364d334929b5a4fc4097

See more details on using hashes here.

File details

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

File metadata

  • Download URL: manasplice-0.1.3a1-py3-none-any.whl
  • Upload date:
  • Size: 45.8 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.3a1-py3-none-any.whl
Algorithm Hash digest
SHA256 8489099f01a132f56ea2811a2c80802e82b99f067aac24a39948e248ae08c901
MD5 df17231705e786c44941dfb0387b0361
BLAKE2b-256 5083e0f75d0ce0676e93fee274dd4a787f7a61e5f0596d806d9f215b75425f47

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