pub struct ScriptTag { /* private fields */ }Expand description
PEP 723 metadata as parsed from a script comment block.
See: https://peps.python.org/pep-0723/
Vendored from: https://github.com/astral-sh/uv/blob/debe67ffdb0cd7835734100e909b2d8f79613743/crates/uv-scripts/src/lib.rs#L283
Implementations§
Source§impl ScriptTag
impl ScriptTag
Sourcepub fn source_map(&self) -> &ScriptSourceMap
pub fn source_map(&self) -> &ScriptSourceMap
Returns the map from extracted TOML offsets to their original script offsets.
Sourcepub fn parse(contents: &[u8]) -> Option<Self>
pub fn parse(contents: &[u8]) -> Option<Self>
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:
#!/usr/bin/env python3
# /// script
# requires-python = '>=3.11'
# dependencies = [
# 'requests<3',
# 'rich',
# ]
# ///
import requests
print("Hello, World!")This function extracts the metadata:
requires-python = '>=3.11'
dependencies = [
'requests<3',
'rich',
]Trait Implementations§
impl Eq for ScriptTag
impl StructuralPartialEq for ScriptTag
Auto Trait Implementations§
impl Freeze for ScriptTag
impl RefUnwindSafe for ScriptTag
impl Send for ScriptTag
impl Sync for ScriptTag
impl Unpin for ScriptTag
impl UnsafeUnpin for ScriptTag
impl UnwindSafe for ScriptTag
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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