Make after-work Mending More flexible In Python

Overview

Mending

Make after-work Mending More flexible In Python

Build Status

A Lite Package focuses on making project's after-post mending pythonic and flexible. Certainly used for expanding finished projects without changing exists source code.

  • No Origin Codes Changes, Injection with Licenses
  • None Invasive Embed Way, More Flexible
  • Easy to use

Package Related

Thr Official Packages ast, inspect, functools used.

Installation

Overwrite requires Python 3.6+ to run.

Simply install with one-line pip command.

pip install Mending

How to Use

Core Import

from Mending import Mend

Set a License Any type of Cipher-text is satisfactory. Set int 0 as example.

_license = 0

Defined Function Mending function, used for overwrite previous method.

def func():
    return

Register Function to Event queue.

  1. Register_type (string): Register with the same Event_queue_type will be added to the same event queue (in registration order).
  2. times (integer): The times this function calling is affected. (if affected forever, set times to -1)
  3. license (any): Used to identify whether the modification is valid and distinguish between different mending events.
  4. func (function): Mending function, used for overwriting.
Mend = Mend()
Mend.Butler.register('Register_type', times, _license, func)
# Add entrance to function
@Mend.entrance(catalog='Register_type')
def affected_func():
    return

Add the License Claim If the license is valid, the registered function affected_func will be modified and completely overwritten by func.

# Claim above the function calling
Mend.claim(_license)
affected_func()

The Performance above is same as:

func()

Features

Complex Overwrite

Mend.Butler.register('Event_queue_type_A', 1, license_A, func_A)
Mend.Butler.register('Event_queue_type_A', 2, license_B, func_B)
Mend.Butler.register('Event_queue_type_B', 1, license_B, func_C)
def func_A():
    print('1')
    return
def func_B():
    print('2')
    return
def func_C():
    print('3')
    return
@Mend.entrance(catalog='Event_queue_type_A')
def affected_func_A():
    print('A')
    return
@Mend.entrance(catalog='Event_queue_type_B')
def affected_func_B():
    print('B')
    return

Different license claiming leads to different way of overwriting. After several times calling set before, the performance of modified function will change back to origin again as a result of event queue gets empty. The program works as below:

@Mend.claim(license_B)
affected_func_A() # Output: 2
@Mend.claim(license_A)
affected_func_A() # Output: 1
@Mend.claim(license_B)
affected_func_A() # Output: 2
@Mend.claim(license_A)
affected_func_A() # Output: A
@Mend.claim(license_B)
affected_func_A() # Output: A
@Mend.claim(license_B)
affected_func_B() # Output: 3
@Mend.claim(license_B)
affected_func_B() # Output: B

Get Catalog Name and Available Licenses of Original Function

Mend.Butler.get(affected_func)
-> dict {'catalog_name': str, 'available_license': list[str]}

Browse the Event Queue

Print details for Event Queue:

Mend.Queue.print(catalog: str)

Get length of Event Queue:

Mend.Queue.len(catalog: str)

Get Event Queue as following type:

Mend.Queue.get(catalog: str)
[{'times_left': int, 'license': any, 'function_name': str}, 
 {'times_left': int, 'license': any, 'function_name': str},
 {'times_left': int, 'license': any, 'function_name': str},]

Directly manipulate the Event Queue

Class Queue redefined, making it compatible with Pythonic Style Commands as below:

Mend.Queue.append(catalog: str, event: list)
Mend.Queue.pop(catalog: str, index: int)
Mend.Queue.replace(catalog: str, event: list, index: int)
Mend.Queue.clear(catalog: str)

Threading

For multi-threaded function overrides, the event queue is cross-threaded, and the order of event completion depends on the total program time sequence, asynchrony may cause event order confusion. Instantiating Mending for each individual thread is a reasonable solution.

Development

Version: 2021.11.18 (0.0.8)

Author: Zack the White, Qcmcmc

Email Contact: Zack the White Qcmcmc

License

MIT

You might also like...
A simple but flexible plugin system for Python.

PluginBase PluginBase is a module for Python that enables the development of flexible plugin systems in Python. Step 1: from pluginbase import PluginB

