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 dynamic_executor import DynamicClass


class SomeDynamicClass(DynamicClass):
    def foo(self):
        raise ValueError
# ImportedModuleValid.py
from dynamic_executor 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.9.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

dynamic_executor-1.0.9-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dynamic-executor-1.0.9.tar.gz
  • Upload date:
  • Size: 6.1 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.9.tar.gz
Algorithm Hash digest
SHA256 e8d56ed5ae0e582fa052e95604fd988edee8b84b3bc4de7e4447c79870156ac2
MD5 aea4eb17eab8bb2062cde4e16f91c044
BLAKE2b-256 913b5f7beb1d8a84e3dee61c6cb0b7383d2e70095aa99ce12828d9ba2b9e2efa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for dynamic_executor-1.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 7c8c06015e8cd9b17e12faa6bd21629af65e3c588a8937f9cc708c5d5dd89d52
MD5 cd6972eafcef05a488fab607d8709bfc
BLAKE2b-256 41e90c2c0882ad92d08593718d1c1244205c945a721a05c4e57e7af3994f46d7

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