Skip to content

Commit 282e48f

Browse files
: python/tests/test_actors.py: more contextmgr improvements
Summary: this refactors the python-side config helpers to make Runtime-layer overrides explicit and reversible, replaces the previous "restore from snapshot" approach with a clearer model that writes into the Runtime layer on entry and clears it on exit, and exposes a Rust-backed `clear()` to support that. the main functional change is adding `configured_with_redirected_stdio()`, which composes configuration overrides with stdio redirection in a single context manager so the tests don't need nested with blocks. all affected tests are updated to use the combined form, but the underlying logging behaviour is unchanged. Differential Revision: D87795973
1 parent c7dae4c commit 282e48f

File tree

4 files changed

+426
-326
lines changed

4 files changed

+426
-326
lines changed

hyperactor/src/config/global.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,8 +524,7 @@ pub fn create_or_merge(source: Source, attrs: Attrs) {
524524
/// contribute to resolution in [`get`], [`get_cloned`], or
525525
/// [`attrs`]. Defaults and any remaining layers continue to apply
526526
/// in their normal priority order.
527-
#[allow(dead_code)]
528-
pub(crate) fn clear(source: Source) {
527+
pub fn clear(source: Source) {
529528
let mut g = LAYERS.write().unwrap();
530529
g.ordered.retain(|l| layer_source(l) != source);
531530
}

monarch_hyperactor/src/config.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,18 @@ fn configure(py: Python<'_>, kwargs: Option<HashMap<String, PyObject>>) -> PyRes
211211
Ok(())
212212
}
213213

214+
/// Clear runtime configuration overrides.
215+
///
216+
/// This removes all entries from the Runtime config layer for this
217+
/// process (e.g. set via test fixtures or ad-hoc tweaking), without
218+
/// affecting any other layers (env, file, test overrides, or built-in
219+
/// defaults).
220+
#[pyfunction]
221+
fn clear(_py: Python<'_>) -> PyResult<()> {
222+
hyperactor::config::global::clear(Source::Runtime);
223+
Ok(())
224+
}
225+
214226
/// For all attribute keys whose `@meta(CONFIG = ConfigAttr { py_name:
215227
/// Some(...), .. })` specifies a kwarg name, return the current
216228
/// associated value in the global config. Keys with no value in the
@@ -252,5 +264,12 @@ pub fn register_python_bindings(module: &Bound<'_, PyModule>) -> PyResult<()> {
252264
)?;
253265
module.add_function(get_configuration)?;
254266

267+
let clear = wrap_pyfunction!(clear, module)?;
268+
clear.setattr(
269+
"__module__",
270+
"monarch._rust_bindings.monarch_hyperactor.config",
271+
)?;
272+
module.add_function(clear)?;
273+
255274
Ok(())
256275
}

python/monarch/_rust_bindings/monarch_hyperactor/config.pyi

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,33 @@ def configure(
2828
enable_log_forwarding: bool = False,
2929
enable_file_capture: bool = False,
3030
tail_log_lines: int = 0,
31-
) -> None: ...
32-
def get_configuration() -> Dict[str, Any]: ...
31+
) -> None:
32+
"""Configure Hyperactor runtime defaults for this process.
33+
34+
This updates the **runtime** configuration layer from Python,
35+
setting the default channel transport and optional logging
36+
behaviour (forwarding, file capture, and how many lines to tail).
37+
Environment-based settings remain in effect and are merged with
38+
these runtime overrides.
39+
40+
"""
41+
...
42+
43+
def clear() -> None:
44+
"""Clear runtime configuration overrides applied from Python.
45+
46+
This resets the **runtime** configuration layer back to its
47+
baseline, undoing any overrides set via this module during the
48+
lifetime of the process.
49+
50+
"""
51+
...
52+
53+
def get_configuration() -> Dict[str, Any]:
54+
"""Return a snapshot of the current Hyperactor configuration.
55+
56+
The result is a plain dictionary view of the merged configuration
57+
(defaults plus any overrides from environment or Python), useful
58+
for debugging and tests.
59+
"""
60+
...

0 commit comments

Comments
 (0)