use super::dialect::{Dialect, Import};
use super::prose::Prose;
pub(super) struct Python;
const PROSE: Prose = Prose {
line_comment: "#",
block_comment: None,
line_string: None,
quotes: b"\"'",
triple_quotes: &["\"\"\"", "'''"],
line_join: true,
};
impl Dialect for Python {
fn name(&self) -> &'static str {
"python"
}
fn extensions(&self) -> &'static [&'static str] {
&["py"]
}
fn manifests(&self) -> &'static [&'static str] {
&["pyproject.toml", "setup.py", "setup.cfg"]
}
fn vendored(&self, manifest: &str) -> Vec<String> {
let code = PROSE.code_only(manifest);
let raw = manifest.as_bytes();
let mut out = Vec::new();
let mut i = 0;
while let Some(head) = find_word(&code, b"path", i) {
let mut j = head + 4;
while matches!(code.get(j), Some(b' ' | b'\t')) {
j += 1;
}
i = head + 1;
if code.get(j) != Some(&b'=') {
continue;
}
if let Some(dir) = literal(raw, j + 1) {
out.push(dir.trim_end_matches('/').to_owned());
}
}
out
}
fn declared(&self, manifest: &str) -> Option<String> {
let code = PROSE.code_only(manifest);
let raw = manifest.as_bytes();
let head = find_line(&code, b"[project]")?;
let body_start = head + b"[project]".len();
let body_end = find_next_table(&code, body_start);
let mut i = body_start;
while i < body_end {
let line_end =
code[i..body_end].iter().position(|&b| b == b'\n').map_or(body_end, |o| i + o);
let indent =
code[i..line_end].iter().take_while(|&&b| matches!(b, b' ' | b'\t')).count();
let key = i + indent;
if code[key..line_end].starts_with(b"name") {
let mut j = key + 4;
while matches!(code.get(j), Some(b' ' | b'\t')) {
j += 1;
}
if code.get(j) == Some(&b'=')
&& let Some(value) = literal(raw, j + 1)
{
return Some(value);
}
}
i = line_end + 1;
}
None
}
fn ambient(&self) -> &'static [&'static str] {
STDLIB
}
fn prose(&self) -> &Prose {
&PROSE
}
fn imports(
&self,
path: &str,
roots: &[&str],
own: &str,
_source: &str,
code: &[u8],
) -> Vec<Import> {
let own = own.replace('-', "_");
let mut out = Vec::new();
let mut i = 0;
while i < code.len() {
let from_at = find_word(code, b"from", i);
let import_at = find_word(code, b"import", i);
let Some(at) = min_of(from_at, import_at) else { break };
if !at_statement_start(code, at) {
i = at + 1;
continue;
}
if from_at == Some(at) {
let (found, end) = parse_from(code, roots, &own, path, at);
out.extend(found);
i = end;
} else {
let (found, end) = parse_plain(code, roots, &own, path, at);
out.extend(found);
i = end;
}
}
out
}
#[allow(clippy::case_sensitive_file_extension_comparisons, reason = "import specs are literal")]
fn is_local(&self, spec: &str) -> bool {
spec.ends_with(".py")
}
fn escape_remedy(&self) -> &'static str {
"Python cannot follow a relative import past the top of its own package; \
name the dependency as an absolute import instead"
}
}
fn parse_from(
code: &[u8],
roots: &[&str],
own: &str,
path: &str,
at: usize,
) -> (Vec<Import>, usize) {
let mut j = at + 4;
if !matches!(code.get(j), Some(b' ' | b'\t')) {
return (Vec::new(), at + 4);
}
j = skip_h(code, j);
let dots = code[j..].iter().take_while(|&&b| b == b'.').count();
j += dots;
let mod_start = j;
j = skip_dotted(code, j);
let mut module = std::str::from_utf8(&code[mod_start..j]).unwrap_or("");
j = skip_h(code, j);
let Some(k) = find_word(code, b"import", j) else { return (Vec::new(), at + 4) };
if code[j..k].iter().any(|&b| !matches!(b, b' ' | b'\t' | b'\n')) {
return (Vec::new(), at + 4); }
j = skip_h(code, k + 6);
let (names, end) = read_name_list(code, j);
let mut out = Vec::new();
if dots == 0 {
if self_ref(module, roots, own) {
module = strip_own(module, own);
} else {
let top = module.split('.').next().unwrap_or("");
if top.is_empty() || !roots.contains(&top) {
if !top.is_empty() {
out.push(spec(at, top.to_owned()));
}
return (out, end);
}
}
}
let climbs = if dots == 0 { depth_of(path) } else { dots - 1 };
let prefix = "../".repeat(climbs);
let dir = if module.is_empty() {
prefix.trim_end_matches('/').to_owned()
} else {
format!("{prefix}{}", module.replace('.', "/"))
};
if dots == 0 {
out.extend(ancestors(&prefix, module, path).into_iter().map(|found| spec(at, found)));
}
if !module.is_empty() {
out.push(spec(at, format!("{dir}.py")));
}
out.push(spec(at, format!("{dir}/__init__.py")));
for name in names {
if name == "*" {
continue;
}
out.push(spec(at, format!("{dir}/{name}.py")));
out.push(spec(at, format!("{dir}/{name}/__init__.py")));
}
(out, end)
}
fn parse_plain(
code: &[u8],
roots: &[&str],
own: &str,
path: &str,
at: usize,
) -> (Vec<Import>, usize) {
let start = at + 6;
let eol = code[start..]
.iter()
.position(|&b| b == b'\n' || b == b';')
.map_or(code.len(), |o| start + o);
let mut out = Vec::new();
for piece in code[start..eol].split(|&b| b == b',') {
let piece = trim(piece);
if piece.is_empty() {
continue;
}
let cut = find(piece, b" as ").unwrap_or(piece.len());
let Ok(dotted) = std::str::from_utf8(trim(&piece[..cut])) else { continue };
if dotted.is_empty() {
continue;
}
let dotted = if self_ref(dotted, roots, own) {
strip_own(dotted, own) } else {
let top = dotted.split('.').next().unwrap_or("");
if !roots.contains(&top) {
out.push(spec(at, top.to_owned()));
continue;
}
dotted
};
let prefix = "../".repeat(depth_of(path));
let dir = if dotted.is_empty() {
prefix.trim_end_matches('/').to_owned()
} else {
format!("{prefix}{}", dotted.replace('.', "/"))
};
out.extend(ancestors(&prefix, dotted, path).into_iter().map(|found| spec(at, found)));
if !dotted.is_empty() {
out.push(spec(at, format!("{dir}.py")));
}
out.push(spec(at, format!("{dir}/__init__.py")));
}
(out, eol)
}
fn ancestors(prefix: &str, module: &str, path: &str) -> Vec<String> {
let mut out = Vec::new();
let mut walked = String::new();
let mut segments = module.split('.').peekable();
while let Some(segment) = segments.next() {
if segments.peek().is_none() {
break;
}
if !walked.is_empty() {
walked.push('/');
}
walked.push_str(segment);
if !path.starts_with(&format!("{walked}/")) {
out.push(format!("{prefix}{walked}/__init__.py"));
}
}
out
}
fn self_ref(module: &str, roots: &[&str], own: &str) -> bool {
!own.is_empty()
&& !roots.contains(&own)
&& (module == own || module.strip_prefix(own).is_some_and(|rest| rest.starts_with('.')))
}
fn strip_own<'a>(module: &'a str, own: &str) -> &'a str {
module.get(own.len()..).unwrap_or("").trim_start_matches('.')
}
fn spec(offset: usize, spec: String) -> Import {
Import { offset, spec }
}
fn depth_of(path: &str) -> usize {
path.rsplit_once('/').map_or(0, |(dir, _)| dir.split('/').count())
}
fn min_of(a: Option<usize>, b: Option<usize>) -> Option<usize> {
match (a, b) {
(Some(x), Some(y)) => Some(x.min(y)),
(Some(x), None) | (None, Some(x)) => Some(x),
(None, None) => None,
}
}
fn at_statement_start(code: &[u8], i: usize) -> bool {
let mut j = i;
while j > 0 && matches!(code[j - 1], b' ' | b'\t') {
j -= 1;
}
j == 0 || matches!(code[j - 1], b'\n' | b';' | b':')
}
fn is_ident(b: u8) -> bool {
b.is_ascii_alphanumeric() || b == b'_' || b >= 0x80
}
fn find_word(code: &[u8], word: &[u8], from: usize) -> Option<usize> {
let mut i = from;
while let Some(k) = find(&code[i..], word) {
let at = i + k;
let before = at == 0 || !is_ident(code[at - 1]);
let after = code.get(at + word.len()).is_none_or(|&b| !is_ident(b));
if before && after {
return Some(at);
}
i = at + 1;
}
None
}
fn skip_h(code: &[u8], mut j: usize) -> usize {
while matches!(code.get(j), Some(b' ' | b'\t')) {
j += 1;
}
j
}
fn skip_dotted(code: &[u8], mut j: usize) -> usize {
while code
.get(j)
.is_some_and(|&b| b.is_ascii_alphanumeric() || matches!(b, b'_' | b'.') || b >= 0x80)
{
j += 1;
}
j
}
fn read_name_list(code: &[u8], j: usize) -> (Vec<String>, usize) {
if code.get(j) == Some(&b'(') {
let close = find(&code[j + 1..], b")").map_or(code.len(), |o| j + 1 + o);
(split_names(&code[j + 1..close]), (close + 1).min(code.len()))
} else {
let eol =
code[j..].iter().position(|&b| b == b'\n' || b == b';').map_or(code.len(), |o| j + o);
(split_names(&code[j..eol]), eol)
}
}
fn split_names(chunk: &[u8]) -> Vec<String> {
chunk
.split(|&b| b == b',')
.filter_map(|raw| {
let piece = trim(raw);
if piece.is_empty() {
None
} else if piece == b"*" {
Some("*".to_owned())
} else {
let cut = find(piece, b" as ").unwrap_or(piece.len());
std::str::from_utf8(trim(&piece[..cut]))
.ok()
.filter(|s| !s.is_empty())
.map(str::to_owned)
}
})
.collect()
}
fn trim(bytes: &[u8]) -> &[u8] {
let start = bytes.iter().position(|&b| !b.is_ascii_whitespace()).unwrap_or(bytes.len());
let end = bytes.iter().rposition(|&b| !b.is_ascii_whitespace()).map_or(start, |p| p + 1);
&bytes[start..end]
}
fn find(haystack: &[u8], needle: &[u8]) -> Option<usize> {
haystack.windows(needle.len()).position(|w| w == needle)
}
fn find_line(code: &[u8], needle: &[u8]) -> Option<usize> {
let mut i = 0;
while i < code.len() {
let end = code[i..].iter().position(|&b| b == b'\n').map_or(code.len(), |o| i + o);
if trim(&code[i..end]) == needle {
return Some(i);
}
i = end + 1;
}
None
}
fn find_next_table(code: &[u8], from: usize) -> usize {
let mut i = from;
while i < code.len() {
let end = code[i..].iter().position(|&b| b == b'\n').map_or(code.len(), |o| i + o);
if trim(&code[i..end]).first() == Some(&b'[') {
return i;
}
i = end + 1;
}
code.len()
}
fn literal(raw: &[u8], from: usize) -> Option<String> {
let mut i = from;
while raw.get(i).is_some_and(u8::is_ascii_whitespace) {
i += 1;
}
let quote = *raw.get(i)?;
if quote != b'"' && quote != b'\'' {
return None;
}
i += 1;
let mut out = Vec::new();
while let Some(&ch) = raw.get(i) {
match ch {
b'\\' if quote == b'"' && i + 1 < raw.len() => {
out.push(raw[i + 1]);
i += 2;
}
b'\n' => return None,
b if b == quote => return String::from_utf8(out).ok(),
_ => {
out.push(ch);
i += 1;
}
}
}
None
}
#[rustfmt::skip]
const STDLIB: &[&str] = &[
"__future__", "_abc", "_aix_support", "_android_support", "_apple_support", "_ast",
"_ast_unparse", "_asyncio", "_bisect", "_blake2", "_bootsubprocess", "_bz2", "_codecs",
"_codecs_cn", "_codecs_hk", "_codecs_iso2022", "_codecs_jp", "_codecs_kr", "_codecs_tw",
"_collections", "_collections_abc", "_colorize", "_compat_pickle", "_compression",
"_contextvars", "_crypt", "_csv", "_ctypes", "_curses", "_curses_panel", "_datetime",
"_dbm", "_decimal", "_elementtree", "_frozen_importlib", "_frozen_importlib_external",
"_functools", "_gdbm", "_hashlib", "_heapq", "_hmac", "_imp", "_interpchannels",
"_interpqueues", "_interpreters", "_io", "_ios_support", "_json", "_locale", "_lsprof",
"_lzma", "_markupbase", "_md5", "_msi", "_multibytecodec", "_multiprocessing", "_opcode",
"_opcode_metadata", "_operator", "_osx_support", "_overlapped", "_pickle", "_posixshmem",
"_posixsubprocess", "_py_abc", "_py_warnings", "_pydatetime", "_pydecimal", "_pyio",
"_pylong", "_pyrepl", "_queue", "_random", "_remote_debugging", "_scproxy", "_sha1",
"_sha2", "_sha256", "_sha3", "_sha512", "_signal", "_sitebuiltins", "_socket", "_sqlite3",
"_sre", "_ssl", "_stat", "_statistics", "_string", "_strptime", "_struct", "_suggestions",
"_symtable", "_sysconfig", "_thread", "_threading_local", "_tkinter", "_tokenize",
"_tracemalloc", "_types", "_typing", "_uuid", "_warnings", "_weakref", "_weakrefset",
"_winapi", "_wmi", "_zoneinfo", "_zstd", "abc", "aifc", "annotationlib", "antigravity",
"argparse", "array", "ast", "asynchat", "asyncio", "asyncore", "atexit", "audioop",
"base64", "bdb", "binascii", "binhex", "bisect", "builtins", "bz2", "cProfile", "calendar",
"cgi", "cgitb", "chunk", "cmath", "cmd", "code", "codecs", "codeop", "collections",
"colorsys", "compileall", "compression", "concurrent", "configparser", "contextlib",
"contextvars", "copy", "copyreg", "crypt", "csv", "ctypes", "curses", "dataclasses",
"datetime", "dbm", "decimal", "difflib", "dis", "distutils", "doctest", "email",
"encodings", "ensurepip", "enum", "errno", "faulthandler", "fcntl", "filecmp", "fileinput",
"fnmatch", "fractions", "ftplib", "functools", "gc", "genericpath", "getopt", "getpass",
"gettext", "glob", "graphlib", "grp", "gzip", "hashlib", "heapq", "hmac", "html", "http",
"idlelib", "imaplib", "imghdr", "imp", "importlib", "inspect", "io", "ipaddress",
"itertools", "json", "keyword", "lib2to3", "linecache", "locale", "logging", "lzma",
"mailbox", "mailcap", "marshal", "math", "mimetypes", "mmap", "modulefinder", "msilib",
"msvcrt", "multiprocessing", "netrc", "nis", "nntplib", "nt", "ntpath", "nturl2path",
"numbers", "opcode", "operator", "optparse", "os", "ossaudiodev", "pathlib", "pdb",
"pickle", "pickletools", "pipes", "pkgutil", "platform", "plistlib", "poplib", "posix",
"posixpath", "pprint", "profile", "pstats", "pty", "pwd", "py_compile", "pyclbr", "pydoc",
"pydoc_data", "pyexpat", "queue", "quopri", "random", "re", "readline", "reprlib",
"resource", "rlcompleter", "runpy", "sched", "secrets", "select", "selectors", "shelve",
"shlex", "shutil", "signal", "site", "smtpd", "smtplib", "sndhdr", "socket",
"socketserver", "spwd", "sqlite3", "sre_compile", "sre_constants", "sre_parse", "ssl",
"stat", "statistics", "string", "stringprep", "struct", "subprocess", "sunau", "symtable",
"sys", "sysconfig", "syslog", "tabnanny", "tarfile", "telnetlib", "tempfile", "termios",
"textwrap", "this", "threading", "time", "timeit", "tkinter", "token", "tokenize",
"tomllib", "trace", "traceback", "tracemalloc", "tty", "turtle", "turtledemo", "types",
"typing", "unicodedata", "unittest", "urllib", "uu", "uuid", "venv", "warnings", "wave",
"weakref", "webbrowser", "winreg", "winsound", "wsgiref", "xdrlib", "xml", "xmlrpc",
"zipapp", "zipfile", "zipimport", "zlib", "zoneinfo",
];
#[cfg(test)]
#[allow(clippy::expect_used, reason = "a test that cannot construct its fixture has failed")]
mod tests {
use super::*;
fn specs(path: &str, roots: &[&str], source: &str) -> Vec<String> {
owned_specs(path, roots, "", source)
}
fn owned_specs(path: &str, roots: &[&str], own: &str, source: &str) -> Vec<String> {
let code = PROSE.code_only(source);
Python.imports(path, roots, own, source, &code).into_iter().map(|i| i.spec).collect()
}
#[test]
fn plain_absolute_import_of_a_root_package() {
assert_eq!(
specs("pkg/mod.py", &["pkg"], "import pkg.util\n"),
["../pkg/util.py", "../pkg/util/__init__.py"]
);
}
#[test]
fn plain_import_of_an_external_dependency() {
assert_eq!(specs("pkg/mod.py", &["pkg"], "import numpy as np\n"), ["numpy"]);
}
#[test]
fn comma_separated_plain_imports() {
assert_eq!(
specs("mod.py", &["pkg"], "import os, pkg.a, sys\n"),
["os", "pkg/__init__.py", "pkg/a.py", "pkg/a/__init__.py", "sys"]
);
}
#[test]
fn from_import_of_named_submodules() {
assert_eq!(
specs("pkg/mod.py", &["pkg"], "from pkg import a, b\n"),
[
"../pkg.py",
"../pkg/__init__.py",
"../pkg/a.py",
"../pkg/a/__init__.py",
"../pkg/b.py",
"../pkg/b/__init__.py",
]
);
}
#[test]
fn from_import_of_an_external_module_is_one_departure() {
assert_eq!(
specs("pkg/mod.py", &["pkg"], "from collections import OrderedDict\n"),
["collections"]
);
}
#[test]
fn relative_import_same_directory() {
assert_eq!(
specs("pkg/mod.py", &["pkg"], "from . import sibling\n"),
["/__init__.py", "/sibling.py", "/sibling/__init__.py"]
);
}
#[test]
fn relative_import_climbs_a_level() {
assert_eq!(
specs("pkg/sub/mod.py", &["pkg"], "from .. import sibling\n"),
["../__init__.py", "../sibling.py", "../sibling/__init__.py"]
);
}
#[test]
fn relative_import_with_a_named_module() {
assert_eq!(
specs("pkg/sub/mod.py", &["pkg"], "from ..util import helper\n"),
[
"../util.py",
"../util/__init__.py",
"../util/helper.py",
"../util/helper/__init__.py",
]
);
}
#[test]
fn star_import_names_only_the_base() {
assert_eq!(
specs("pkg/mod.py", &["pkg"], "from pkg.sub import *\n"),
["../pkg/sub.py", "../pkg/sub/__init__.py"]
);
}
#[test]
fn parenthesized_multiline_names() {
let src = "from pkg import (\n a,\n b as c,\n)\n";
assert_eq!(
specs("mod.py", &["pkg"], src),
[
"pkg.py",
"pkg/__init__.py",
"pkg/a.py",
"pkg/a/__init__.py",
"pkg/b.py",
"pkg/b/__init__.py",
]
);
}
#[test]
fn comments_and_docstrings_are_not_mistaken_for_imports() {
let src = "\
\"\"\"
import fake.one
\"\"\"
# import fake.two
import real\n";
assert_eq!(specs("mod.py", &[], src), ["real"]);
}
#[test]
fn a_flat_package_recognizes_its_own_declared_name() {
assert_eq!(
owned_specs(
"runtime/host.py",
&["contracts", "runtime"],
"acme",
"from acme.contracts.types import Event\n"
),
[
"../contracts/__init__.py",
"../contracts/types.py",
"../contracts/types/__init__.py",
"../contracts/types/Event.py",
"../contracts/types/Event/__init__.py",
]
);
assert_eq!(
owned_specs(
"runtime/host.py",
&["contracts", "runtime"],
"acme",
"import acme.contracts.types\n"
),
["../contracts/__init__.py", "../contracts/types.py", "../contracts/types/__init__.py"]
);
}
#[test]
fn a_bare_self_import_names_the_module_roots_own_init() {
assert_eq!(
owned_specs("runtime/host.py", &["contracts", "runtime"], "acme", "import acme\n"),
["../__init__.py"]
);
assert_eq!(
owned_specs(
"runtime/host.py",
&["contracts", "runtime"],
"acme",
"from acme import contracts\n"
),
["../__init__.py", "../contracts.py", "../contracts/__init__.py"]
);
}
#[test]
fn a_hyphenated_declared_name_matches_its_underscored_import() {
assert_eq!(
owned_specs(
"mod.py",
&["contracts"],
"my-package",
"from my_package.contracts import X\n"
),
["contracts.py", "contracts/__init__.py", "contracts/X.py", "contracts/X/__init__.py"]
);
}
#[test]
fn a_package_that_already_has_a_directory_of_its_own_name_is_untouched() {
assert_eq!(
owned_specs("mod.py", &["acme"], "acme", "from acme.contracts import X\n"),
[
"acme/__init__.py",
"acme/contracts.py",
"acme/contracts/__init__.py",
"acme/contracts/X.py",
"acme/contracts/X/__init__.py",
]
);
}
#[test]
fn raise_from_and_yield_from_are_not_import_statements() {
let src = "\
def f():
raise ValueError() from cause
yield from other()
";
assert_eq!(specs("mod.py", &[], src), Vec::<String>::new());
}
#[test]
fn indented_and_semicolon_separated_imports_are_still_statements() {
let src = "\
if True:
import os
import sys; import re
";
assert_eq!(specs("mod.py", &[], src), ["os", "sys", "re"]);
}
#[test]
fn a_backslash_continues_a_name_list_onto_the_next_line() {
assert_eq!(specs("mod.py", &[], "import os, \\\n sys\n"), ["os", "sys"]);
assert_eq!(
specs("mod.py", &[], "from collections import abc, \\\n OrderedDict\n"),
["collections"]
);
}
#[test]
fn a_backslash_continues_a_from_clause_before_its_import() {
assert_eq!(specs("mod.py", &[], "from os \\\n import path\n"), ["os"]);
}
#[test]
fn only_the_word_import_counts_not_a_longer_identifier() {
assert_eq!(
specs("mod.py", &[], "import_module('x')\nreimport = 1\n"),
Vec::<String>::new()
);
}
#[test]
fn an_absolute_import_depends_on_every_ancestor_it_initializes() {
assert_eq!(
specs("low/consumer.py", &["mid"], "import mid.deep.leaf\n"),
[
"../mid/__init__.py",
"../mid/deep/__init__.py",
"../mid/deep/leaf.py",
"../mid/deep/leaf/__init__.py",
]
);
assert_eq!(
specs("low/consumer.py", &["mid"], "from mid.deep.leaf import LEAF\n"),
[
"../mid/__init__.py",
"../mid/deep/__init__.py",
"../mid/deep/leaf.py",
"../mid/deep/leaf/__init__.py",
"../mid/deep/leaf/LEAF.py",
"../mid/deep/leaf/LEAF/__init__.py",
]
);
}
#[test]
fn a_file_owes_nothing_to_the_package_root_it_already_lives_under() {
assert_eq!(
specs("principia/linalg/ops.py", &["principia"], "from principia._loader import ffi\n"),
[
"../../principia/_loader.py",
"../../principia/_loader/__init__.py",
"../../principia/_loader/ffi.py",
"../../principia/_loader/ffi/__init__.py",
]
);
}
#[test]
fn a_relative_import_owes_nothing_to_the_ancestors_it_climbs_through() {
assert_eq!(
specs("mid/deep/mod.py", &["mid"], "from ..other.leaf import X\n"),
[
"../other/leaf.py",
"../other/leaf/__init__.py",
"../other/leaf/X.py",
"../other/leaf/X/__init__.py",
]
);
}
#[test]
fn is_local_distinguishes_a_produced_path_from_a_module_name() {
assert!(Python.is_local("../pkg/a.py"));
assert!(!Python.is_local("numpy"));
assert!(!Python.is_local("os"));
}
#[test]
fn declared_reads_the_pep_621_project_name() {
let manifest = "\
[build-system]
requires = [\"hatchling\"]
[project]
name = \"my-package\"
version = \"0.1.0\"
";
assert_eq!(Python.declared(manifest).as_deref(), Some("my-package"));
let manifest = "\
[project]
# name = \"wrong\"
name = \"right\"
";
assert_eq!(Python.declared(manifest).as_deref(), Some("right"));
assert_eq!(Python.declared("[tool.other]\nname = \"x\"\n"), None);
}
#[test]
fn vendored_reads_path_dependencies() {
let manifest = "\
[tool.uv.sources]
mypackage = { path = \"../mypackage\" }
";
assert_eq!(Python.vendored(manifest), ["../mypackage"]);
}
#[test]
fn stdlib_covers_the_modules_every_supported_interpreter_ships() {
for name in ["os", "sys", "typing", "__future__", "tomllib", "dataclasses"] {
assert!(STDLIB.contains(&name), "{name} should be ambient");
}
}
}