Upgrades pyo3 to 0.13

Drops python 3.5 support
pull/71/head
Tpt 4 years ago
parent d9fadca612
commit 40a08ac623
  1. 2
      python/Cargo.toml
  2. 4
      python/src/io.rs
  3. 4
      python/src/memory_store.rs
  4. 50
      python/src/model.rs
  5. 4
      python/src/sled_store.rs
  6. 10
      python/src/sparql.rs

@ -16,7 +16,7 @@ doctest = false
[dependencies] [dependencies]
oxigraph = {version = "0.1.1", path="../lib", features = ["sled", "http_client"]} oxigraph = {version = "0.1.1", path="../lib", features = ["sled", "http_client"]}
pyo3 = {version = "0.12", features = ["extension-module"]} pyo3 = {version = "0.13", features = ["extension-module"]}
[package.metadata.maturin] [package.metadata.maturin]
classifier = [ classifier = [

@ -145,7 +145,7 @@ pub fn serialize(input: &PyAny, output: &PyAny, mime_type: &str, py: Python<'_>)
} }
} }
#[pyclass(name = TripleReader)] #[pyclass(name = "TripleReader", module = "oxigraph")]
pub struct PyTripleReader { pub struct PyTripleReader {
inner: TripleReader<BufReader<PyFileLike>>, inner: TripleReader<BufReader<PyFileLike>>,
} }
@ -164,7 +164,7 @@ impl PyIterProtocol for PyTripleReader {
} }
} }
#[pyclass(name = QuadReader)] #[pyclass(name = "QuadReader", module = "oxigraph")]
pub struct PyQuadReader { pub struct PyQuadReader {
inner: QuadReader<BufReader<PyFileLike>>, inner: QuadReader<BufReader<PyFileLike>>,
} }

@ -24,7 +24,7 @@ use std::io::BufReader;
/// >>> 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')))
/// >>> str(store) /// >>> str(store)
/// '<http://example.com> <http://example.com/p> "1" <http://example.com/g> .\n' /// '<http://example.com> <http://example.com/p> "1" <http://example.com/g> .\n'
#[pyclass(name = MemoryStore)] #[pyclass(name = "MemoryStore", module = "oxigraph")]
#[derive(Eq, PartialEq, Clone)] #[derive(Eq, PartialEq, Clone)]
#[text_signature = "()"] #[text_signature = "()"]
pub struct PyMemoryStore { pub struct PyMemoryStore {
@ -385,7 +385,7 @@ impl PyIterProtocol for PyMemoryStore {
} }
} }
#[pyclass(unsendable)] #[pyclass(unsendable, module = "oxigraph")]
pub struct QuadIter { pub struct QuadIter {
inner: MemoryQuadIter, inner: MemoryQuadIter,
} }

