From 3d9cbc5d142ae77a0b1823090144b2a3fafa98d2 Mon Sep 17 00:00:00 2001 From: Tpt Date: Wed, 18 Jan 2023 17:52:01 +0100 Subject: [PATCH] Migrates to pyO3 0.18 --- Cargo.lock | 30 +++++++++++++++--------------- python/Cargo.toml | 2 +- python/src/io.rs | 1 - python/src/model.rs | 4 ++-- python/src/store.rs | 31 +++++-------------------------- 5 files changed, 23 insertions(+), 45 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e3b02f2d..a1547627 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -860,18 +860,18 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "memoffset" -version = "0.6.5" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" +checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4" dependencies = [ "autocfg", ] [[package]] name = "memoffset" -version = "0.7.1" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4" +checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1" dependencies = [ "autocfg", ] @@ -1248,14 +1248,14 @@ dependencies = [ [[package]] name = "pyo3" -version = "0.17.3" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "268be0c73583c183f2b14052337465768c07726936a260f480f0857cb95ba543" +checksum = "ccd4149c8c3975099622b4e1962dac27565cf5663b76452c3e2b66e0b6824277" dependencies = [ "cfg-if", "indoc", "libc", - "memoffset 0.6.5", + "memoffset 0.8.0", "parking_lot", "pyo3-build-config", "pyo3-ffi", @@ -1265,9 +1265,9 @@ dependencies = [ [[package]] name = "pyo3-build-config" -version = "0.17.3" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28fcd1e73f06ec85bf3280c48c67e731d8290ad3d730f8be9dc07946923005c8" +checksum = "9cd09fe469834db21ee60e0051030339e5d361293d8cb5ec02facf7fdcf52dbf" dependencies = [ "once_cell", "target-lexicon", @@ -1275,9 +1275,9 @@ dependencies = [ [[package]] name = "pyo3-ffi" -version = "0.17.3" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f6cb136e222e49115b3c51c32792886defbfb0adead26a688142b346a0b9ffc" +checksum = "0c427c9a96b9c5b12156dbc11f76b14f49e9aae8905ca783ea87c249044ef137" dependencies = [ "libc", "pyo3-build-config", @@ -1285,9 +1285,9 @@ dependencies = [ [[package]] name = "pyo3-macros" -version = "0.17.3" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94144a1266e236b1c932682136dc35a9dee8d3589728f68130c7c3861ef96b28" +checksum = "16b822bbba9d60630a44d2109bc410489bb2f439b33e3a14ddeb8a40b378a7c4" dependencies = [ "proc-macro2", "pyo3-macros-backend", @@ -1297,9 +1297,9 @@ dependencies = [ [[package]] name = "pyo3-macros-backend" -version = "0.17.3" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8df9be978a2d2f0cdebabb03206ed73b11314701a5bfe71b0d753b81997777f" +checksum = "84ae898104f7c99db06231160770f3e40dad6eb9021daddc0fedfa3e41dff10a" dependencies = [ "proc-macro2", "quote", diff --git a/python/Cargo.toml b/python/Cargo.toml index 5a4a9c92..a744351b 100644 --- a/python/Cargo.toml +++ b/python/Cargo.toml @@ -20,4 +20,4 @@ abi3 = ["pyo3/abi3-py37"] [dependencies] oxigraph = { version = "0.3.10", path="../lib", features = ["http_client"] } -pyo3 = { version = "0.17", features = ["extension-module"] } +pyo3 = { version = "0.18", features = ["extension-module"] } diff --git a/python/src/io.rs b/python/src/io.rs index 64b1b028..a34377c0 100644 --- a/python/src/io.rs +++ b/python/src/io.rs @@ -117,7 +117,6 @@ pub fn parse( /// >>> output.getvalue() /// b' "1" .\n' #[pyfunction] -#[pyo3(text_signature = "(input, output, mime_type)")] pub fn serialize(input: &PyAny, output: PyObject, mime_type: &str, py: Python<'_>) -> PyResult<()> { let output = if let Ok(path) = output.extract::<&str>(py) { PyWritable::from_file(path, py) diff --git a/python/src/model.rs b/python/src/model.rs index d050516d..864b68d3 100644 --- a/python/src/model.rs +++ b/python/src/model.rs @@ -262,11 +262,11 @@ impl From for Term { #[pymethods] impl PyLiteral { #[new] - #[args(value, "*", datatype = "None", language = "None")] + #[pyo3(signature = (value, *, datatype = None, language = None))] fn new( value: String, - language: Option, datatype: Option, + language: Option, ) -> PyResult { Ok(if let Some(language) = language { if let Some(datatype) = datatype { diff --git a/python/src/store.rs b/python/src/store.rs index 8ae81d43..c7ac180a 100644 --- a/python/src/store.rs +++ b/python/src/store.rs @@ -66,7 +66,6 @@ impl PyStore { /// >>> store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g'))) /// >>> list(store) /// [ predicate= object=> graph_name=>] - #[pyo3(text_signature = "($self, quad)")] fn add(&self, quad: &PyQuad, py: Python<'_>) -> PyResult<()> { py.allow_threads(|| { self.inner.insert(quad).map_err(map_storage_error)?; @@ -87,7 +86,6 @@ impl PyStore { /// >>> store.remove(quad) /// >>> list(store) /// [] - #[pyo3(text_signature = "($self, quad)")] fn remove(&self, quad: &PyQuad, py: Python<'_>) -> PyResult<()> { py.allow_threads(|| { self.inner.remove(quad).map_err(map_storage_error)?; @@ -171,16 +169,9 @@ impl PyStore { /// >>> store.query('ASK { ?s ?p ?o }') /// True #[pyo3( + signature = (query, *, base_iri = None, use_default_graph_as_union = false, default_graph = None, named_graphs = None), text_signature = "($self, query, *, base_iri = None, use_default_graph_as_union = False, default_graph = None, named_graphs = None)" )] - #[args( - query, - "*", - base_iri = "None", - use_default_graph_as_union = "false", - default_graph = "None", - named_graphs = "None" - )] fn query( &self, query: &str, @@ -236,8 +227,7 @@ impl PyStore { /// >>> store.update('DELETE WHERE { ?p ?o }') /// >>> list(store) /// [] - #[pyo3(text_signature = "($self, update, *, base_iri = None)")] - #[args(update, "*", base_iri = "None")] + #[pyo3(signature = (update, *, base_iri = None), text_signature = "($self, update, *, base_iri = None)")] fn update(&self, update: &str, base_iri: Option<&str>, py: Python<'_>) -> PyResult<()> { py.allow_threads(|| { let update = @@ -282,8 +272,7 @@ impl PyStore { /// >>> store.load(io.BytesIO(b'

"1" .'), "text/turtle", base_iri="http://example.com/", to_graph=NamedNode("http://example.com/g")) /// >>> list(store) /// [ predicate= object=> graph_name=>] - #[pyo3(text_signature = "($self, input, mime_type, *, base_iri = None, to_graph = None)")] - #[args(input, mime_type, "*", base_iri = "None", to_graph = "None")] + #[pyo3(signature = (input, mime_type, *, base_iri = None, to_graph = None), text_signature = "($self, input, mime_type, *, base_iri = None, to_graph = None)")] fn load( &self, input: PyObject, @@ -366,8 +355,7 @@ impl PyStore { /// >>> store.bulk_load(io.BytesIO(b'

"1" .'), "text/turtle", base_iri="http://example.com/", to_graph=NamedNode("http://example.com/g")) /// >>> list(store) /// [ predicate= object=> graph_name=>] - #[pyo3(text_signature = "($self, input, mime_type, *, base_iri = None, to_graph = None)")] - #[args(input, mime_type, "*", base_iri = "None", to_graph = "None")] + #[pyo3(signature = (input, mime_type, *, base_iri = None, to_graph = None), text_signature = "($self, input, mime_type, *, base_iri = None, to_graph = None)")] fn bulk_load( &self, input: PyObject, @@ -446,8 +434,7 @@ impl PyStore { /// >>> store.dump(output, "text/turtle", from_graph=NamedNode("http://example.com/g")) /// >>> output.getvalue() /// b' "1" .\n' - #[pyo3(text_signature = "($self, output, mime_type, *, from_graph = None)")] - #[args(output, mime_type, "*", from_graph = "None")] + #[pyo3(signature = (output, mime_type, *, from_graph = None), text_signature = "($self, output, mime_type, *, from_graph = None)")] fn dump( &self, output: PyObject, @@ -502,7 +489,6 @@ impl PyStore { /// >>> store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g'))) /// >>> list(store.named_graphs()) /// [] - #[pyo3(text_signature = "($self)")] fn named_graphs(&self) -> GraphNameIter { GraphNameIter { inner: self.inner.named_graphs(), @@ -520,7 +506,6 @@ impl PyStore { /// >>> store.add_graph(NamedNode('http://example.com/g')) /// >>> list(store.named_graphs()) /// [] - #[pyo3(text_signature = "($self, graph_name)")] fn add_graph(&self, graph_name: &PyAny, py: Python<'_>) -> PyResult<()> { let graph_name = GraphName::from(&PyGraphNameRef::try_from(graph_name)?); py.allow_threads(|| { @@ -551,7 +536,6 @@ impl PyStore { /// [] /// >>> list(store.named_graphs()) /// [] - #[pyo3(text_signature = "($self, graph_name)")] fn clear_graph(&self, graph_name: &PyAny, py: Python<'_>) -> PyResult<()> { let graph_name = GraphName::from(&PyGraphNameRef::try_from(graph_name)?); py.allow_threads(|| { @@ -575,7 +559,6 @@ impl PyStore { /// >>> store.remove_graph(NamedNode('http://example.com/g')) /// >>> list(store.named_graphs()) /// [] - #[pyo3(text_signature = "($self, graph_name)")] fn remove_graph(&self, graph_name: &PyAny, py: Python<'_>) -> PyResult<()> { let graph_name = GraphName::from(&PyGraphNameRef::try_from(graph_name)?); py.allow_threads(|| { @@ -604,7 +587,6 @@ impl PyStore { /// [] /// >>> list(store.named_graphs()) /// [] - #[pyo3(text_signature = "($self)")] fn clear(&self, py: Python<'_>) -> PyResult<()> { py.allow_threads(|| self.inner.clear().map_err(map_storage_error)) } @@ -615,7 +597,6 @@ impl PyStore { /// /// :rtype: None /// :raises IOError: if an I/O error happens during the flush. - #[pyo3(text_signature = "($self)")] fn flush(&self, py: Python<'_>) -> PyResult<()> { py.allow_threads(|| self.inner.flush().map_err(map_storage_error)) } @@ -626,7 +607,6 @@ impl PyStore { /// /// :rtype: None /// :raises IOError: if an I/O error happens during the optimization. - #[pyo3(text_signature = "($self)")] fn optimize(&self, py: Python<'_>) -> PyResult<()> { py.allow_threads(|| self.inner.optimize().map_err(map_storage_error)) } @@ -652,7 +632,6 @@ impl PyStore { /// :type target_directory: str /// :rtype: None /// :raises IOError: if an I/O error happens during the backup. - #[pyo3(text_signature = "($self, target_directory)")] fn backup(&self, target_directory: &str, py: Python<'_>) -> PyResult<()> { py.allow_threads(|| { self.inner