Skip to content

Commit f2e0aa8

Browse files
committed
feat: add __version__ in python module
1 parent b0a55c2 commit f2e0aa8

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

boreal-py/src/lib.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,28 @@ create_exception!(boreal, AddRuleError, PyException, "error when adding rules");
2323

2424
#[pymodule]
2525
fn boreal(m: &Bound<'_, PyModule>) -> PyResult<()> {
26+
let py = m.py();
27+
2628
m.add_function(wrap_pyfunction!(compile, m)?)?;
27-
m.add("modules", get_available_modules(m.py()))?;
2829

29-
m.add("AddRuleError", m.py().get_type::<AddRuleError>())?;
30-
m.add("ScanError", m.py().get_type::<scanner::ScanError>())?;
31-
m.add("TimeoutError", m.py().get_type::<scanner::TimeoutError>())?;
30+
m.add("modules", get_available_modules(py))?;
31+
m.add("__version__", env!("CARGO_PKG_VERSION"))?;
32+
33+
m.add("AddRuleError", py.get_type::<AddRuleError>())?;
34+
m.add("ScanError", py.get_type::<scanner::ScanError>())?;
35+
m.add("TimeoutError", py.get_type::<scanner::TimeoutError>())?;
3236

33-
m.add("Rule", m.py().get_type::<rule::Rule>())?;
34-
m.add("Match", m.py().get_type::<rule_match::Match>())?;
35-
m.add("Scanner", m.py().get_type::<scanner::Scanner>())?;
36-
m.add("RulesIter", m.py().get_type::<scanner::RulesIter>())?;
37+
m.add("Rule", py.get_type::<rule::Rule>())?;
38+
m.add("Match", py.get_type::<rule_match::Match>())?;
39+
m.add("Scanner", py.get_type::<scanner::Scanner>())?;
40+
m.add("RulesIter", py.get_type::<scanner::RulesIter>())?;
3741
m.add(
3842
"StringMatchInstance",
39-
m.py()
40-
.get_type::<string_match_instance::StringMatchInstance>(),
43+
py.get_type::<string_match_instance::StringMatchInstance>(),
4144
)?;
4245
m.add(
4346
"StringMatches",
44-
m.py().get_type::<string_matches::StringMatches>(),
47+
py.get_type::<string_matches::StringMatches>(),
4548
)?;
4649

4750
Ok(())

boreal-py/tests/test_api.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,8 @@ def test_modules(module, is_yara):
1010
assert 'pe' in modules
1111
assert 'time' in modules
1212
assert 'console' in modules
13+
14+
15+
@pytest.mark.parametrize('module,is_yara', MODULES)
16+
def test_version(module, is_yara):
17+
assert type(module.__version__) is str

0 commit comments

Comments
 (0)