A flexible free and unlimited python tool to translate between different languages in a simple way using multiple translators.
A flexible free and unlimited python tool to translate between different languages in a simple way using multiple translators.

deep-translator Translation for humans A flexible FREE and UNLIMITED tool to translate between different languages in a simple way using multiple tran

A simple but flexible plugin system for Python.

PluginBase PluginBase is a module for Python that enables the development of flexible plugin systems in Python. Step 1: from pluginbase import PluginB

Simple yet flexible natural sorting in Python.

natsort Simple yet flexible natural sorting in Python. Source Code: https://github.com/SethMMorton/natsort Downloads: https://pypi.org/project/natsort

Providing a working, flexible, easier and faster installer than the one officially provided by Arch Linux
Providing a working, flexible, easier and faster installer than the one officially provided by Arch Linux

Purpose The purpose is to bring more people to Arch Linux by providing a working, flexible, easier and faster installer than the one officially provid

Datamol is a python library to work with molecules.
Datamol is a python library to work with molecules.

Datamol is a python library to work with molecules. It's a layer built on top of RDKit and aims to be as light as possible.

Python module to work with Magneto Database directly without using broken Magento 2 core
Python module to work with Magneto Database directly without using broken Magento 2 core

Python module to work with Magneto Database directly without using broken Magento 2 core

A Python Perforce package that doesn't bring in any other packages to work.

P4CMD 🌴 A Python Perforce package that doesn't bring in any other packages to work. Relies on p4cli installed on the system. p4cmd The p4cmd module h

A Python 3 client for the beanstalkd work queue

Greenstalk Greenstalk is a small and unopinionated Python client library for communicating with the beanstalkd work queue. The API provided mostly map

Owner
null
An attempt at furthering Factorio Calculator to work in more general contexts.

factorio-optimizer Lets do Factorio Calculator but make it optimize. Why not use Factorio Calculator? Becuase factorio calculator is not general. The

Jonathan Woollett-Light 1 Jun 3, 2022
Collection of tools to be more productive in your work environment and to avoid certain repetitive tasks. 💛💙💚

Collection of tools to be more productive in your work environment and to avoid certain repetitive tasks. ??????

Raja Rakotonirina 2 Jan 10, 2022
use Notepad++ for real-time sync after python appending new log text

FTP远程log同步工具 使用Notepad++配合来获取实时更新的log文档效果 适用于FTP协议的log远程同步工具,配合MT管理器开启FTP服务器使用,通过Notepad++监听文本变化,更便捷的使用电脑查看方法注入打印后的信息 功能 过滤器 对每行要打印的文本使用回调函数筛选,支持链式调用

Liuhaixv 1 Oct 17, 2021
These are After Effects and Python files that were made in the process of creating the video for the contest.

spirograph These are After Effects and Python files that were made in the process of creating the video for the contest. In the python file you can qu

null 91 Dec 7, 2022
A Python script to delete movies with a certain tag after a certain amount of days.

radarr_autodelete Simple script, which deletes movies with a specific tag after a certain amount of days Pip Packages pip3 install pyarr python-dotenv

null 7 Dec 6, 2022
A simple bot that will help you in your learning and make it more fun.

hyperskill-SimpleChattyBot-python A simple bot that will help you in your learning and make it more fun. Syntax bot.py Stages Stage #1: Zuhura Bot we

null 1 Nov 9, 2021
Custom SLURM wrapper scripts to make finding job histories and system resource usage more easily accessible

SLURM Wrappers Executables job-history A simple wrapper for grabbing data for completed and running jobs. nodes-busy Developed for the HPC systems at

Sara 2 Dec 13, 2021
This is the community maintained fork of ungleich's cdist (after f061fb1).

cdist This is the community maintained fork of ungleich's cdist (after f061fb1). Work is split between three repositories: cdist - implementation of t

cdist community edition 0 Aug 2, 2022
An After Effects render queue for ShotGrid Toolkit.

AEQueue An After Effects render queue for ShotGrid Toolkit. Features Render multiple comps to locations defined by templates in your Toolkit config. C

Brand New School 5 Nov 20, 2022