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 parse(contents: &[u8]) -> Option<ScriptTag>
pub fn parse(contents: &[u8]) -> Option<ScriptTag>
Given the contents of a Python file, extract the script metadata block with leading
comment hashes removed, any preceding shebang or content (prelude), and the remaining 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 would return:
- Preamble:
#!/usr/bin/env python3\n - Metadata:
requires-python = '>=3.11'\ndependencies = [\n 'requests<3',\n 'rich',\n] - Postlude:
import requests\n\nprint("Hello, World!")\n
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.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