Skip to content

Commit 454fbd3

Browse files
working on python support
1 parent ca2ed0d commit 454fbd3

File tree

5 files changed

+79
-1
lines changed

5 files changed

+79
-1
lines changed

Cargo.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# See Notices.txt for copyright information
33
[package]
44
name = "algebraics"
5-
version = "0.1.0"
5+
version = "0.1.1"
66
authors = ["Jacob Lifshay <[email protected]>"]
77
edition = "2018"
88
license = "LGPL-2.1-or-later"
@@ -11,6 +11,14 @@ keywords = ["algebraic-numbers", "arbitrary-precision", "polynomials", "real-num
1111
repository = "https://salsa.debian.org/Kazan-team/algebraics"
1212
readme = "README.md"
1313

14+
[features]
15+
default = []
16+
python-extension = ["pyo3", "pyo3/extension-module"]
17+
18+
[lib]
19+
name = "algebraics"
20+
crate-type = ["rlib", "cdylib"]
21+
1422
[dependencies]
1523
num-traits = "0.2"
1624
num-bigint = "0.2"
@@ -19,3 +27,4 @@ num-rational = "0.2"
1927
rand = "0.5"
2028
rand_pcg = "0.1.1"
2129
lazy_static = "1.4"
30+
pyo3 = { version = "0.8.0", optional = true }

pyproject.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# SPDX-License-Identifier: LGPL-2.1-or-later
2+
# See Notices.txt for copyright information
3+
[build-system]
4+
requires = ["maturin"]
5+
build-backend = "maturin"
6+
7+
[tool.maturin]
8+
bindings = "pyo3"
9+
cargo-extra-args = "--features python-extension"

rls.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
features = ["python-extension"]

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub(crate) mod lattice;
1111
pub mod mod_int;
1212
pub mod polynomial;
1313
pub mod prelude;
14+
pub mod python;
1415
pub(crate) mod quadratic_numbers;
1516
pub mod traits;
1617
pub mod util;

src/python.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// SPDX-License-Identifier: LGPL-2.1-or-later
2+
// See Notices.txt for copyright information
3+
4+
#![cfg(feature = "python-extension")]
5+
6+
use crate::algebraic_numbers::RealAlgebraicNumber;
7+
use num_bigint::BigInt;
8+
use num_traits::Zero;
9+
use pyo3::prelude::*;
10+
use pyo3::types::PyAny;
11+
use pyo3::types::PyInt;
12+
13+
// TODO: Switch to using BigInt's python conversions once they are implemented
14+
// see https://github.com/PyO3/pyo3/issues/543
15+
#[derive(Clone, Debug)]
16+
pub struct PyBigInt(pub BigInt);
17+
18+
impl ToPyObject for PyBigInt {
19+
fn to_object(&self, py: Python) -> PyObject {
20+
// FIXME: implement
21+
unimplemented!()
22+
}
23+
}
24+
25+
impl FromPyObject<'_> for PyBigInt {
26+
fn extract(ob: &PyAny) -> PyResult<Self> {
27+
// FIXME: implement
28+
unimplemented!()
29+
}
30+
}
31+
32+
#[pyclass(name=RealAlgebraicNumber, module="algebraics")]
33+
struct RealAlgebraicNumberPy {
34+
value: RealAlgebraicNumber,
35+
}
36+
37+
#[pymethods]
38+
impl RealAlgebraicNumberPy {
39+
#[new]
40+
fn new(obj: &PyRawObject, value: Option<&PyInt>) {
41+
match value {
42+
None => obj.init(RealAlgebraicNumberPy {
43+
value: RealAlgebraicNumber::zero(),
44+
}),
45+
Some(value) => {
46+
// FIXME: implement
47+
unimplemented!();
48+
}
49+
}
50+
}
51+
// FIXME: implement rest of methods
52+
}
53+
54+
#[pymodule]
55+
fn algebraics(py: Python, m: &PyModule) -> PyResult<()> {
56+
// FIXME: add module members
57+
Ok(())
58+
}

0 commit comments

Comments
 (0)