#pyproject #pep517 #pep518 #pep621

pyproject-toml

pyproject.toml parser in Rust

8 releases

new 0.4.0 Mar 19, 2023
0.3.3 Jan 28, 2023
0.3.1 Nov 18, 2021
0.2.0 Aug 13, 2021
0.1.1 May 30, 2021

#365 in Parser implementations

Download history 2430/week @ 2022-11-27 2285/week @ 2022-12-04 1878/week @ 2022-12-11 2013/week @ 2022-12-18 1350/week @ 2022-12-25 1830/week @ 2023-01-01 2519/week @ 2023-01-08 2076/week @ 2023-01-15 2499/week @ 2023-01-22 4021/week @ 2023-01-29 2763/week @ 2023-02-05 3205/week @ 2023-02-12 2665/week @ 2023-02-19 2689/week @ 2023-02-26 2016/week @ 2023-03-05 2054/week @ 2023-03-12

9,685 downloads per month
Used in 2 crates

MIT license

10KB
154 lines

pyproject-toml-rs

GitHub Actions Crates.io docs.rs

pyproject.toml parser in Rust.

Installation

Add it to your Cargo.toml:

[dependencies]
pyproject-toml = "0.3"

then you are good to go. If you are using Rust 2015 you have to add extern crate pyproject_toml to your crate root as well.

Extended parsing

If you want to add additional fields parsing, you can do it with serde's flatten feature and implement the Deref trait, for example:

use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct PyProjectToml {
    #[serde(flatten)]
    inner: pyproject_toml::PyProjectToml,
    tool: Option<Tool>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "kebab-case")]
pub struct Tool {
    maturin: Option<ToolMaturin>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "kebab-case")]
pub struct ToolMaturin {
    sdist_include: Option<Vec<String>>,
}

impl std::ops::Deref for PyProjectToml {
    type Target = pyproject_toml::PyProjectToml;

    fn deref(&self) -> &Self::Target {
        &self.inner
    }
}

impl PyProjectToml {
    pub fn new(content: &str) -> Result<Self, toml::de::Error> {
        toml::from_str(content)
    }
}

License

This work is released under the MIT license. A copy of the license is provided in the LICENSE file.

Dependencies

~3.5MB
~71K SLoC