Reloadr's hot-reloading Python code + a bunch of little extensions.
Project description
Reloadrable
Reloadr + A Bunch of Little Extensions.
Reloadr is a great tool to hot-reload Python code.
This library is based on Reloadr, with a bunch of little extensions added.
List of added features
- Made some functions to be public to suppress IDE's warning
- Ways to stop periodical reloads and to stop reloads on file modifications
- Decorators for periodical reloading.
- Added decorators to set an event handler instance that handles a callback on reload and to set a file path to be observed for reloading the target.
- Added logging.
Usage
Add auto-reloading on file modification
You can decorate the target with @autoreload
just like Reloadr.
from reloadrable import autoreload
@autoreload
def target_function(a, b):
return a + b
@autoreload
class TargetClass:
def __init__(self):
print("Target class is created.")
Add periodic reloading
You can decorate the target with @autoupdate
instead of @autoreload
.
from reloadrable import autoupdate, ReloadableHandler
@autoupdate
def target_function(a, b):
return a + b
@autoupdate
class TargetClass:
def __init__(self):
print("Target class is created.")
Add auto-reloading on file modification with specific settings
You can use @autoreload_with
to set an event handler and/or a file path to be observed.
from reloadrable import autoreload_with, ReloadableHandler
class FuncReloadingHandler(ReloadableHandler):
def on_reloaded(self, target):
print(f"{str(target)} reloaded")
@autoreload_with(handler=FuncReloadingHandler())
def target_function(a, b):
return a + b
@autoreload_with(file_path="/path/to/be/observed")
class TargetClass:
def __init__(self):
print("Target class is created.")
Add periodic reloading with specific settings
You can use @autoupdate_with
to set an event handler and/or the interval between periodic reloading.
from reloadrable import autoupdate_with, ReloadableHandler
class FuncReloadingHandler(ReloadableHandler):
def on_reloaded(self, target):
print(f"{str(target)} reloaded")
@autoupdate_with(handler=FuncReloadingHandler())
def target_function(a, b):
return a + b
@autoupdate_with(interval=1.5)
class TargetClass:
def __init__(self):
print("Target class is created.")
Manually reload the target
You can manually reload the target just like Reloadr.
Besides, you can manually control reloading without warnings in IDEs.
from pathlib import Path
from reloadrable import reloadr, ReloadableHandler
@reloadr
class Gear:
def shift(self):
print("Rattling")
# Manual reload (just like Reloadr)
Gear._reload()
# Manual reload (without warning in IDEs)
Gear.reload()
# Start auto-reloading on file modification (just like Reloadr)
Gear._start_watch_reload()
# Start auto-reloading on file modification (without warning in IDEs)
Gear.start_on_modified_update()
# Start periodic reloading (just like Reloadr)
Gear._start_timer_reload(1)
# Start periodic reloading (without warning in IDEs)
Gear.start_periodic_update(interval=1)
# Add an event handler
class GearReloadingHandler(ReloadableHandler):
def on_reloaded(self, target):
if isinstance(target, Gear):
target.shift()
Gear.set_handler(handler=GearReloadingHandler())
# Add a file path to be observed for reloading the target
Gear.set_file_path(file_path="/path/to/be/observed")
# You can use pathlib.Path as well as str
Gear.set_file_path(file_path=Path("/path/to/be/observed"))
Manage auto-reloading and observing
You can use ReloadableManager
to stop periodical reloads and to stop reloads on file modifications.
from reloadrable import ReloadableManager
# Stop all periodical reloads
ReloadableManager.stop_periodic_updates()
# Stop all observations of file modification.
ReloadableManager.stop_on_modified_updates()
License & copyright notice
This library is based on Reloadr.
Reloadr
Copyright 2015-2020, Hugo Herter and the Reloadr contributors.
Reloadr is licensed under the GNU Lesser General Public License v3.0.
Reloadrable
Copyright 2021-2021, Yuta Urushiyama,
Copyright 2015-2020, Hugo Herter and the Reloadr contributors.
Reloadrable is licensed under the same license as Reloadr.
Misc
- Back-porting is welcome for me. I made this just because I need it for my personal work as soon as possible.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file Reloadrable-1.0.0.tar.gz
.
File metadata
- Download URL: Reloadrable-1.0.0.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5450a700ad37614a18f98cb56dfbd4b3a20a588577017c33d7c9c266834d67b |
|
MD5 | c0a7eaf83bdfd2500d032014318288f1 |
|
BLAKE2b-256 | ec8d15c9f90407034bb32a005d86a109d8429b1d46bd63cdaab5b7978b5d9a7a |
File details
Details for the file Reloadrable-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: Reloadrable-1.0.0-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1477bab82cd24682e0ae015fdd049c1873808ea0c1db0c1fa246a42285224976 |
|
MD5 | 9b189dd68e39080a9e0a9699a52dadce |
|
BLAKE2b-256 | 5df0c9e4bbaf1e49734d844a6ed511c29503c81051a71b477134f1f4bce5d61f |