-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d111277
commit 057de1e
Showing
15 changed files
with
443 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "shaperglot-py" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
[lib] | ||
name = "shaperglot" | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
shaperglot = { path = "../shaperglot-lib" } | ||
pyo3 = "0.22" | ||
pythonize = "0.22.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[build-system] | ||
requires = ["maturin>=1.3,<2.0"] | ||
build-backend = "maturin" | ||
|
||
[project] | ||
name = "shaperglot" | ||
requires-python = ">=3.8" | ||
classifiers = [ | ||
"Programming Language :: Rust", | ||
"Programming Language :: Python :: Implementation :: CPython", | ||
"Programming Language :: Python :: Implementation :: PyPy", | ||
] | ||
dynamic = ["version"] | ||
[tool.maturin] | ||
features = ["pyo3/extension-module"] | ||
module-name = "shaperglot._shaperglot" | ||
python-source = "python" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use ::shaperglot::Check as RustCheck; | ||
use pyo3::prelude::*; | ||
use shaperglot::checks::CheckImplementation; | ||
|
||
#[pyclass(module = "shaperglot")] | ||
pub(crate) struct Check(pub(crate) RustCheck); | ||
|
||
#[pymethods] | ||
impl Check { | ||
#[getter] | ||
fn description(&self) -> String { | ||
self.0.description.to_string() | ||
} | ||
|
||
#[getter] | ||
fn implementations(&self) -> Vec<String> { | ||
self.0 | ||
.implementations | ||
.iter() | ||
.map(|s| s.describe()) | ||
.collect() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use crate::{language::Language, reporter::Reporter}; | ||
use ::shaperglot::Checker as RustChecker; | ||
use pyo3::{exceptions::PyValueError, prelude::*}; | ||
|
||
use std::sync::Arc; | ||
|
||
#[pyclass(module = "shaperglot")] | ||
pub(crate) struct Checker(Vec<u8>); | ||
|
||
impl Checker { | ||
pub(crate) fn _checker(&self) -> Result<Arc<RustChecker>, PyErr> { | ||
Ok(Arc::new(RustChecker::new(&self.0).map_err(|e| { | ||
PyErr::new::<PyValueError, _>(e.to_string()) | ||
})?)) | ||
} | ||
} | ||
|
||
#[pymethods] | ||
impl Checker { | ||
#[new] | ||
pub(crate) fn new(filename: &str) -> Result<Self, PyErr> { | ||
let font_binary = std::fs::read(filename)?; | ||
Ok(Self(font_binary)) | ||
} | ||
|
||
pub(crate) fn check(&self, lang: &Language) -> PyResult<Reporter> { | ||
Ok(self._checker()?.check(&lang.0).into()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use ::shaperglot::{CheckResult as RustCheckResult, Problem as RustProblem, ResultCode}; | ||
use pyo3::prelude::*; | ||
use pythonize::pythonize; | ||
|
||
#[pyclass(module = "shaperglot")] | ||
pub(crate) struct CheckResult(pub(crate) RustCheckResult); | ||
|
||
#[pymethods] | ||
impl CheckResult { | ||
#[getter] | ||
pub(crate) fn message(&self) -> String { | ||
self.0.to_string() | ||
} | ||
|
||
pub(crate) fn __str__(&self) -> String { | ||
self.0.to_string() | ||
} | ||
|
||
#[getter] | ||
pub(crate) fn is_success(&self) -> bool { | ||
self.0.status == ResultCode::Pass | ||
} | ||
|
||
#[getter] | ||
pub(crate) fn status_code(&self) -> String { | ||
self.0.status.to_string() | ||
} | ||
|
||
#[getter] | ||
pub(crate) fn problems(&self) -> Vec<Problem> { | ||
self.0.problems.iter().map(|p| Problem(p.clone())).collect() | ||
} | ||
} | ||
|
||
#[pyclass(module = "shaperglot")] | ||
pub(crate) struct Problem(pub(crate) RustProblem); | ||
#[pymethods] | ||
impl Problem { | ||
#[getter] | ||
fn check_name(&self) -> String { | ||
self.0.check_name.to_string() | ||
} | ||
|
||
#[getter] | ||
fn message(&self) -> String { | ||
self.0.message.to_string() | ||
} | ||
|
||
#[getter] | ||
fn code(&self) -> String { | ||
self.0.code.to_string() | ||
} | ||
|
||
#[getter] | ||
fn terminal(&self) -> bool { | ||
self.0.terminal | ||
} | ||
|
||
#[getter] | ||
fn context<'py>(&self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr> { | ||
pythonize(py, &self.0.context) | ||
.map_err(|e| PyErr::new::<pyo3::exceptions::PyTypeError, _>(e.to_string())) | ||
} | ||
} |
Oops, something went wrong.