Skip to content

Commit a3b6aba

Browse files
authored
Merge pull request #1 from aboutcode-org/remve-py-binding
Remove Python binding from library
2 parents db7fbfb + 2cbdbc6 commit a3b6aba

File tree

6 files changed

+93
-214
lines changed

6 files changed

+93
-214
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,9 @@ edition = "2024"
55
authors = ["Keshav Priyadarshi <[email protected]>", "AboutCode <[email protected]>"]
66
description = "PackageURL validator using prebuilt FST"
77
license = "Apache-2.0"
8-
repository = "https://github.com/aboutcode-org/purl-validator"
8+
repository = "https://github.com/aboutcode-org/purl-validator-rust"
99

10-
[lib]
11-
name = "purl_validator"
12-
crate-type = ["cdylib", "rlib"]
13-
14-
[dependencies]
15-
fst = "0.4.7"
16-
once_cell = "1.21"
17-
pyo3 = { version = "0.27.1", features = ["extension-module"] }
18-
19-
[[bin]]
20-
name = "fst_builder"
21-
path = "fst_builder/main.rs"
10+
exclude = ["fst_builder/*"]
2211

2312
include = [
2413
"src/**",
@@ -28,8 +17,14 @@ include = [
2817
"LICENSE"
2918
]
3019

31-
[package.metadata.maturin]
20+
[lib]
3221
name = "purl_validator"
22+
crate-type = ["rlib"]
3323

34-
[tool.maturin]
35-
include = ["purls.fst"]
24+
[dependencies]
25+
fst = "0.4.7"
26+
once_cell = "1.21"
27+
28+
[[bin]]
29+
name = "fst_builder"
30+
path = "fst_builder/main.rs"

Makefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
build-fst:
22
cargo run --bin fst_builder
33

4-
build-python:
5-
maturin build --release
64

75
clean:
86
cargo clean
97
rm -f purls.fst
108
rm -rf target
119

12-
.PHONY: build-fst build-python clean
10+
.PHONY: build-fst clean

README.md

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,76 @@
1-
# purl-validator
1+
# purl-validator
2+
3+
[![License](https://img.shields.io/badge/License-Apache--2.0-blue.svg?style=for-the-badge)](https://opensource.org/licenses/Apache-2.0)
4+
[![Version](https://img.shields.io/github/v/release/aboutcode-org/purl-validator-rust?style=for-the-badge)](https://github.com/aboutcode-org/purl-validator-rust/releases)
5+
[![Test](https://img.shields.io/github/actions/workflow/status/aboutcode-org/purl-validator-rust/run-test.yml?style=for-the-badge&logo=github)](https://github.com/aboutcode-org/purl-validator-rust/actions)
6+
7+
**purl-validator** is a Rust library for validating [Package URLs (PURLs)](https://github.com/package-url/purl-spec). It works fully offline, including in **air-gapped** or **restricted environments**, and answers one key question: **Does the package this PURL represents actually exist?**
8+
9+
## How It Works?
10+
11+
**purl-validator** is shipped with a pre-built FST (Finite State Transducer), a set of compact automata containing latest Package URLs mined by the MineCode[^1]. Library uses this FST to perform lookups and confirm whether the **base PURL**[^2] exists.
12+
13+
## Currently Supported Ecosystems
14+
15+
- **nuget**: [https://www.nuget.org/](https://www.nuget.org/)
16+
17+
## Usage
18+
19+
Add `purl-validator` to your Rust dependency
20+
21+
```bash
22+
cargo add purl-validator
23+
```
24+
25+
Use it in your code like this
26+
27+
```rust
28+
use purl_validator::validate;
29+
30+
let result: bool = validate("pkg:nuget/FluentValidation");
31+
```
32+
33+
## Contribution
34+
35+
We welcome contributions from the community! If you find a bug or have an idea for a new feature, please open an issue on the GitHub repository. If you want to contribute code, you can fork the repository, make your changes, and submit a pull request.
36+
37+
* Please try to write a good commit message, see [good commit message wiki](https://aboutcode.readthedocs.io/en/latest/contributing/writing_good_commit_messages.html).
38+
* Add DCO `Sign Off` to your commits.
39+
40+
## Development Setup
41+
42+
Run these commands, starting from a git clone of [https://github.com/aboutcode-org/purl-validator-rust.git](https://github.com/aboutcode-org/purl-validator-rust.git)
43+
44+
Generate FST:
45+
46+
```bash
47+
make build-fst
48+
```
49+
50+
Run tests:
51+
52+
```bash
53+
make test
54+
```
55+
56+
## License
57+
58+
SPDX-License-Identifier: Apache-2.0
59+
60+
purl-validator is licensed under Apache License version 2.0.
61+
62+
```text
63+
You may not use this software except in compliance with the License.
64+
You may obtain a copy of the License at
65+
66+
http://www.apache.org/licenses/LICENSE-2.0
67+
68+
Unless required by applicable law or agreed to in writing, software
69+
distributed under the License is distributed on an "AS IS" BASIS,
70+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
71+
See the License for the specific language governing permissions and
72+
limitations under the License.
73+
```
74+
75+
[^1]: MineCode continuously collects package metadata from various package ecosystems to maintain an up-to-date catalog of known packages.
76+
[^2]: A Base Package URL is a Package URL without a version or subpath.

pyproject.toml

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/lib.rs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
11
use fst::Set;
22
use once_cell::sync::Lazy;
33

4-
54
static FST_BYTES: &[u8] = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/purls.fst"));
65

7-
static VALIDATOR: Lazy<Set<&[u8]>> = Lazy::new(|| {
8-
Set::new(FST_BYTES).expect("Failed to load FST from embedded bytes")
9-
});
10-
11-
12-
pub fn validate(word: &str) -> bool {
13-
VALIDATOR.contains(word)
14-
}
15-
16-
17-
#[pyo3::pymodule]
18-
mod purl_validator {
19-
use pyo3::prelude::*;
20-
use crate::validate;
6+
static VALIDATOR: Lazy<Set<&[u8]>> =
7+
Lazy::new(|| Set::new(FST_BYTES).expect("Failed to load FST from embedded bytes"));
218

22-
#[pyfunction(name = "validate")]
23-
fn py_validate(word: &str) -> PyResult<bool> {
24-
Ok(validate(word))
25-
}
9+
pub fn validate(packageurl: &str) -> bool {
10+
let trimmed_packageurl = packageurl.trim_end_matches("/");
11+
VALIDATOR.contains(trimmed_packageurl)
2612
}

0 commit comments

Comments
 (0)