Skip to content

Commit ad75680

Browse files
committed
Add python binding for rust PURL validation
Signed-off-by: Keshav Priyadarshi <[email protected]>
1 parent 27b6e04 commit ad75680

File tree

4 files changed

+217
-1
lines changed

4 files changed

+217
-1
lines changed

Cargo.lock

Lines changed: 180 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ repository = "https://github.com/aboutcode-org/purl-validator"
99

1010
[lib]
1111
name = "purl_validator"
12-
crate-type = ["rlib"]
12+
crate-type = ["cdylib", "rlib"]
1313

1414
[dependencies]
1515
fst = "0.4.7"
1616
once_cell = "1.21"
17+
pyo3 = { version = "0.27.1", features = ["extension-module"] }
1718

1819
[[bin]]
1920
name = "fst_builder"
@@ -26,3 +27,9 @@ include = [
2627
"README.md",
2728
"LICENSE"
2829
]
30+
31+
[package.metadata.maturin]
32+
name = "purl_validator"
33+
34+
[tool.maturin]
35+
include = ["purls.fst"]

pyproject.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[build-system]
2+
requires = ["maturin>=1.5"]
3+
build-backend = "maturin"
4+
5+
[project]
6+
name = "purl-validator"
7+
version = "0.1.0"
8+
description = "PackageURL validator using prebuilt FST"
9+
authors = [
10+
{ name = "Keshav Priyadarshi", email = "[email protected]" },
11+
{ name = "AboutCode", email = "[email protected]" },
12+
]
13+
license = "Apache-2.0"
14+
readme = "README.md"
15+
requires-python = ">=3.10"
16+
17+
[tool.maturin]
18+
name = "purl_validator"

src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,14 @@ pub fn validate(word: &str) -> bool {
1313
VALIDATOR.contains(word)
1414
}
1515

16+
17+
#[pyo3::pymodule]
18+
mod purl_validator {
19+
use pyo3::prelude::*;
20+
use crate::validate;
21+
22+
#[pyfunction(name = "validate")]
23+
fn py_validate(word: &str) -> PyResult<bool> {
24+
Ok(validate(word))
25+
}
26+
}

0 commit comments

Comments
 (0)