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.2.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: dynamic-executor-1.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 298873f2acf8aeb01212b0a88221faf24045f79a6c2648eca95796fd6f16ec07
MD5 dc01743f16812b5101604ee9b104755c
BLAKE2b-256 64ec778d341b87a4f6a774eba7e2157f3f8a50c023ace57984741b850fe843f0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for dynamic_executor-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 29e56916b5f002a1c92642e203f603f5e5c9b8c4d4316f1d5ea1cc89b6198110
MD5 9ca87b7bfde3e801305c42100692309e
BLAKE2b-256 67c99ec75eb74c8493f16cffa0c9b67204305465c0c167f227be73f170105fce

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