MCPcopy Create free account
hub / github.com/astral-sh/ruff / parse

Method parse

crates/ruff_python_ast/src/script.rs:65–69  ·  view source on GitHub ↗

Given the contents of a Python file, extract the `script` metadata block with leading comment hashes removed and map its offsets to the original Python script. Given the following input string representing the contents of a Python script: ```python #!/usr/bin/env python3 # /// script # requires-python = '>=3.11' # dependencies = [ # 'requests<3', # 'rich', # ] # /// import requests print("

(contents: &[u8])

Source from the content-addressed store, hash-verified

63 ///
64 /// See: <https://peps.python.org/pep-0723/>
65 pub fn parse(contents: &[u8]) -> Option<Self> {
66 FINDER
67 .find_iter(contents)
68 .find_map(|index| Self::parse_at(contents, index))
69 }
70
71 fn parse_at(contents: &[u8], index: usize) -> Option<Self> {
72 // The opening pragma must be the first line, or immediately preceded by a newline.

Callers 2

try_fromMethod · 0.45
deserializeMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected