From b17d7fe27a68c0ea93fb0d6e5b81fe3c166dcee0 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Sat, 16 Nov 2024 14:16:39 +0100 Subject: build(treewide): Update dependencies --- crates/yt_dlp/src/lib.rs | 26 +++++++++++++------------- crates/yt_dlp/src/logging.rs | 16 +++++++++++----- 2 files changed, 24 insertions(+), 18 deletions(-) (limited to 'crates/yt_dlp/src') diff --git a/crates/yt_dlp/src/lib.rs b/crates/yt_dlp/src/lib.rs index 980d807..970bfe2 100644 --- a/crates/yt_dlp/src/lib.rs +++ b/crates/yt_dlp/src/lib.rs @@ -26,7 +26,7 @@ use pyo3::types::{PyString, PyTuple, PyTupleMethods}; use pyo3::{ pyfunction, types::{PyAnyMethods, PyDict, PyDictMethods, PyList, PyListMethods, PyModule}, - wrap_pyfunction_bound, Bound, PyAny, PyResult, Python, + wrap_pyfunction, Bound, PyAny, PyResult, Python, }; use serde::Serialize; use serde_json::{Map, Value}; @@ -53,7 +53,7 @@ pub fn add_logger_and_sig_handler<'a>( ) -> PyResult> { setup_logging(py, "yt_dlp")?; - let logging = PyModule::import_bound(py, "logging")?; + let logging = PyModule::import(py, "logging")?; let ytdl_logger = logging.call_method1("getLogger", ("yt_dlp",))?; // Ensure that all events are logged by setting the log level to NOTSET (we filter on rust's side) @@ -62,8 +62,8 @@ pub fn add_logger_and_sig_handler<'a>( // Disable the SIGINT (Ctrl+C) handler, python installs. // This allows the user to actually stop the application with Ctrl+C. // This is here because it can only be run in the main thread and this was here already. - py.run_bound( - "\ + py.run( + c"\ import signal signal.signal(signal.SIGINT, signal.SIG_DFL)", None, @@ -71,7 +71,7 @@ signal.signal(signal.SIGINT, signal.SIG_DFL)", ) .expect("This code should always work"); - let config_opts = PyDict::new_bound(py); + let config_opts = PyDict::new(py); config_opts .set_item("level", 0) .expect("Setting this item should always work"); @@ -285,12 +285,12 @@ pub fn progress_hook(py: Python<'_>, input: &Bound<'_, PyDict>) -> PyResult<()> pub fn add_hooks<'a>(opts: Bound<'a, PyDict>, py: Python<'_>) -> PyResult> { if let Some(hooks) = opts.get_item("progress_hooks")? { let hooks = hooks.downcast::()?; - hooks.append(wrap_pyfunction_bound!(progress_hook, py)?)?; + hooks.append(wrap_pyfunction!(progress_hook, py)?)?; opts.set_item("progress_hooks", hooks)?; } else { // No hooks are set yet - let hooks_list = PyList::new_bound(py, &[wrap_pyfunction_bound!(progress_hook, py)?]); + let hooks_list = PyList::new(py, &[wrap_pyfunction!(progress_hook, py)?])?; opts.set_item("progress_hooks", hooks_list)?; } @@ -327,7 +327,7 @@ pub async fn extract_info( let instance = get_yt_dlp(py, opts)?; let args = (url.as_str(),); - let kwargs = PyDict::new_bound(py); + let kwargs = PyDict::new(py); kwargs.set_item("download", download)?; kwargs.set_item("process", process)?; @@ -417,10 +417,10 @@ fn json_map_to_py_dict<'a>( fn json_dumps(py: Python<'_>, input: Bound<'_, PyAny>) -> PyResult { // json.dumps(yt_dlp.sanitize_info(input)) - let yt_dlp = get_yt_dlp(py, PyDict::new_bound(py))?; + let yt_dlp = get_yt_dlp(py, PyDict::new(py))?; let sanitized_result = yt_dlp.call_method1("sanitize_info", (input,))?; - let json = PyModule::import_bound(py, "json")?; + let json = PyModule::import(py, "json")?; let dumps = json.getattr("dumps")?; let output = dumps.call1((sanitized_result,))?; @@ -439,7 +439,7 @@ fn json_loads_str(py: Python<'_>, input: T) -> PyResult, input: String) -> PyResult> { // json.loads(input) - let json = PyModule::import_bound(py, "json")?; + let json = PyModule::import(py, "json")?; let dumps = json.getattr("loads")?; let output = dumps.call1((input,))?; @@ -451,7 +451,7 @@ fn json_loads(py: Python<'_>, input: String) -> PyResult> { } fn get_yt_dlp_utils(py: Python<'_>) -> PyResult> { - let yt_dlp = PyModule::import_bound(py, "yt_dlp")?; + let yt_dlp = PyModule::import(py, "yt_dlp")?; let utils = yt_dlp.getattr("utils")?; Ok(utils) @@ -461,7 +461,7 @@ fn get_yt_dlp<'a>(py: Python<'a>, opts: Bound<'a, PyDict>) -> PyResult, rust_target: &str) -> PyResult<()> { /// Registers the `host_log` function in rust as the event handler for Python's logging logger /// This function needs to be called from within a pyo3 context as early as possible to ensure logging messages /// arrive to the rust consumer. +/// +/// # Panics +/// Only if internal assertions fail. #[allow(clippy::module_name_repetitions)] pub fn setup_logging(py: Python<'_>, target: &str) -> PyResult<()> { - let logging = py.import_bound("logging")?; + let logging = py.import("logging")?; logging.setattr("host_log", wrap_pyfunction!(host_log, &logging)?)?; - py.run_bound( - format!( + py.run( + CString::new(format!( r#" class HostHandler(Handler): def __init__(self, level=0): @@ -113,8 +118,9 @@ def basicConfig(*pargs, **kwargs): kwargs["handlers"] = [HostHandler()] return oldBasicConfig(*pargs, **kwargs) "# - ) - .as_str(), + )) + .expect("This is hardcoded") + .as_c_str(), Some(&logging.dict()), None, )?; -- cgit 1.4.1