Skip to main content

python_facade_basic_usage/
basic_usage.rs

1use use_python::{
2    PipRequirement, PytestNodeId, PythonIdentifier, PythonImplementation, PythonPrimitiveValue,
3    PythonVersion,
4};
5
6fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let version: PythonVersion = "Python 3.12.1".parse()?;
8    let identifier = PythonIdentifier::new("async_task")?;
9    let requirement = PipRequirement::new("requests>=2")?;
10    let node_id = PytestNodeId::new("tests/test_app.py::test_smoke")?;
11
12    assert!(version.is_python3());
13    assert_eq!(identifier.as_str(), "async_task");
14    assert_eq!(PythonImplementation::CPython.as_str(), "cpython");
15    assert_eq!(PythonPrimitiveValue::None.type_name(), "NoneType");
16    assert!(!requirement.is_editable());
17    assert!(node_id.has_scope_separator());
18    Ok(())
19}