{"record":{"id":"8fe8934adb2e4b90","repo":"astral-sh/uv","slug":"does-not-contain-inline-script-metadata","errorCode":null,"errorMessage":"`{}` does not contain inline script metadata","messagePattern":"`(.+?)` does not contain inline script metadata","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/uv-requirements/src/specification.rs","lineNumber":325,"sourceCode":"\n                Self {\n                    source_trees: vec![SourceTree::PyProjectToml(path.clone(), pyproject_toml)],\n                    ..Self::default()\n                }\n            }\n            RequirementsSource::Pep723Script(path) => {\n                let content = if let Some(content) = cache.get(path.as_path()) {\n                    content.clone()\n                } else {\n                    let content = read_file(path, client_builder).await?;\n                    cache.insert(path.clone(), content.clone());\n                    content\n                };\n\n                let metadata = match Pep723Metadata::parse(content.as_bytes()) {\n                    Ok(Some(script)) => script,\n                    Ok(None) => {\n                        return Err(anyhow::anyhow!(\n                            \"`{}` does not contain inline script metadata\",\n                            path.user_display(),\n                        ));\n                    }\n                    Err(err) => return Err(err.into()),\n                };\n\n                Self::from_pep723_metadata(&metadata)\n            }\n            RequirementsSource::SetupPy(path) => {\n                if !path.is_file() {\n                    return Err(anyhow::anyhow!(\"File not found: `{}`\", path.user_display()));\n                }\n\n                Self {\n                    source_trees: vec![SourceTree::SetupPy(path.clone())],\n                    ..Self::default()\n                }","sourceCodeStart":307,"sourceCodeEnd":343,"githubUrl":"https://github.com/astral-sh/uv/blob/f1a42680ff5272232d65748acf338b19778dde24/crates/uv-requirements/src/specification.rs#L307-L343","documentation":"Thrown in from_source_with_cache (crates/uv-requirements/src/specification.rs:325) when a RequirementsSource::Pep723Script's content parses without a PEP 723 metadata block — Pep723Metadata::parse returns Ok(None). The source was explicitly declared to be an inline-metadata script (e.g. `uv run script.py` resolving it as such), so uv errors rather than silently treating it as dependency-free.","triggerScenarios":"`uv run --with-requirements` style flows or programmatic RequirementsSource::Pep723Script(path) where the file lacks a `# /// script` TOML block; PEP 723 requires the metadata comment block (`# /// script\\n# dependencies = [...]`) and parse returns Ok(None) when absent.","commonSituations":"A script that once had inline metadata was stripped (formatter, copy-paste, minifier); the user renamed a requirements.txt to .py expecting uv to read it; the `# /// script` fence was mangled (e.g. wrong number of slashes or block key).","solutions":["Add a PEP 723 block to the script: `uv init --script script.py` scaffolds it","Manually insert the block starting with `# /// script` and listing `dependencies = [\"flask\"]` inside as TOML comments","If the script needs no metadata, pass its dependencies separately (e.g. `uv run --with flask script.py`)"],"exampleFix":"# before: script.py has no metadata block\n# after: script.py\n# /// script\n# requires-python = \">=3.12\"\n# dependencies = [\"flask\"]\n# ///\nimport flask","handlingStrategy":"validation","validationCode":"fn has_pep723_block(content: &str) -> bool {\n    // PEP 723 block must appear before the first statement; simple pre-check:\n    content.lines().take_while(|l| l.starts_with(\"#!\") || l.trim().is_empty())\n        .count();\n    content.contains(\"# /// script\")\n}\n\nlet content = std::fs::read_to_string(&path)?;\nif !has_pep723_block(&content) {\n    // treat as a plain script or require metadata before creating a Pep723Script source\n}","typeGuard":null,"tryCatchPattern":"match RequirementsSpecification::from_source(src, &client_builder).await {\n    Err(err) if err.to_string().contains(\"does not contain inline script metadata\") => {\n        // fall back: run script with explicit --with flags instead of metadata\n    }\n    spec => spec?,\n}","preventionTips":["Scaffold scripts with `uv init --script` so the metadata block is always present","Configure formatters (black/ruff) to keep comment blocks intact","In CI, grep scripts for `# /// script` when inline deps are expected"],"tags":["uv","pep723","inline-script-metadata","uv-run","file-format"],"backgroundTag":null,"analyzedSha":"f1a42680ff5272232d65748acf338b19778dde24","analyzedAt":"2026-08-16T04:51:47.599Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}