Skip to content

Commit 3bf7f26

Browse files
committed
Add some metadata to ua-parser-py
While it's not really in need of documentation as it's an implementation detail of uap-python, opening the link to the dependency from the main package and seeing an empty page is rather suspicious. Adding info / metadata would, I hope and assume, assuage fears. Fixes #13
1 parent 2cd7c6a commit 3bf7f26

File tree

3 files changed

+32
-14
lines changed

3 files changed

+32
-14
lines changed

ua-parser-py/Cargo.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
[package]
22
name = "ua-parser-rs"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
edition = "2021"
55
license = "Apache 2.0"
6+
description = "A native accelerator for uap-python"
7+
repository = "https://github.com/ua-parser/uap-rust/"
8+
homepage = "https://github.com/ua-parser/uap-rust/blob/main/ua-parser/"
9+
authors = ["masklinn <[email protected]>"]
610

711
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
812
[lib]
913
name = "ua_parser_rs"
1014
crate-type = ["cdylib"]
1115

1216
[dependencies]
13-
pyo3 = { version = "0.22", features = ["extension-module", "abi3", "abi3-py38"] }
17+
pyo3 = { version = "0.22", features = ["extension-module", "abi3", "abi3-py39"] }
1418
ua-parser = { version = "0.2.0", path = "../ua-parser" }

ua-parser-py/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
a ua-parser accelerator
2+
=======================
3+
4+
This package is (currently) not intended to be used directly, instead
5+
it is one of the native accelerators for [ua-parser][1].
6+
7+
The API is very simplistic and should be pretty stable (if only
8+
because having to update [ua-parser][1] all the time is undesirable),
9+
but there is no formal guarantee that it'll keep, as the goal is
10+
really nothing more than a very basic export of [uap-rust][2] to
11+
Python.
12+
13+
[1]: https://pypi.org/project/ua-parser/
14+
[2]: https://crates.io/crates/ua-parser

ua-parser-py/src/lib.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
/// them to Parsers as well but that's still very confusing given the
2626
/// global Parser object, unless *that* gets renamed to Extractor on
2727
/// the python side, or something.
28-
use pyo3::exceptions::PyValueError;
28+
use pyo3::{exceptions::PyValueError, types::PyString};
2929
use pyo3::prelude::*;
3030
use std::borrow::Cow::{self, Owned};
3131

@@ -42,15 +42,15 @@ struct UserAgentExtractor(ua_parser::user_agent::Extractor<'static>);
4242
#[pyclass(frozen)]
4343
struct UserAgent {
4444
#[pyo3(get)]
45-
family: String,
45+
family: Py<PyString>,
4646
#[pyo3(get)]
47-
major: Option<String>,
47+
major: Option<Py<PyString>>,
4848
#[pyo3(get)]
49-
minor: Option<String>,
49+
minor: Option<Py<PyString>>,
5050
#[pyo3(get)]
51-
patch: Option<String>,
51+
patch: Option<Py<PyString>>,
5252
#[pyo3(get)]
53-
patch_minor: Option<String>,
53+
patch_minor: Option<Py<PyString>>,
5454
}
5555
#[pymethods]
5656
impl UserAgentExtractor {
@@ -74,13 +74,13 @@ impl UserAgentExtractor {
7474
.map_err(|e| PyValueError::new_err(e.to_string()))
7575
.map(Self)
7676
}
77-
fn extract(&self, s: &str) -> PyResult<Option<UserAgent>> {
77+
fn extract(&self, py: Python<'_>, s: &str) -> PyResult<Option<UserAgent>> {
7878
Ok(self.0.extract(s).map(|v| UserAgent {
79-
family: v.family.into_owned(),
80-
major: v.major.map(|s| s.to_string()),
81-
minor: v.minor.map(|s| s.to_string()),
82-
patch: v.patch.map(|s| s.to_string()),
83-
patch_minor: v.patch_minor.map(|s| s.to_string()),
79+
family: PyString::new_bound(py, &v.family).unbind(),
80+
major: v.major.map(|s| PyString::new_bound(py, s).unbind()),
81+
minor: v.minor.map(|s| PyString::new_bound(py, s).unbind()),
82+
patch: v.patch.map(|s| PyString::new_bound(py, s).unbind()),
83+
patch_minor: v.patch_minor.map(|s| PyString::new_bound(py, s).unbind()),
8484
}))
8585
}
8686
}

0 commit comments

Comments
 (0)