Skip to content

Conversation

@isaac-mcfadyen
Copy link
Contributor

Motivation

In October 2023, PEP 723 introduced an official specification for inline script metadata: https://packaging.python.org/en/latest/specifications/inline-script-metadata/

Inline script metadata allows compatible tools to discover the dependencies of a given script without needing to parse any requirements.txt or pyproject.toml.

For example, the uv tool supports this, which means you can just run uv run ./script.py and it will automatically parse the metadata and create a temporary virtual environment.

Because inline metadata is just a comment, it's fully backwards-compatible; tools that don't use it will just ignore it.

Changes

This PR adds inline metadata to the Python scripts in the scripts/ directory, such that they can be directly run with compatible tools.

Example (note that I wasn't in a virtual environment and my global Python packages remained untouched):

❯ uv run ./scripts/get_chat_template.py CohereForAI/c4ai-command-r7b-12-2024 tool_use
Reading inline script metadata from `scripts/get_chat_template.py`
Installed 12 packages in 8ms
# ... output of script as normal ...

@github-actions github-actions bot added script Script related python python script changes labels Feb 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python python script changes script Script related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant