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

Support PEP-723 Style in-line metadata annotated scripts #266

Open
clayrosenthal opened this issue Nov 25, 2024 · 0 comments · May be fixed by #267
Open

Support PEP-723 Style in-line metadata annotated scripts #266

clayrosenthal opened this issue Nov 25, 2024 · 0 comments · May be fixed by #267

Comments

@clayrosenthal
Copy link

PEP-723 describes how to add comments to a script to specify what its dependencies should be similar to a pyproject.toml. The Python Packaging Docs give more information and include future updates to the spec.

example.py:

# /// script
# requires-python = ">=3.11"
# dependencies = [
#   "requests<3",
#   "rich",
# ]
# ///

import requests
from rich.pretty import pprint

resp = requests.get("https://peps.python.org/api/peps.json")
data = resp.json()
pprint([(k, v["title"]) for k, v in data.items()][:10])

uv supports running the above script directly with uv run example.py. The downside with this is that each time you run it with uv it will make calls to the network to ensure its on the correct versions of the packages each time. Fine for development, less so for production use cases.

It would be nice if shiv could do something similar like shiv --inline-script example.py --output-file example to make a portable script that needs no network requirement.

@clayrosenthal clayrosenthal linked a pull request Dec 3, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant