Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pyo3 from v0.20 to v0.22 #1893

Merged
merged 4 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 13 additions & 73 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
rand = "0.8"
serde_json = "1.0"
pyo3 = "0.20"
pyo3 = "0.22"
quantum-sparse-sim = { git = "https://github.com/qir-alliance/qir-runner", tag = "v0.7.4" }
async-trait = "0.1"
tokio = { version = "1.35", features = ["macros", "rt"] }
Expand Down
30 changes: 17 additions & 13 deletions pip/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,23 +104,24 @@ impl FileSystem for Py<'_> {
}

fn read_file(py: Python, read_file: &PyObject, path: &Path) -> PyResult<(Arc<str>, Arc<str>)> {
let read_file_result = read_file.call1(py, PyTuple::new(py, &[path.to_string_lossy()]))?;
let read_file_result =
read_file.call1(py, PyTuple::new_bound(py, &[path.to_string_lossy()]))?;

let tuple = read_file_result.downcast::<PyTuple>(py)?;
let tuple = read_file_result.downcast_bound::<PyTuple>(py)?;

Ok((get_tuple_string(tuple, 0)?, get_tuple_string(tuple, 1)?))
}

fn list_directory(py: Python, list_directory: &PyObject, path: &Path) -> PyResult<Vec<Entry>> {
let list_directory_result =
list_directory.call1(py, PyTuple::new(py, &[path.to_string_lossy()]))?;
list_directory.call1(py, PyTuple::new_bound(py, &[path.to_string_lossy()]))?;

list_directory_result
.downcast::<PyList>(py)?
.downcast_bound::<PyList>(py)?
.into_iter()
.map(|e| {
let dict = e.downcast::<PyDict>()?;
let entry_type = match get_dict_string(dict, "type")? {
let entry_type = match get_dict_string(dict, "type")?.to_string().as_str() {
"file" => EntryType::File,
"folder" => EntryType::Folder,
"symlink" => EntryType::Symlink,
Expand All @@ -146,11 +147,14 @@ fn resolve_path(
) -> PyResult<PathBuf> {
let resolve_path_result = resolve_path.call1(
py,
PyTuple::new(py, &[base.to_string_lossy(), path.to_string_lossy()]),
PyTuple::new_bound(py, &[base.to_string_lossy(), path.to_string_lossy()]),
)?;

Ok(PathBuf::from(
resolve_path_result.downcast::<PyString>(py)?.to_str()?,
resolve_path_result
.downcast_bound::<PyString>(py)?
.str()?
.to_string(),
))
}

Expand All @@ -163,31 +167,31 @@ fn fetch_github(
path: &str,
) -> PyResult<Arc<str>> {
let fetch_github_result =
fetch_github.call1(py, PyTuple::new(py, [owner, repo, r#ref, path]))?;
fetch_github.call1(py, PyTuple::new_bound(py, [owner, repo, r#ref, path]))?;

Ok(fetch_github_result
.downcast::<PyString>(py)?
.downcast_bound::<PyString>(py)?
.to_string()
.into())
}

fn get_tuple_string(tuple: &PyTuple, index: usize) -> PyResult<Arc<str>> {
fn get_tuple_string(tuple: &Bound<'_, PyTuple>, index: usize) -> PyResult<Arc<str>> {
Ok(tuple
.get_item(index)?
.downcast::<PyString>()?
.to_string()
.into())
}

fn get_dict_string<'a>(dict: &'a PyDict, key: &'a str) -> PyResult<&'a str> {
fn get_dict_string<'a>(dict: &Bound<'a, PyDict>, key: &'a str) -> PyResult<Bound<'a, PyString>> {
match dict.get_item(key)? {
Some(item) => Ok(item.downcast::<PyString>()?.to_str()?),
Some(item) => Ok(item.downcast::<PyString>()?.str()?),
None => Err(PyException::new_err(format!("missing key `{key}` in dict"))),
}
}

fn diagnostic_from(py: Python<'_>, err: &PyErr) -> miette::Report {
if let Some(traceback) = err.traceback(py) {
if let Some(traceback) = err.traceback_bound(py) {
match traceback.format() {
Ok(traceback) => miette!(format!("{err}\n{traceback}",)),
Err(traceback_err) => {
Expand Down
Loading
Loading