-
I have included some package data as described in the guide, but am unsure the best way to get its path once installed. In Python I would use |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 8 replies
-
I think it's the same for maturin since maturin does nothing special. If it doesn't work for you, it might be a implementation bug in maturin, in that case please file a bug report. cc @konstin |
Beta Was this translation helpful? Give feedback.
-
Based on @messense response I came up with this to get the base path to a package. fn resources_path(py: Python<'_>, package: &str) -> PyResult<PathBuf> {
let resources = py.import("importlib.resources")?;
let files = resources.call_method1("files", (package,))?;
let files = resources.call_method1("as_file", (files,))?;
let path = files.call_method0("__enter__")?; // enter python context manager
let path: PathBuf = path.extract()?;
let none = py.None();
files.call_method1("__exit__", (&none, &none, &none))?; // exit python context manager
Ok(path)
} If anybody has feedback on the "goodness" of this, I would greatly appreciate the code review. |
Beta Was this translation helpful? Give feedback.
-
While this seems to get the path to the |
Beta Was this translation helpful? Give feedback.
Perhaps I should call
__exit__
based on the result ofpath.extract
?