pub struct PypiParser;Expand description
Parser for Python pyproject.toml files.
Supports both PEP 621 standard format and Poetry format.
Uses toml_edit to preserve source positions for LSP operations.
§Examples
use deps_pypi::parser::PypiParser;
use tower_lsp_server::ls_types::Uri;
let content = r#"
[project]
dependencies = ["requests>=2.28.0", "flask[async]>=3.0"]
"#;
let parser = PypiParser::new();
let uri = Uri::from_file_path("/test/pyproject.toml").unwrap();
let result = parser.parse_content(content, &uri).unwrap();
assert_eq!(result.dependencies.len(), 2);Implementations§
Source§impl PypiParser
impl PypiParser
Sourcepub const fn new() -> PypiParser
pub const fn new() -> PypiParser
Create a new PyPI parser.
Sourcepub fn parse_content(
&self,
content: &str,
uri: &Uri,
) -> Result<ParseResult, PypiError>
pub fn parse_content( &self, content: &str, uri: &Uri, ) -> Result<ParseResult, PypiError>
Parse pyproject.toml content and extract all dependencies.
Parses both PEP 621 and Poetry formats in a single pass.
§Errors
Returns an error if:
- TOML is malformed
- PEP 508 dependency specifications are invalid
§Examples
let parser = PypiParser::new();
let content = std::fs::read_to_string("pyproject.toml").unwrap();
let uri = Uri::from_file_path("/project/pyproject.toml").unwrap();
let result = parser.parse_content(&content, &uri).unwrap();Trait Implementations§
Source§impl Default for PypiParser
impl Default for PypiParser
Source§fn default() -> PypiParser
fn default() -> PypiParser
Returns the “default value” for a type. Read more
Source§impl ManifestParser for PypiParser
impl ManifestParser for PypiParser
Source§type Dependency = PypiDependency
type Dependency = PypiDependency
Parsed dependency type for this ecosystem.
Source§type ParseResult = ParseResult
type ParseResult = ParseResult
Parse result containing dependencies and optional workspace information.
Source§fn parse(
&self,
content: &str,
doc_uri: &Uri,
) -> Result<<PypiParser as ManifestParser>::ParseResult, DepsError>
fn parse( &self, content: &str, doc_uri: &Uri, ) -> Result<<PypiParser as ManifestParser>::ParseResult, DepsError>
Parses a manifest file and extracts all dependencies with positions. Read more
Auto Trait Implementations§
impl Freeze for PypiParser
impl RefUnwindSafe for PypiParser
impl Send for PypiParser
impl Sync for PypiParser
impl Unpin for PypiParser
impl UnwindSafe for PypiParser
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more