Add PEP 723 inline script metadata support#452
Open
gilgamezh wants to merge 1 commit into
Open
Conversation
Closes #423. fades now understands the PEP 723 `# /// script` metadata block, so it can run scripts written for other runners (pipx, pip-run, uv) and vice versa. - parse the block's `dependencies` and merge them like any other source - honor `requires-python`: keep the selected interpreter if it satisfies the specifier, otherwise auto-discover a suitable one on PATH (failing cleanly if none is available); an explicit --python that conflicts is reported instead of being silently overridden - malformed metadata (bad TOML, bad requirement, bad/non-string requires-python, non-list dependencies, multiple script blocks) raises a clean FadesError with an explanatory log line instead of dumping a traceback - use stdlib tomllib on 3.11+, falling back to tomli on older Pythons Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
Author
|
Did run tests here because we only run them when target is master https://github.com/PyAr/fades/actions/runs/27750679594 should be executed when we change the target branch |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requires #451 pointing to it until it's merged
Closes #423.
PEP 723 defines a standard
# /// scriptcomment block (TOML) for declaring a single-file script'sdependenciesandrequires-python. It's implemented by pipx, pip-run and uv. This adds support to fades so it can run scripts written for other runners — and so scripts written for fades can run on them.What it does
dependencies: parsed from the block and merged like every other dependency source (inline# fadesmarks, docstrings,-rfiles,-dflags).requires-python: honored by selecting a suitable interpreter — the currently selected one (--pythonor fades' own) if it satisfies the specifier, otherwise an auto-discoveredpythonX.YonPATH, failing cleanly if none is available. An explicit--pythonthat conflicts is reported rather than silently overridden, so the user stays in control.tomllibon Python 3.11+, falling back totomlion older versions (conditional dependency insetup.py).requires-python, non-listdependencies, multiplescriptblocks) raises a cleanFadesErrorwith an explanatory log line instead of dumping a traceback.Example:
requires-pythonbehaviorThis goes beyond pipx and pip-run, which both ignore
requires-python(only uv honors it, via its own interpreter management). Since fades has no interpreter management, the chosen behavior is:--python→ discover a matchingpythonX.YonPATH, else fail;--pythonwas given → fail (don't override the user's explicit choice).Discovery is best-effort over
PATH(python3.6–python3.29,python3,python). Happy to dial this back to validate-only if preferred.Tests
New
tests/test_parsing/test_pep723.pyplus fixtures, interpreter-selection/version-probe tests intest_helpers.py, and aconsolidate_dependenciestest intest_main.py. Full suite green (./test), flake8 clean. Docs updated inREADME.rstandman/fades.1.🤖 Generated with Claude Code