diff --git a/Cargo.toml b/Cargo.toml index 001066c8..fdc4b869 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,5 @@ [workspace] members = [ "lib", - "python", "server" ] \ No newline at end of file diff --git a/python/Cargo.toml b/python/Cargo.toml deleted file mode 100644 index f4a93438..00000000 --- a/python/Cargo.toml +++ /dev/null @@ -1,20 +0,0 @@ -[package] -name = "rudf_python" -version = "0.1.0" -authors = ["Tpt "] -license = "MIT/Apache-2.0" -readme = "../README.md" -keywords = ["RDF", "N-Triples", "Turtle", "RDF/XML", "SPARQL", "Python"] -repository = "https://github.com/Tpt/rudf" -description = """ -Python bindings of the Rudf library -""" -edition = "2018" - -[lib] -name = "rudf" -crate-type = ["cdylib"] - -[dependencies] -rudf = {path = "../lib"} -cpython = { version = "0.2", features = ["extension-module"]} diff --git a/python/MANIFEST.in b/python/MANIFEST.in deleted file mode 100644 index 83c99e08..00000000 --- a/python/MANIFEST.in +++ /dev/null @@ -1,2 +0,0 @@ -include Cargo.toml -recursive-include src * \ No newline at end of file diff --git a/python/pyproject.toml b/python/pyproject.toml deleted file mode 100644 index 2d3b7557..00000000 --- a/python/pyproject.toml +++ /dev/null @@ -1,2 +0,0 @@ -[build-system] -requires = ["setuptools", "wheel", "setuptools-rust"] \ No newline at end of file diff --git a/python/rudf/__init__.py b/python/rudf/__init__.py deleted file mode 100644 index 056af597..00000000 --- a/python/rudf/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .rudf import * \ No newline at end of file diff --git a/python/setup.py b/python/setup.py deleted file mode 100644 index 8811d49b..00000000 --- a/python/setup.py +++ /dev/null @@ -1,15 +0,0 @@ -from setuptools import setup - -try: - from setuptools_rust import Binding, RustExtension -except ImportError: - print('You should install the setuptool-rust package to be able to build rudf') - - -setup( - name="rudf", - version="0.1", - rust_extensions=[RustExtension("rudf.rudf", binding=Binding.RustCPython)], - packages=["rudf"], - zip_safe=False, -) \ No newline at end of file diff --git a/python/src/lib.rs b/python/src/lib.rs deleted file mode 100644 index e0ebcfac..00000000 --- a/python/src/lib.rs +++ /dev/null @@ -1,124 +0,0 @@ -#![allow(clippy::zero_ptr, clippy::transmute_ptr_to_ptr)] - -use cpython::exc::ValueError; -use cpython::*; -use rudf::model; -use rudf::Error; -use std::collections::hash_map::DefaultHasher; -use std::hash::Hash; -use std::hash::Hasher; -use std::str::FromStr; - -py_module_initializer!(rudf, initrudf, PyInit_rudf, |py, m| { - r#try!(m.add(py, "__doc__", "Rudf Python bindings")); - r#try!(m.add_class::(py)); - r#try!(m.add_class::(py)); - r#try!(m.add_class::(py)); - Ok(()) -}); - -fn new_value_error(py: Python<'_>, error: &Error) -> PyErr { - PyErr::new::(py, error.to_string()) -} - -fn eq_compare(a: &T, b: &T, op: &CompareOp) -> bool { - match op { - CompareOp::Lt => a < b, - CompareOp::Le => a <= b, - CompareOp::Eq => a == b, - CompareOp::Ne => a != b, - CompareOp::Gt => a > b, - CompareOp::Ge => a >= b, - } -} - -fn hash(t: &impl Hash) -> u64 { - let mut s = DefaultHasher::new(); - t.hash(&mut s); - s.finish() -} - -py_class!(class NamedNode |py| { - data inner: model::NamedNode; - - def __new__(_cls, value: &str) -> PyResult { - NamedNode::create_instance(py, model::NamedNode::from_str(value).map_err(|error| new_value_error(py, &error))?) - } - - def value(&self) -> PyResult { - Ok(self.inner(py).as_str().to_string()) - } - - def __str__(&self) -> PyResult { - Ok(self.inner(py).to_string()) - } - - def __richcmp__(&self, other: &NamedNode, op: CompareOp) -> PyResult { - Ok(eq_compare(&self.inner(py), &other.inner(py), &op)) - } - - def __hash__(&self) -> PyResult { - Ok(hash(self.inner(py))) - } -}); - -py_class!(class BlankNode |py| { - data inner: model::BlankNode; - - def __new__(_cls) -> PyResult { - BlankNode::create_instance(py, model::BlankNode::default()) - } - - def __str__(&self) -> PyResult { - Ok(self.inner(py).to_string()) - } - - def __richcmp__(&self, other: &BlankNode, op: CompareOp) -> PyResult { - Ok(eq_compare(&self.inner(py), &other.inner(py), &op)) - } - - def __hash__(&self) -> PyResult { - Ok(hash(self.inner(py))) - } -}); - -py_class!(class Literal |py| { - data inner: model::Literal; - - def __new__(_cls, value: String, language: Option = None, datatype: Option = None) -> PyResult { - Literal::create_instance(py, match language { - Some(language) => { - let language = model::LanguageTag::parse(&language).map_err(|error| new_value_error(py, &error.into()))?; - model::Literal::new_language_tagged_literal(value, language) - }, - None => match datatype { - Some(datatype) => model::Literal::new_typed_literal(value, datatype.inner(py).clone()), - None => model::Literal::new_simple_literal(value) - } - }) - } - - def value(&self) -> PyResult { - Ok(self.inner(py).value().to_string()) - } - - def language(&self) -> PyResult> { - Ok(self.inner(py).language().map(|l| l.as_str().to_string())) - } - - def datatype(&self) -> PyResult { - NamedNode::create_instance(py, self.inner(py).datatype().clone()) - } - - def __str__(&self) -> PyResult { - Ok(self.inner(py).to_string()) - } - - def __richcmp__(&self, other: &Literal, op: CompareOp) -> PyResult { - Ok(eq_compare(&self.inner(py), &other.inner(py), &op)) - } - - def __hash__(&self) -> PyResult { - Ok(hash(self.inner(py))) - } -}); diff --git a/python/tests/test_model.py b/python/tests/test_model.py deleted file mode 100644 index 3172dea0..00000000 --- a/python/tests/test_model.py +++ /dev/null @@ -1,33 +0,0 @@ -import unittest -from rudf import * - -XSD_STRING = NamedNode('http://www.w3.org/2001/XMLSchema#string') -XSD_INTEGER = NamedNode('http://www.w3.org/2001/XMLSchema#integer') -RDF_LANG_STRING = NamedNode('http://www.w3.org/1999/02/22-rdf-syntax-ns#langString') - - -class TestNamedNode(unittest.TestCase): - def test_constructor(self): - self.assertEqual(NamedNode('http://foo').value(), 'http://foo/') - - -class TestBlankNode(unittest.TestCase): - def test_constructor(self): - self.assertNotEqual(BlankNode(), BlankNode()) - - -class TestLiteral(unittest.TestCase): - def test_constructor(self): - self.assertEqual(Literal('foo').value(), 'foo') - self.assertEqual(Literal('foo').datatype(), XSD_STRING) - - self.assertEqual(Literal('foo', 'en').value(), 'foo') - self.assertEqual(Literal('foo', 'en').language(), 'en') - self.assertEqual(Literal('foo', 'en').datatype(), RDF_LANG_STRING) - - self.assertEqual(Literal('foo', datatype=XSD_INTEGER).value(), 'foo') - self.assertEqual(Literal('foo', datatype=XSD_INTEGER).datatype(), XSD_INTEGER) - - -if __name__ == '__main__': - unittest.main()