Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scripts: added inline script metadata per PEP 723 #11597

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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
@isaac-mcfadyen isaac-mcfadyen force-pushed the scripts-inline-metadata branch from fec7738 to 2ae9bb7 Compare February 2, 2025 16:55
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