diff --git a/antlir/artifacts_dir.rs b/antlir/artifacts_dir.rs index d95e746d920..63aa2828fb1 100644 --- a/antlir/artifacts_dir.rs +++ b/antlir/artifacts_dir.rs @@ -18,7 +18,11 @@ fn ensure_path_in_repo(py: Python<'_>, path_in_repo: Option) -> PyResul match path_in_repo { Some(p) => Ok(p), None => { - let argv0: String = py.import("sys")?.getattr("argv")?.get_item(0)?.extract()?; + let argv0: String = py + .import_bound("sys")? + .getattr("argv")? + .get_item(0)? + .extract()?; let argv0 = PathBuf::from(argv0); Ok(argv0.canonicalize()?) } @@ -26,14 +30,15 @@ fn ensure_path_in_repo(py: Python<'_>, path_in_repo: Option) -> PyResul } #[pymodule] -pub fn artifacts_dir(py: Python<'_>, m: &PyModule) -> PyResult<()> { - m.add("SigilNotFound", py.get_type::())?; +pub fn artifacts_dir(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> { + m.add("SigilNotFound", py.get_type_bound::())?; /// find_repo_root($self, path_in_repo = None) /// -- /// /// Find the path of the VCS repository root. #[pyfn(m)] + #[pyo3(signature = (path_in_repo=None))] fn find_repo_root(py: Python<'_>, path_in_repo: Option) -> PyResult { let path_in_repo = ensure_path_in_repo(py, path_in_repo.map(|p| p.into()))?; match find_root::find_repo_root(path_in_repo) { diff --git a/antlir/fs_utils_rs.rs b/antlir/fs_utils_rs.rs index ea4b387d7fa..6dd5662cce9 100644 --- a/antlir/fs_utils_rs.rs +++ b/antlir/fs_utils_rs.rs @@ -54,9 +54,9 @@ impl IntoPy for AntlirPath { // Python->Rust->Python, but it's a necessary indirection evil // until/unless we replace antlir.fs_utils.Path with a Rust // implementation - let fs_utils = - PyModule::import(py, "antlir.fs_utils").expect("antlir.fs_utils must be available"); - let bytes = PyBytes::new(py, self.0.as_os_str().as_bytes()); + let fs_utils = PyModule::import_bound(py, "antlir.fs_utils") + .expect("antlir.fs_utils must be available"); + let bytes = PyBytes::new_bound(py, self.0.as_os_str().as_bytes()); // finally, create a fs_utils.Path from the bytes object fs_utils .getattr("Path") @@ -67,8 +67,8 @@ impl IntoPy for AntlirPath { } } -impl<'source> FromPyObject<'source> for AntlirPath { - fn extract(p: &'source PyAny) -> PyResult { +impl<'py> FromPyObject<'py> for AntlirPath { + fn extract_bound(p: &Bound<'py, PyAny>) -> PyResult { // first attempt to get a raw bytes string, which most paths should // already be if let Ok(bytes) = p.downcast::() { @@ -88,13 +88,13 @@ impl<'source> FromPyObject<'source> for AntlirPath { } #[pymodule] -pub fn fs_utils_rs(_py: Python<'_>, m: &PyModule) -> PyResult<()> { +pub fn fs_utils_rs(_py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> { /// Largely just useful for tests from Python, this will take the given /// input and attempt to round-trip it through [Path] and back into an /// `antlir.fs_utils.Path` #[pyfn(m)] #[pyo3(name = "Path")] - fn path(p: &PyAny) -> PyResult { + fn path(p: &Bound) -> PyResult { p.extract() } diff --git a/antlir/rust/BUCK b/antlir/rust/BUCK index 4c426f68cd0..a92636cb207 100644 --- a/antlir/rust/BUCK +++ b/antlir/rust/BUCK @@ -36,7 +36,7 @@ write_file( out = "register_modules.rs", content = [ "use pyo3::prelude::*;", - "pub(crate) fn register_modules(py: Python<'_>, m: &PyModule) -> PyResult<()> {", + "pub(crate) fn register_modules(py: Python<'_>, m: &Bound) -> PyResult<()> {", ] + [ 'submodule!({}, "{}", py, m)?;'.format(crate, module) for crate, module in extension_modules.items() diff --git a/antlir/rust/src/lib.rs b/antlir/rust/src/lib.rs index 089240998ab..346dcae963d 100644 --- a/antlir/rust/src/lib.rs +++ b/antlir/rust/src/lib.rs @@ -13,9 +13,9 @@ use pyo3::prelude::*; /// (https://pyo3.rs/v0.16.4/module.html) macro_rules! submodule { ($module:ident, $full_module_name:literal, $py:ident, $parent_module:ident) => {{ - let child_module = PyModule::new($py, stringify!($module))?; - $module::$module($py, child_module)?; - $parent_module.add_submodule(child_module)?; + let child_module = PyModule::new_bound($py, stringify!($module))?; + $module::$module($py, &child_module)?; + $parent_module.add_submodule(&child_module)?; // Small hack to enable intuitive Python import resolution. All // submodules technically come from loading `antlir.rust`, but we want @@ -26,7 +26,7 @@ macro_rules! submodule { // there might be in pure-Python module imports, since all the // initialization is done as part of importing the top level // `antlir.rust` module in the first place. - $py.import("sys")? + $py.import_bound("sys")? .getattr("modules")? .set_item($full_module_name, child_module)?; Ok::<_, pyo3::PyErr>(()) @@ -37,7 +37,7 @@ mod register_modules; #[pymodule] #[pyo3(name = "native_antlir_impl")] -fn native(py: Python<'_>, m: &PyModule) -> PyResult<()> { +fn native(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> { register_modules::register_modules(py, m)?; Ok(()) }