@ -20,7 +20,7 @@ use std::vec::IntoIter;
/// ///
/// >>> str(NamedNode('http://example.com')) /// >>> str(NamedNode('http://example.com'))
/// '<http://example.com>' /// '<http://example.com>'
#[pyclass(name = NamedNode)] #[pyclass(name = "NamedNode", module = "oxigraph")]
#[text_signature = "(value)"] #[text_signature = "(value)"]
#[derive(Eq, PartialEq, Ord, PartialOrd, Debug, Clone, Hash)] #[derive(Eq, PartialEq, Ord, PartialOrd, Debug, Clone, Hash)]
pub struct PyNamedNode { pub struct PyNamedNode {
@ -96,9 +96,9 @@ impl PyObjectProtocol for PyNamedNode {
fn __richcmp__(&self, other: &PyAny, op: CompareOp) -> PyResult<bool> { fn __richcmp__(&self, other: &PyAny, op: CompareOp) -> PyResult<bool> {
if let Ok(other) = other.downcast::<PyCell<PyNamedNode>>() { if let Ok(other) = other.downcast::<PyCell<PyNamedNode>>() {
Ok(eq_ord_compare(self, &other.borrow(), op)) Ok(eq_ord_compare(self, &other.borrow(), op))
} else if PyBlankNode::is_instance(other) } else if PyBlankNode::is_type_of(other)
|| PyLiteral::is_instance(other) || PyLiteral::is_type_of(other)
|| PyDefaultGraph::is_instance(other) || PyDefaultGraph::is_type_of(other)
{ {
eq_compare_other_type(op) eq_compare_other_type(op)
} else { } else {
@ -119,7 +119,7 @@ impl PyObjectProtocol for PyNamedNode {
/// ///
/// >>> str(BlankNode('ex')) /// >>> str(BlankNode('ex'))
/// '_:ex' /// '_:ex'
#[pyclass(name = BlankNode)] #[pyclass(name = "BlankNode", module = "oxigraph")]
#[text_signature = "(value)"] #[text_signature = "(value)"]
#[derive(Eq, PartialEq, Debug, Clone, Hash)] #[derive(Eq, PartialEq, Debug, Clone, Hash)]
pub struct PyBlankNode { pub struct PyBlankNode {
@ -198,9 +198,9 @@ impl PyObjectProtocol for PyBlankNode {
fn __richcmp__(&self, other: &PyAny, op: CompareOp) -> PyResult<bool> { fn __richcmp__(&self, other: &PyAny, op: CompareOp) -> PyResult<bool> {
if let Ok(other) = other.downcast::<PyCell<PyBlankNode>>() { if let Ok(other) = other.downcast::<PyCell<PyBlankNode>>() {
eq_compare(self, &other.borrow(), op) eq_compare(self, &other.borrow(), op)
} else if PyNamedNode::is_instance(other) } else if PyNamedNode::is_type_of(other)
|| PyLiteral::is_instance(other) || PyLiteral::is_type_of(other)
|| PyDefaultGraph::is_instance(other) || PyDefaultGraph::is_type_of(other)
{ {
eq_compare_other_type(op) eq_compare_other_type(op)
} else { } else {
@ -229,7 +229,7 @@ impl PyObjectProtocol for PyBlankNode {
/// '"example"@en' /// '"example"@en'
/// >>> str(Literal('11', datatype=NamedNode('http://www.w3.org/2001/XMLSchema#integer'))) /// >>> str(Literal('11', datatype=NamedNode('http://www.w3.org/2001/XMLSchema#integer')))
/// '"11"^^<http://www.w3.org/2001/XMLSchema#integer>' /// '"11"^^<http://www.w3.org/2001/XMLSchema#integer>'
#[pyclass(name = Literal)] #[pyclass(name = "Literal", module = "oxigraph")]
#[text_signature = "(value, *, datatype = None, language = None)"] #[text_signature = "(value, *, datatype = None, language = None)"]
#[derive(Eq, PartialEq, Debug, Clone, Hash)] #[derive(Eq, PartialEq, Debug, Clone, Hash)]
pub struct PyLiteral { pub struct PyLiteral {
@ -337,9 +337,9 @@ impl PyObjectProtocol for PyLiteral {
fn __richcmp__(&self, other: &PyAny, op: CompareOp) -> PyResult<bool> { fn __richcmp__(&self, other: &PyAny, op: CompareOp) -> PyResult<bool> {
if let Ok(other) = other.downcast::<PyCell<PyLiteral>>() { if let Ok(other) = other.downcast::<PyCell<PyLiteral>>() {
eq_compare(self, &other.borrow(), op) eq_compare(self, &other.borrow(), op)
} else if PyNamedNode::is_instance(other) } else if PyNamedNode::is_type_of(other)
|| PyBlankNode::is_instance(other) || PyBlankNode::is_type_of(other)
|| PyDefaultGraph::is_instance(other) || PyDefaultGraph::is_type_of(other)
{ {
eq_compare_other_type(op) eq_compare_other_type(op)
} else { } else {
@ -351,7 +351,7 @@ impl PyObjectProtocol for PyLiteral {
} }
/// The RDF `default graph name <https://www.w3.org/TR/rdf11-concepts/#dfn-default-graph>`_ /// The RDF `default graph name <https://www.w3.org/TR/rdf11-concepts/#dfn-default-graph>`_
#[pyclass(name = DefaultGraph)] #[pyclass(name = "DefaultGraph", module = "oxigraph")]
#[derive(Eq, PartialEq, Debug, Clone, Copy, Hash)] #[derive(Eq, PartialEq, Debug, Clone, Copy, Hash)]
pub struct PyDefaultGraph {} pub struct PyDefaultGraph {}
@ -391,9 +391,9 @@ impl PyObjectProtocol for PyDefaultGraph {
fn __richcmp__(&self, other: &PyAny, op: CompareOp) -> PyResult<bool> { fn __richcmp__(&self, other: &PyAny, op: CompareOp) -> PyResult<bool> {
if let Ok(other) = other.downcast::<PyCell<PyDefaultGraph>>() { if let Ok(other) = other.downcast::<PyCell<PyDefaultGraph>>() {
eq_compare(self, &other.borrow(), op) eq_compare(self, &other.borrow(), op)
} else if PyNamedNode::is_instance(other) } else if PyNamedNode::is_type_of(other)
|| PyBlankNode::is_instance(other) || PyBlankNode::is_type_of(other)
|| PyLiteral::is_instance(other) || PyLiteral::is_type_of(other)
{ {
eq_compare_other_type(op) eq_compare_other_type(op)
} else { } else {
@ -453,7 +453,7 @@ impl From<PyTerm> for Term {
/// A triple could also be easily destructed into its components: /// A triple could also be easily destructed into its components:
/// ///
/// >>> (s, p, o) = Triple(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1')) /// >>> (s, p, o) = Triple(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'))
#[pyclass(name = Triple)] #[pyclass(name = "Triple", module = "oxigraph")]
#[derive(Eq, PartialEq, Debug, Clone, Hash)] #[derive(Eq, PartialEq, Debug, Clone, Hash)]
#[text_signature = "(subject, predicate, object)"] #[text_signature = "(subject, predicate, object)"]
pub struct PyTriple { pub struct PyTriple {
@ -616,7 +616,7 @@ impl From<PyGraphName> for GraphName {
/// A quad could also be easily destructed into its components: /// A quad could also be easily destructed into its components:
/// ///
/// >>> (s, p, o, g) = Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g')) /// >>> (s, p, o, g) = Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'), NamedNode('http://example.com/g'))
#[pyclass(name = Quad)] #[pyclass(name = "Quad", module = "oxigraph")]
#[text_signature = "(subject, predicate, object, graph_name = None)"] #[text_signature = "(subject, predicate, object, graph_name = None)"]
#[derive(Eq, PartialEq, Debug, Clone, Hash)] #[derive(Eq, PartialEq, Debug, Clone, Hash)]
pub struct PyQuad { pub struct PyQuad {
@ -792,7 +792,7 @@ impl PyIterProtocol for PyQuad {
/// ///
/// >>> str(Variable('foo')) /// >>> str(Variable('foo'))
/// '?foo' /// '?foo'
#[pyclass(name = Variable)] #[pyclass(name = "Variable", module = "oxigraph")]
#[text_signature = "(value)"] #[text_signature = "(value)"]
#[derive(Eq, PartialEq, Debug, Clone, Hash)] #[derive(Eq, PartialEq, Debug, Clone, Hash)]
pub struct PyVariable { pub struct PyVariable {
@ -873,7 +873,7 @@ impl<'a> TryFrom<&'a PyAny> for PyNamedNodeRef<'a> {
} else { } else {
Err(PyTypeError::new_err(format!( Err(PyTypeError::new_err(format!(
"{} is not an RDF named node", "{} is not an RDF named node",
value.get_type().name(), value.get_type().name()?,
))) )))
} }
} }
@ -904,7 +904,7 @@ impl<'a> TryFrom<&'a PyAny> for PyNamedOrBlankNodeRef<'a> {
} else { } else {
Err(PyTypeError::new_err(format!( Err(PyTypeError::new_err(format!(
"{} is not an RDF named or blank node", "{} is not an RDF named or blank node",
value.get_type().name(), value.get_type().name()?,
))) )))
} }
} }
@ -952,7 +952,7 @@ impl<'a> TryFrom<&'a PyAny> for PyTermRef<'a> {
} else { } else {
Err(PyTypeError::new_err(format!( Err(PyTypeError::new_err(format!(
"{} is not an RDF term", "{} is not an RDF term",
value.get_type().name(), value.get_type().name()?,
))) )))
} }
} }
@ -1001,7 +1001,7 @@ impl<'a> TryFrom<&'a PyAny> for PyGraphNameRef<'a> {
} else { } else {
Err(PyTypeError::new_err(format!( Err(PyTypeError::new_err(format!(
"{} is not an RDF graph name", "{} is not an RDF graph name",
value.get_type().name(), value.get_type().name()?,
))) )))
} }
} }
@ -1093,7 +1093,7 @@ fn graph_name_repr(term: GraphNameRef<'_>, buffer: &mut String) {
} }
} }
#[pyclass] #[pyclass(module = "oxigraph")]
pub struct TripleComponentsIter { pub struct TripleComponentsIter {
inner: IntoIter<Term>, inner: IntoIter<Term>,
} }
@ -1109,7 +1109,7 @@ impl PyIterProtocol for TripleComponentsIter {
} }
} }
#[pyclass] #[pyclass(module = "oxigraph")]
pub struct QuadComponentsIter { pub struct QuadComponentsIter {
inner: IntoIter<Option<Term>>, inner: IntoIter<Option<Term>>,
} }

@ -29,7 +29,7 @@ use std::io::BufReader;
/// >>> 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')))
/// >>> str(store) /// >>> str(store)
/// '<http://example.com> <http://example.com/p> "1" <http://example.com/g> .\n' /// '<http://example.com> <http://example.com/p> "1" <http://example.com/g> .\n'
#[pyclass(name = SledStore)] #[pyclass(name = "SledStore", module = "oxigraph")]
#[text_signature = "(path = None)"] #[text_signature = "(path = None)"]
#[derive(Clone)] #[derive(Clone)]
pub struct PySledStore { pub struct PySledStore {
@ -391,7 +391,7 @@ impl PyIterProtocol for PySledStore {
} }
} }
#[pyclass] #[pyclass(module = "oxigraph")]
pub struct QuadIter { pub struct QuadIter {
inner: SledQuadIter, inner: SledQuadIter,
} }

@ -85,7 +85,7 @@ pub fn query_results_to_python(py: Python<'_>, results: QueryResults) -> PyResul
/// >>> s, p, o = solution /// >>> s, p, o = solution
/// >>> s /// >>> s
/// <NamedNode value=http://example.com> /// <NamedNode value=http://example.com>
#[pyclass(unsendable, name = QuerySolution)] #[pyclass(unsendable, name = "QuerySolution", module = "oxigraph")]
pub struct PyQuerySolution { pub struct PyQuerySolution {
inner: QuerySolution, inner: QuerySolution,
} }
@ -132,7 +132,7 @@ impl PyMappingProtocol for PyQuerySolution {
} else { } else {
Err(PyTypeError::new_err(format!( Err(PyTypeError::new_err(format!(
"{} is not an integer of a string", "{} is not an integer of a string",
input.get_type().name(), input.get_type().name()?,
))) )))
} }
} }
@ -152,7 +152,7 @@ impl PyIterProtocol for PyQuerySolution {
} }
} }
#[pyclass] #[pyclass(module = "oxigraph")]
pub struct SolutionValueIter { pub struct SolutionValueIter {
inner: IntoIter<Option<Term>>, inner: IntoIter<Option<Term>>,
} }
@ -176,7 +176,7 @@ impl PyIterProtocol for SolutionValueIter {
/// >>> store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'))) /// >>> store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1')))
/// >>> list(store.query('SELECT ?s WHERE { ?s ?p ?o }')) /// >>> list(store.query('SELECT ?s WHERE { ?s ?p ?o }'))
/// [<QuerySolution s=<NamedNode value=http://example.com>>] /// [<QuerySolution s=<NamedNode value=http://example.com>>]
#[pyclass(unsendable, name = QuerySolutions)] #[pyclass(unsendable, name = "QuerySolutions", module = "oxigraph")]
pub struct PyQuerySolutions { pub struct PyQuerySolutions {
inner: QuerySolutionIter, inner: QuerySolutionIter,
} }
@ -221,7 +221,7 @@ impl PyIterProtocol for PyQuerySolutions {
/// >>> store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'))) /// >>> store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1')))
/// >>> list(store.query('CONSTRUCT WHERE { ?s ?p ?o }')) /// >>> list(store.query('CONSTRUCT WHERE { ?s ?p ?o }'))
/// [<Triple 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>>>] /// [<Triple 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>>>]
#[pyclass(unsendable, name = QueryTriples)] #[pyclass(unsendable, name = "QueryTriples", module = "oxigraph")]
pub struct PyQueryTriples { pub struct PyQueryTriples {
inner: QueryTripleIter, inner: QueryTripleIter,
} }

Loading…
Cancel
Save