Last active
July 22, 2025 15:21
-
-
Save asdkant/0e70f10aa82864610799b9f2636c632b to your computer and use it in GitHub Desktop.
get TOML from inline python script metadata using awk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline script metadata docs: https://packaging.python.org/en/latest/specifications/inline-script-metadata/ | |
This awk line is useful because pip and uv can't read the TOML in the .py header directly, but they can read a separate TOML file without issue. | |
user@host:/tmp$ head -n 13 main.py | |
# /// script | |
# authors = [ | |
# { name = "John Doe", email = "[email protected]" } | |
# ] | |
# requires-python = ">=3.10" | |
# dependencies = [ | |
# "dotenv>=0.9.9", | |
# "repo1 @ git+https://github.com/org/repo1", | |
# "icecream>=2.1.5", | |
# "jsonpickle>=4.1.1", | |
# "repo2@git+https://github.com/org/repo2", | |
# ] | |
# /// | |
user@host:/tmp$ awk '/^# \/\/\/ script/ {in_block=1; next} in_block && /^# \/\/\// {exit} in_block { sub(/^# ?/, ""); print }' main.py | |
authors = [ | |
{ name = "John Doe", email = "[email protected]" } | |
] | |
requires-python = ">=3.10" | |
dependencies = [ | |
"dotenv>=0.9.9", | |
"repo1 @ git+https://github.com/org/repo1", | |
"icecream>=2.1.5", | |
"jsonpickle>=4.1.1", | |
"repo2@git+https://github.com/org/repo2", | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment