Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Unreleased
# v0.22.0

* When strip=True in code/text, then text steps line are rstripped
* "typst" extension for writing mathematical expressions
* Migrate to parle 0.7
* Migrate to parley 0.7

# v0.21.2

Expand Down
58 changes: 22 additions & 36 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions nelsie/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "nelsie"
version = "0.20.2"
edition = "2021"
version = "0.22.0"
edition = "2024"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
Expand All @@ -15,9 +15,9 @@ thiserror = { workspace = true }
xmltree = { workspace = true }
smallvec = { workspace = true }

pyo3 = { version = "0.26", features = ["abi3-py311", "extension-module"] }
pyo3 = { version = "0.27", features = ["abi3-py311", "extension-module"] }
itertools = "0.14"
strict-num = "*"
imagesize = { version = "0.14", default-features = false, features = ["jpeg", "png"] }
zip = { version = "4.6", default-features = false, features = ["deflate"] }
zip = { version = "7.2", default-features = false, features = ["deflate"] }
notify = "8"
13 changes: 8 additions & 5 deletions nelsie/src/common/steps.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use pyo3::exceptions::PyException;
use pyo3::types::{PyAnyMethods, PyTuple};
use pyo3::{Bound, FromPyObject, IntoPyObject, IntoPyObjectExt, PyAny, PyErr, PyResult, Python};
use smallvec::{smallvec, SmallVec};
use pyo3::types::PyTuple;
use pyo3::{
Borrowed, Bound, FromPyObject, IntoPyObject, IntoPyObjectExt, PyAny, PyErr, PyResult, Python,
};
use smallvec::{SmallVec, smallvec};
use std::cmp::Ordering;
use std::fmt::{Debug, Display, Formatter};

Expand Down Expand Up @@ -94,8 +96,9 @@ impl<'py> IntoPyObject<'py> for &Step {
}
}

impl<'py> FromPyObject<'py> for Step {
fn extract_bound(ob: &Bound<'py, PyAny>) -> PyResult<Self> {
impl<'py> FromPyObject<'_, 'py> for Step {
type Error = PyErr;
fn extract(ob: Borrowed<'_, 'py, PyAny>) -> PyResult<Self> {
if let Ok(v) = ob.extract::<u32>() {
return Ok(Step::from_int(v));
}
Expand Down
10 changes: 5 additions & 5 deletions nelsie/src/pyinterface/check.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use pyo3::exceptions::PyException;
use pyo3::types::PyAnyMethods;
use pyo3::{pyfunction, Bound, PyAny, PyResult};
use pyo3::{Bound, PyAny, PyResult, pyfunction};
use std::str::FromStr;

/// Formats the sum of two numbers as string.
#[pyfunction]
pub(crate) fn check_color<'py>(obj: &Bound<'py, PyAny>) -> PyResult<()> {
if let Ok(s) = obj.extract::<&str>() {
if renderer::Color::from_str(s).is_ok() {
return Ok(());
}
if let Ok(s) = obj.extract::<&str>()
&& renderer::Color::from_str(s).is_ok()
{
return Ok(());
}
Err(PyException::new_err(format!("Invalid color: '{}'", obj)))
}
8 changes: 4 additions & 4 deletions nelsie/src/pyinterface/common.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use pyo3::types::PyAnyMethods;
use pyo3::{Bound, FromPyObject, PyAny, PyResult};
use pyo3::{Borrowed, FromPyObject, PyAny, PyErr, PyResult};
use renderer::Color;
use std::str::FromStr;

pub(crate) struct PyColor(Color);

impl<'py> FromPyObject<'py> for PyColor {
fn extract_bound(obj: &Bound<'py, PyAny>) -> PyResult<Self> {
impl<'py> FromPyObject<'_, 'py> for PyColor {
type Error = PyErr;
fn extract(obj: Borrowed<'_, 'py, PyAny>) -> PyResult<Self> {
let s: &str = obj.extract()?;
Ok(PyColor(Color::from_str(s).map_err(crate::Error::from)?))
}
Expand Down
47 changes: 26 additions & 21 deletions nelsie/src/pyinterface/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::pyinterface::text::PyTextContent;
use pyo3::exceptions::PyValueError;
use pyo3::prelude::PyAnyMethods;
use pyo3::types::PyList;
use pyo3::{intern, Bound, FromPyObject, PyAny, PyResult};
use pyo3::{Borrowed, Bound, FromPyObject, PyAny, PyErr, PyResult, intern};
use renderer::taffy::style_helpers::{
FromFlex, FromLength, FromPercent, TaffyGridLine, TaffyGridSpan,
};
Expand All @@ -29,8 +29,9 @@ struct PyPage<'py> {

struct PyLengthOrExpr(LengthOrExpr);

impl<'py> FromPyObject<'py> for PyLengthOrExpr {
fn extract_bound(obj: &Bound<'py, PyAny>) -> PyResult<Self> {
impl<'py> FromPyObject<'_, 'py> for PyLengthOrExpr {
type Error = PyErr;
fn extract(obj: Borrowed<'_, 'py, PyAny>) -> PyResult<Self> {
Ok(PyLengthOrExpr(if let Ok(value) = obj.extract::<f32>() {
LengthOrExpr::points(value)
} else if let Ok(value) = obj.extract::<&str>() {
Expand All @@ -43,8 +44,9 @@ impl<'py> FromPyObject<'py> for PyLengthOrExpr {

struct PyLength(Length);

impl<'py> FromPyObject<'py> for PyLength {
fn extract_bound(obj: &Bound<'py, PyAny>) -> PyResult<Self> {
impl<'py> FromPyObject<'_, 'py> for PyLength {
type Error = PyErr;
fn extract(obj: Borrowed<'_, 'py, PyAny>) -> PyResult<Self> {
Ok(PyLength(if let Ok(value) = obj.extract::<f32>() {
Length::Points { value }
} else if let Ok(value) = obj.extract::<&str>() {
Expand All @@ -57,8 +59,9 @@ impl<'py> FromPyObject<'py> for PyLength {

struct PyLengthOrAuto(LengthOrAuto);

impl<'py> FromPyObject<'py> for PyLengthOrAuto {
fn extract_bound(obj: &Bound<'py, PyAny>) -> PyResult<Self> {
impl<'py> FromPyObject<'_, 'py> for PyLengthOrAuto {
type Error = PyErr;
fn extract(obj: Borrowed<'_, 'py, PyAny>) -> PyResult<Self> {
Ok(PyLengthOrAuto(if let Ok(value) = obj.extract::<f32>() {
LengthOrAuto::Length(Length::Points { value })
} else if let Ok(value) = obj.extract::<&str>() {
Expand All @@ -71,8 +74,9 @@ impl<'py> FromPyObject<'py> for PyLengthOrAuto {

struct PyAlignItems(AlignItems);

impl<'py> FromPyObject<'py> for PyAlignItems {
fn extract_bound(obj: &Bound<'py, PyAny>) -> PyResult<Self> {
impl<'py> FromPyObject<'_, 'py> for PyAlignItems {
type Error = PyErr;
fn extract(obj: Borrowed<'_, 'py, PyAny>) -> PyResult<Self> {
let s = obj.extract::<&str>()?;
Ok(PyAlignItems(match s {
"start" => AlignItems::Start,
Expand All @@ -95,8 +99,9 @@ impl From<PyAlignItems> for AlignItems {

struct PyAlignContent(AlignContent);

impl<'py> FromPyObject<'py> for PyAlignContent {
fn extract_bound(obj: &Bound<'py, PyAny>) -> PyResult<Self> {
impl<'py> FromPyObject<'_, 'py> for PyAlignContent {
type Error = PyErr;
fn extract(obj: Borrowed<'_, 'py, PyAny>) -> PyResult<Self> {
let s = obj.extract::<&str>()?;
Ok(PyAlignContent(match s {
"start" => AlignContent::Start,
Expand All @@ -121,8 +126,9 @@ impl From<PyAlignContent> for AlignContent {

struct PyGridTemplateItem(NonRepeatedTrackSizingFunction);

impl<'py> FromPyObject<'py> for PyGridTemplateItem {
fn extract_bound(obj: &Bound<'py, PyAny>) -> PyResult<Self> {
impl<'py> FromPyObject<'_, 'py> for PyGridTemplateItem {
type Error = PyErr;
fn extract(obj: Borrowed<'_, 'py, PyAny>) -> PyResult<Self> {
Ok(PyGridTemplateItem(
if let Ok(value) = obj.extract::<f32>() {
NonRepeatedTrackSizingFunction::from_length(value)
Expand Down Expand Up @@ -156,7 +162,7 @@ impl From<PyGridTemplateItem> for NonRepeatedTrackSizingFunction {

struct PyGridLinePlacement(Line<GridPlacement>);

fn parse_grid_placement_item(obj: &Bound<PyAny>) -> PyResult<GridPlacement> {
fn parse_grid_placement_item(obj: Borrowed<'_, '_, PyAny>) -> PyResult<GridPlacement> {
if obj.is_none() {
return Ok(GridPlacement::Auto);
}
Expand All @@ -180,20 +186,19 @@ fn parse_grid_placement_item(obj: &Bound<PyAny>) -> PyResult<GridPlacement> {
}
}

impl<'py> FromPyObject<'py> for PyGridLinePlacement {
fn extract_bound(obj: &Bound<'py, PyAny>) -> PyResult<Self> {
impl<'py> FromPyObject<'_, 'py> for PyGridLinePlacement {
type Error = PyErr;
fn extract(obj: Borrowed<'_, 'py, PyAny>) -> PyResult<Self> {
if let Ok(value) = parse_grid_placement_item(obj) {
return Ok(PyGridLinePlacement(Line {
start: value,
end: GridPlacement::Auto,
}));
} else if let Ok((value1, value2)) = obj.extract::<(Bound<'py, PyAny>, Bound<'py, PyAny>)>()
&& let Ok(start) = parse_grid_placement_item(value1.as_borrowed())
&& let Ok(end) = parse_grid_placement_item(value2.as_borrowed())
{
if let Ok(start) = parse_grid_placement_item(&value1) {
if let Ok(end) = parse_grid_placement_item(&value2) {
return Ok(PyGridLinePlacement(Line { start, end }));
}
}
return Ok(PyGridLinePlacement(Line { start, end }));
}
Err(PyValueError::new_err("Invalid grid placement"))
}
Expand Down
10 changes: 6 additions & 4 deletions nelsie/src/pyinterface/image.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use super::ora::create_ora;
use crate::common::steps::{bool_at_step, Step};
use crate::common::steps::{Step, bool_at_step};
use crate::parsers::steps::parse_bool_steps;
use itertools::Itertools;
use pyo3::exceptions::{PyException, PyValueError};
use pyo3::types::PyAnyMethods;
use pyo3::{
pyclass, pyfunction, pymethods, Bound, FromPyObject, IntoPyObject, PyAny, PyResult, Python,
Borrowed, Bound, FromPyObject, IntoPyObject, PyAny, PyErr, PyResult, Python, pyclass,
pyfunction, pymethods,
};
use renderer::{InMemoryBinImage, InMemorySvgImage, Rectangle};
use resvg::usvg::roxmltree;
Expand Down Expand Up @@ -292,8 +293,9 @@ pub(crate) enum PyImageFormat {
Svg,
}

impl<'py> FromPyObject<'py> for PyImageFormat {
fn extract_bound(ob: &Bound<'py, PyAny>) -> PyResult<Self> {
impl<'py> FromPyObject<'_, 'py> for PyImageFormat {
type Error = PyErr;
fn extract(ob: Borrowed<'_, 'py, PyAny>) -> PyResult<Self> {
let s: &str = ob.extract()?;
Ok(match s {
"png" => Self::Png,
Expand Down
Loading