Skip to main content

Pull class methods into Jupyter cells and inject edited versions back — with optional persistence to source files

Project description

jlab_method_pull

Pull class methods into editable JupyterLab cells and inject modified versions back — optionally rewriting the source file for persistence.

Install

pip install jlab_method_pull

To make pullMethodCode and injectMethod available automatically in every JupyterLab kernel, run once:

from jlab_method_pull import install
install()

Usage

Pull a method into a new cell

from jlab_method_pull import pullMethodCode, injectMethod
from mymodule import MyClass

pullMethodCode(MyClass.some_method)

A new cell appears below, pre-filled with the method's source, all imports from the source file, and a ready-to-run injectMethod call:

import numpy as np
from mymodule import MyClass, OtherClass

def some_method(self, x):
    ...

injectMethod(some_method, MyClass, persistent=False)

Inject a method back

# In-memory only (survives the session, not reimports):
injectMethod(some_method, MyClass, persistent=False)

# Persistent (also rewrites mymodule.py on disk):
injectMethod(some_method, MyClass, persistent=True)

persistent=True uses AST to locate the exact lines of the old method in the source file and replaces them. It works correctly even if the method was previously monkey-patched in memory.

How it compares

Tool Cell injection Runtime patch Rewrites source file
IPython %load file-level only
gorilla yes
jlab_method_pull method-level yes yes

Requirements

  • Python ≥ 3.9
  • IPython (only required for the Jupyter cell injection and install())

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

jlab_method_pull-1.1.0.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

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

jlab_method_pull-1.1.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file jlab_method_pull-1.1.0.tar.gz.

File metadata

  • Download URL: jlab_method_pull-1.1.0.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for jlab_method_pull-1.1.0.tar.gz
Algorithm Hash digest
SHA256 76a36391217c9ec189033ca980f390266b960c52ba9510656d1646b22166fac3
MD5 3a9d897798097652172016a7f20db7f0
BLAKE2b-256 fb2cfe2bba991601d35492c296efac251040f568b9e3ecfc576d516dd004580d

See more details on using hashes here.

File details

Details for the file jlab_method_pull-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for jlab_method_pull-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ae00a438d9632cacb9abb24bf6a71985824f3680d4c51aecb4f8631653b95dc5
MD5 72c0713596e165d226ea7d746bd4b526
BLAKE2b-256 fe4c9f0e1ad7780baa893d9f55599e2a16895256b1fa72cbbe9d6ec66ad98bb4

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