Skip to main content

Module for making changes in code during runtime

Project description

Dynamic-executor library for changing python code during runtime

Dynamic python is ment to be used in test development for creating and updating tests or wherever the need arises to change the code during runtime and have results visible instantaneously without restarting. The main functionality is provided by exec_in_dynamic_mode generator that reloads all project-root modules (neither builtin not venv modules are reloaded)

Installation

You can install the dynamic-executor package using pip:

pip install dynamic-executor

Or by cloning the repository directly :

git clone git@github.com:Tesla2000/dynamic_executor.git

Example

Here's an example of how to use the exec_in_dynamic_mode function:

# ImportedModuleFaulty.py
from dython import DynamicClass


class SomeDynamicClass(DynamicClass):
    def foo(self):
        raise ValueError
# ImportedModuleValid.py
from dython import DynamicClass


class SomeDynamicClass(DynamicClass):
    def foo(self):
        pass
# test_executor.py
dynamic_instance.foo()
from dython import exec_in_dynamic_mode
parent = Path(__file__).parent
parent.joinpath("ImportedModule.py").write_text(
    parent.joinpath("ImportedModuleFaulty.py").read_text()
)  # faulty version of imported module
from ImportedModule import SomeDynamicClass
dynamic_instance = SomeDynamicClass()
index = -1
for index, error in enumerate(exec_in_dynamic_mode(locals(), globals(), parent.joinpath("test_executor.py"))):
    if index:
        assert False  # ensuring that the error is corrected
    parent.joinpath("ImportedModule.py").write_text(
        parent.joinpath("ImportedModuleValid.py").read_text()
    )  # correcting module

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

dynamic-executor-1.0.3.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

dynamic_executor-1.0.3-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file dynamic-executor-1.0.3.tar.gz.

File metadata

  • Download URL: dynamic-executor-1.0.3.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.0

File hashes

Hashes for dynamic-executor-1.0.3.tar.gz
Algorithm Hash digest
SHA256 4490251be60fa43fe3bb34316752d787983de1587d30065f0e6a120f9c70addb
MD5 5d88bc174e7858792c707f27880ef51d
BLAKE2b-256 b4087b647d4f448998904c65baae7881ea9616146315aee211ad631853b723f9

See more details on using hashes here.

File details

Details for the file dynamic_executor-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for dynamic_executor-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 286b32988f703bd5de0e99cbd7f15a2bc96830bbd9ee5bed7913391141098b16
MD5 55f1a7a099079e8934c087aeb758edd7
BLAKE2b-256 955ae00641db61901b759559609d0bac3022e97ba664a06f5be0365b88fda6e7

See more details on using hashes here.

Supported by

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