@@ -11,7 +11,7 @@ use std::path::PathBuf;
1111use std:: str:: FromStr ;
1212
1313#[ pyfunction( name = "configure_policy" ) ]
14- #[ pyo3( signature = ( on_recorder_error=None , require_trace=None , keep_partial_trace=None , log_level=None , log_file=None , json_errors=None , io_capture_line_proxies=None , io_capture_fd_fallback=None ) ) ]
14+ #[ pyo3( signature = ( on_recorder_error=None , require_trace=None , keep_partial_trace=None , log_level=None , log_file=None , json_errors=None , io_capture_line_proxies=None , io_capture_fd_fallback=None , module_name_from_globals= None ) ) ]
1515pub fn configure_policy_py (
1616 on_recorder_error : Option < & str > ,
1717 require_trace : Option < bool > ,
@@ -21,6 +21,7 @@ pub fn configure_policy_py(
2121 json_errors : Option < bool > ,
2222 io_capture_line_proxies : Option < bool > ,
2323 io_capture_fd_fallback : Option < bool > ,
24+ module_name_from_globals : Option < bool > ,
2425) -> PyResult < ( ) > {
2526 let mut update = PolicyUpdate :: default ( ) ;
2627
@@ -64,6 +65,10 @@ pub fn configure_policy_py(
6465 update. io_capture_fd_fallback = Some ( value) ;
6566 }
6667
68+ if let Some ( value) = module_name_from_globals {
69+ update. module_name_from_globals = Some ( value) ;
70+ }
71+
6772 apply_policy_update ( update) ;
6873 Ok ( ( ) )
6974}
@@ -97,6 +102,10 @@ pub fn py_policy_snapshot(py: Python<'_>) -> PyResult<PyObject> {
97102 dict. set_item ( "log_file" , py. None ( ) ) ?;
98103 }
99104 dict. set_item ( "json_errors" , snapshot. json_errors ) ?;
105+ dict. set_item (
106+ "module_name_from_globals" ,
107+ snapshot. module_name_from_globals ,
108+ ) ?;
100109
101110 let io_dict = PyDict :: new ( py) ;
102111 io_dict. set_item ( "line_proxies" , snapshot. io_capture . line_proxies ) ?;
@@ -123,6 +132,7 @@ mod tests {
123132 Some ( true ) ,
124133 Some ( true ) ,
125134 Some ( true ) ,
135+ Some ( true ) ,
126136 )
127137 . expect ( "configure policy via PyO3 facade" ) ;
128138
@@ -141,13 +151,24 @@ mod tests {
141151 assert ! ( snap. json_errors) ;
142152 assert ! ( snap. io_capture. line_proxies) ;
143153 assert ! ( snap. io_capture. fd_fallback) ;
154+ assert ! ( snap. module_name_from_globals) ;
144155 reset_policy_for_tests ( ) ;
145156 }
146157
147158 #[ test]
148159 fn configure_policy_py_rejects_invalid_on_recorder_error ( ) {
149160 reset_policy_for_tests ( ) ;
150- let err = configure_policy_py ( Some ( "unknown" ) , None , None , None , None , None , None , None )
161+ let err = configure_policy_py (
162+ Some ( "unknown" ) ,
163+ None ,
164+ None ,
165+ None ,
166+ None ,
167+ None ,
168+ None ,
169+ None ,
170+ None ,
171+ )
151172 . expect_err ( "invalid variant should error" ) ;
152173 // Ensure the error maps through map_recorder_error by checking the display text.
153174 let message = Python :: with_gil ( |py| err. value ( py) . to_string ( ) ) ;
@@ -186,6 +207,7 @@ mod tests {
186207 Some ( true ) ,
187208 Some ( false ) ,
188209 Some ( false ) ,
210+ Some ( false ) ,
189211 )
190212 . expect ( "configure policy" ) ;
191213
@@ -218,6 +240,7 @@ mod tests {
218240 super :: super :: env:: ENV_LOG_FILE ,
219241 super :: super :: env:: ENV_JSON_ERRORS ,
220242 super :: super :: env:: ENV_CAPTURE_IO ,
243+ super :: super :: env:: ENV_MODULE_NAME_FROM_GLOBALS ,
221244 ] {
222245 std:: env:: remove_var ( key) ;
223246 }
0 commit comments