For some additional context: PEP 722[1] proposes a similar technique, but only for the script's requirements (and not the full TOML-formatted package metadata).<p>[1]: <a href="https://peps.python.org/pep-0722/" rel="nofollow noreferrer">https://peps.python.org/pep-0722/</a>
This will be useful, and definitely handy when sharing random scripts with a defined structure for its requirements. I've struggled to give scripts to non-developers to run recently and between getting them to configure a virtualenv and install dependencies by hand to using `pipx` it's been a pain so hopefully this will alleviate some if it in the future.<p>Not sure, however, that I buy the argument that it's going to be simpler for non-programmers to use TOML embedded inside a multiline string versus using something along the lines of requirements.txt - there's going to be absolutely zero syntax highlighting so things like missing quotes or bracket's will need to be carefully identified.<p>There's also going to be inevitable differences between `__pyproject__` and `pyproject.toml` which could lead to more confusion, such as the `readme` key - that's likely to be useful to include some help information alongside your script so it's self documenting, but in `pyproject.toml` it must refer to another file and in `__pyproject__` I'd assume it can itself be a multiline string..?
Will it be part of the Python distribution (3.12?) or a specification for an independent package? Is there already an implementation, apart from the GitHub repository referenced in the article?
One thing I don't quite get is why the proposal here is so insistent on triple quoted strings only. Shouldn't a \n formatted string also be considered valid? Its practically just a string after all.<p>Other than that, this isn't a bad proposal. Generally for single-file scripts, figuring out the imports isn't too difficult but you do have the occasionally weirdly named pypi package vs installed import package.
It's interesting that they tested for AI code completion compatibility. It makes sense as AI code completion is now a big part of tooling and standards should accomodate for common tools.