Migrates to pyO3 0.18

pull/365/head
Tpt 2 years ago committed by Thomas Tanon
parent 0c23589187
commit 3d9cbc5d14
  1. 30
      Cargo.lock
  2. 2
      python/Cargo.toml
  3. 1
      python/src/io.rs
  4. 4
      python/src/model.rs
  5. 31
      python/src/store.rs

30
Cargo.lock generated

@ -860,18 +860,18 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
[[package]] [[package]]
name = "memoffset" name = "memoffset"
version = "0.6.5" version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4"
dependencies = [ dependencies = [
"autocfg", "autocfg",
] ]
[[package]] [[package]]
name = "memoffset" name = "memoffset"
version = "0.7.1" version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4" checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1"
dependencies = [ dependencies = [
"autocfg", "autocfg",
] ]
@ -1248,14 +1248,14 @@ dependencies = [
[[package]] [[package]]
name = "pyo3" name = "pyo3"
version = "0.17.3" version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "268be0c73583c183f2b14052337465768c07726936a260f480f0857cb95ba543" checksum = "ccd4149c8c3975099622b4e1962dac27565cf5663b76452c3e2b66e0b6824277"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"indoc", "indoc",
"libc", "libc",
"memoffset 0.6.5", "memoffset 0.8.0",
"parking_lot", "parking_lot",
"pyo3-build-config", "pyo3-build-config",
"pyo3-ffi", "pyo3-ffi",
@ -1265,9 +1265,9 @@ dependencies = [
[[package]] [[package]]
name = "pyo3-build-config" name = "pyo3-build-config"
version = "0.17.3" version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28fcd1e73f06ec85bf3280c48c67e731d8290ad3d730f8be9dc07946923005c8" checksum = "9cd09fe469834db21ee60e0051030339e5d361293d8cb5ec02facf7fdcf52dbf"
dependencies = [ dependencies = [
"once_cell", "once_cell",
"target-lexicon", "target-lexicon",
@ -1275,9 +1275,9 @@ dependencies = [
[[package]] [[package]]
name = "pyo3-ffi" name = "pyo3-ffi"
version = "0.17.3" version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f6cb136e222e49115b3c51c32792886defbfb0adead26a688142b346a0b9ffc" checksum = "0c427c9a96b9c5b12156dbc11f76b14f49e9aae8905ca783ea87c249044ef137"
dependencies = [ dependencies = [
"libc", "libc",
"pyo3-build-config", "pyo3-build-config",
@ -1285,9 +1285,9 @@ dependencies = [
[[package]] [[package]]
name = "pyo3-macros" name = "pyo3-macros"
version = "0.17.3" version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94144a1266e236b1c932682136dc35a9dee8d3589728f68130c7c3861ef96b28" checksum = "16b822bbba9d60630a44d2109bc410489bb2f439b33e3a14ddeb8a40b378a7c4"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"pyo3-macros-backend", "pyo3-macros-backend",
@ -1297,9 +1297,9 @@ dependencies = [
[[package]] [[package]]
name = "pyo3-macros-backend" name = "pyo3-macros-backend"
version = "0.17.3" version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c8df9be978a2d2f0cdebabb03206ed73b11314701a5bfe71b0d753b81997777f" checksum = "84ae898104f7c99db06231160770f3e40dad6eb9021daddc0fedfa3e41dff10a"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",

@ -20,4 +20,4 @@ abi3 = ["pyo3/abi3-py37"]
[dependencies] [dependencies]
oxigraph = { version = "0.3.10", path="../lib", features = ["http_client"] } oxigraph = { version = "0.3.10", path="../lib", features = ["http_client"] }
pyo3 = { version = "0.17", features = ["extension-module"] } pyo3 = { version = "0.18", features = ["extension-module"] }

@ -117,7 +117,6 @@ pub fn parse(
/// >>> output.getvalue() /// >>> output.getvalue()
/// b'<http://example.com> <http://example.com/p> "1" .\n' /// b'<http://example.com> <http://example.com/p> "1" .\n'
#[pyfunction] #[pyfunction]
#[pyo3(text_signature = "(input, output, mime_type)")]
pub fn serialize(input: &PyAny, output: PyObject, mime_type: &str, py: Python<'_>) -> PyResult<()> { pub fn serialize(input: &PyAny, output: PyObject, mime_type: &str, py: Python<'_>) -> PyResult<()> {
let output = if let Ok(path) = output.extract::<&str>(py) { let output = if let Ok(path) = output.extract::<&str>(py) {
PyWritable::from_file(path, py) PyWritable::from_file(path, py)

@ -262,11 +262,11 @@ impl From<PyLiteral> for Term {
#[pymethods] #[pymethods]
impl PyLiteral { impl PyLiteral {
#[new] #[new]
#[args(value, "*", datatype = "None", language = "None")] #[pyo3(signature = (value, *, datatype = None, language = None))]
fn new( fn new(
value: String, value: String,
language: Option<String>,
datatype: Option<PyNamedNode>, datatype: Option<PyNamedNode>,
language: Option<String>,
) -> PyResult<Self> { ) -> PyResult<Self> {
Ok(if let Some(language) = language { Ok(if let Some(language) = language {
if let Some(datatype) = datatype { if let Some(datatype) = datatype {

@ -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'))) /// >>> store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g')))
/// >>> list(store) /// >>> list(store)
/// [<Quad subject=<NamedNode value=http://example.com> predicate=<NamedNode value=http://example.com/p> object=<Literal value=1 datatype=<NamedNode value=http://www.w3.org/2001/XMLSchema#string>> graph_name=<NamedNode value=http://example.com/g>>] /// [<Quad subject=<NamedNode value=http://example.com> predicate=<NamedNode value=http://example.com/p> object=<Literal value=1 datatype=<NamedNode value=http://www.w3.org/2001/XMLSchema#string>> graph_name=<NamedNode value=http://example.com/g>>]
#[pyo3(text_signature = "($self, quad)")]
fn add(&self, quad: &PyQuad, py: Python<'_>) -> PyResult<()> { fn add(&self, quad: &PyQuad, py: Python<'_>) -> PyResult<()> {
py.allow_threads(|| { py.allow_threads(|| {
self.inner.insert(quad).map_err(map_storage_error)?; self.inner.insert(quad).map_err(map_storage_error)?;
@ -87,7 +86,6 @@ impl PyStore {
/// >>> store.remove(quad) /// >>> store.remove(quad)
/// >>> list(store) /// >>> list(store)
/// [] /// []
#[pyo3(text_signature = "($self, quad)")]
fn remove(&self, quad: &PyQuad, py: Python<'_>) -> PyResult<()> { fn remove(&self, quad: &PyQuad, py: Python<'_>) -> PyResult<()> {
py.allow_threads(|| { py.allow_threads(|| {
self.inner.remove(quad).map_err(map_storage_error)?; self.inner.remove(quad).map_err(map_storage_error)?;
@ -171,16 +169,9 @@ impl PyStore {
/// >>> store.query('ASK { ?s ?p ?o }') /// >>> store.query('ASK { ?s ?p ?o }')
/// True /// True
#[pyo3( #[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)" 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( fn query(
&self, &self,
query: &str, query: &str,
@ -236,8 +227,7 @@ impl PyStore {
/// >>> store.update('DELETE WHERE { <http://example.com> ?p ?o }') /// >>> store.update('DELETE WHERE { <http://example.com> ?p ?o }')
/// >>> list(store) /// >>> list(store)
/// [] /// []
#[pyo3(text_signature = "($self, update, *, base_iri = None)")] #[pyo3(signature = (update, *, base_iri = None), text_signature = "($self, update, *, base_iri = None)")]
#[args(update, "*", base_iri = "None")]
fn update(&self, update: &str, base_iri: Option<&str>, py: Python<'_>) -> PyResult<()> { fn update(&self, update: &str, base_iri: Option<&str>, py: Python<'_>) -> PyResult<()> {
py.allow_threads(|| { py.allow_threads(|| {
let update = let update =
@ -282,8 +272,7 @@ impl PyStore {
/// >>> store.load(io.BytesIO(b'<foo> <p> "1" .'), "text/turtle", base_iri="http://example.com/", to_graph=NamedNode("http://example.com/g")) /// >>> store.load(io.BytesIO(b'<foo> <p> "1" .'), "text/turtle", base_iri="http://example.com/", to_graph=NamedNode("http://example.com/g"))
/// >>> list(store) /// >>> list(store)
/// [<Quad subject=<NamedNode value=http://example.com/foo> predicate=<NamedNode value=http://example.com/p> object=<Literal value=1 datatype=<NamedNode value=http://www.w3.org/2001/XMLSchema#string>> graph_name=<NamedNode value=http://example.com/g>>] /// [<Quad subject=<NamedNode value=http://example.com/foo> predicate=<NamedNode value=http://example.com/p> object=<Literal value=1 datatype=<NamedNode value=http://www.w3.org/2001/XMLSchema#string>> graph_name=<NamedNode value=http://example.com/g>>]
#[pyo3(text_signature = "($self, 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)")]
#[args(input, mime_type, "*", base_iri = "None", to_graph = "None")]
fn load( fn load(
&self, &self,
input: PyObject, input: PyObject,
@ -366,8 +355,7 @@ impl PyStore {
/// >>> store.bulk_load(io.BytesIO(b'<foo> <p> "1" .'), "text/turtle", base_iri="http://example.com/", to_graph=NamedNode("http://example.com/g")) /// >>> store.bulk_load(io.BytesIO(b'<foo> <p> "1" .'), "text/turtle", base_iri="http://example.com/", to_graph=NamedNode("http://example.com/g"))
/// >>> list(store) /// >>> list(store)
/// [<Quad subject=<NamedNode value=http://example.com/foo> predicate=<NamedNode value=http://example.com/p> object=<Literal value=1 datatype=<NamedNode value=http://www.w3.org/2001/XMLSchema#string>> graph_name=<NamedNode value=http://example.com/g>>] /// [<Quad subject=<NamedNode value=http://example.com/foo> predicate=<NamedNode value=http://example.com/p> object=<Literal value=1 datatype=<NamedNode value=http://www.w3.org/2001/XMLSchema#string>> graph_name=<NamedNode value=http://example.com/g>>]
#[pyo3(text_signature = "($self, 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)")]
#[args(input, mime_type, "*", base_iri = "None", to_graph = "None")]
fn bulk_load( fn bulk_load(
&self, &self,
input: PyObject, input: PyObject,
@ -446,8 +434,7 @@ impl PyStore {
/// >>> store.dump(output, "text/turtle", from_graph=NamedNode("http://example.com/g")) /// >>> store.dump(output, "text/turtle", from_graph=NamedNode("http://example.com/g"))
/// >>> output.getvalue() /// >>> output.getvalue()
/// b'<http://example.com> <http://example.com/p> "1" .\n' /// b'<http://example.com> <http://example.com/p> "1" .\n'
#[pyo3(text_signature = "($self, output, mime_type, *, from_graph = None)")] #[pyo3(signature = (output, mime_type, *, from_graph = None), text_signature = "($self, output, mime_type, *, from_graph = None)")]
#[args(output, mime_type, "*", from_graph = "None")]
fn dump( fn dump(
&self, &self,
output: PyObject, 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'))) /// >>> store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g')))
/// >>> list(store.named_graphs()) /// >>> list(store.named_graphs())
/// [<NamedNode value=http://example.com/g>] /// [<NamedNode value=http://example.com/g>]
#[pyo3(text_signature = "($self)")]
fn named_graphs(&self) -> GraphNameIter { fn named_graphs(&self) -> GraphNameIter {
GraphNameIter { GraphNameIter {
inner: self.inner.named_graphs(), inner: self.inner.named_graphs(),
@ -520,7 +506,6 @@ impl PyStore {
/// >>> store.add_graph(NamedNode('http://example.com/g')) /// >>> store.add_graph(NamedNode('http://example.com/g'))
/// >>> list(store.named_graphs()) /// >>> list(store.named_graphs())
/// [<NamedNode value=http://example.com/g>] /// [<NamedNode value=http://example.com/g>]
#[pyo3(text_signature = "($self, graph_name)")]
fn add_graph(&self, graph_name: &PyAny, py: Python<'_>) -> PyResult<()> { fn add_graph(&self, graph_name: &PyAny, py: Python<'_>) -> PyResult<()> {
let graph_name = GraphName::from(&PyGraphNameRef::try_from(graph_name)?); let graph_name = GraphName::from(&PyGraphNameRef::try_from(graph_name)?);
py.allow_threads(|| { py.allow_threads(|| {
@ -551,7 +536,6 @@ impl PyStore {
/// [] /// []
/// >>> list(store.named_graphs()) /// >>> list(store.named_graphs())
/// [<NamedNode value=http://example.com/g>] /// [<NamedNode value=http://example.com/g>]
#[pyo3(text_signature = "($self, graph_name)")]
fn clear_graph(&self, graph_name: &PyAny, py: Python<'_>) -> PyResult<()> { fn clear_graph(&self, graph_name: &PyAny, py: Python<'_>) -> PyResult<()> {
let graph_name = GraphName::from(&PyGraphNameRef::try_from(graph_name)?); let graph_name = GraphName::from(&PyGraphNameRef::try_from(graph_name)?);
py.allow_threads(|| { py.allow_threads(|| {
@ -575,7 +559,6 @@ impl PyStore {
/// >>> store.remove_graph(NamedNode('http://example.com/g')) /// >>> store.remove_graph(NamedNode('http://example.com/g'))
/// >>> list(store.named_graphs()) /// >>> list(store.named_graphs())
/// [] /// []
#[pyo3(text_signature = "($self, graph_name)")]
fn remove_graph(&self, graph_name: &PyAny, py: Python<'_>) -> PyResult<()> { fn remove_graph(&self, graph_name: &PyAny, py: Python<'_>) -> PyResult<()> {
let graph_name = GraphName::from(&PyGraphNameRef::try_from(graph_name)?); let graph_name = GraphName::from(&PyGraphNameRef::try_from(graph_name)?);
py.allow_threads(|| { py.allow_threads(|| {
@ -604,7 +587,6 @@ impl PyStore {
/// [] /// []
/// >>> list(store.named_graphs()) /// >>> list(store.named_graphs())
/// [] /// []
#[pyo3(text_signature = "($self)")]
fn clear(&self, py: Python<'_>) -> PyResult<()> { fn clear(&self, py: Python<'_>) -> PyResult<()> {
py.allow_threads(|| self.inner.clear().map_err(map_storage_error)) py.allow_threads(|| self.inner.clear().map_err(map_storage_error))
} }
@ -615,7 +597,6 @@ impl PyStore {
/// ///
/// :rtype: None /// :rtype: None
/// :raises IOError: if an I/O error happens during the flush. /// :raises IOError: if an I/O error happens during the flush.
#[pyo3(text_signature = "($self)")]
fn flush(&self, py: Python<'_>) -> PyResult<()> { fn flush(&self, py: Python<'_>) -> PyResult<()> {
py.allow_threads(|| self.inner.flush().map_err(map_storage_error)) py.allow_threads(|| self.inner.flush().map_err(map_storage_error))
} }
@ -626,7 +607,6 @@ impl PyStore {
/// ///
/// :rtype: None /// :rtype: None
/// :raises IOError: if an I/O error happens during the optimization. /// :raises IOError: if an I/O error happens during the optimization.
#[pyo3(text_signature = "($self)")]
fn optimize(&self, py: Python<'_>) -> PyResult<()> { fn optimize(&self, py: Python<'_>) -> PyResult<()> {
py.allow_threads(|| self.inner.optimize().map_err(map_storage_error)) py.allow_threads(|| self.inner.optimize().map_err(map_storage_error))
} }
@ -652,7 +632,6 @@ impl PyStore {
/// :type target_directory: str /// :type target_directory: str
/// :rtype: None /// :rtype: None
/// :raises IOError: if an I/O error happens during the backup. /// :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<()> { fn backup(&self, target_directory: &str, py: Python<'_>) -> PyResult<()> {
py.allow_threads(|| { py.allow_threads(|| {
self.inner self.inner

Loading…
Cancel
Save