6 ms·
Heck, you can get even cleaner than that by using uv’s support for PEP 723’s inline script dependencies: # /// script # requires-python = ">=3.12" # depe
by riwsky 2y ago
Heck, you can get even cleaner than that by using uv’s support for PEP 723’s inline script dependencies:
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "pandas",
# ]
# ///
h/t https://simonwillison.net/2024/Dec/19/one-shot-python-tools/ https://simonwillison.net/2024/Dec/19/one-shot-python-tools/
- aeurielesn 2y agoI don't understand how things like this get approved into PEPs.
- zanie 2y agoAs in, you think this shouldn't be possible or you think it should be written differently?
- Karupan 2y agoSeems like a great way to write self documenting code which can be optionally used by your python runtime.
- linsomniac 2y agoI don't think this IS a PEP, I believe it is simply something the uv tool supports and as far as Python is concerned it is just a comment.
- mkl 2y agohttps://peps.python.org/pep-0723/ https://peps.python.org/pep-0723/
- linsomniac 2y agoThank you for the pointer, I had searched for it but couldn't find it. (edit: Glad I spent the downvotes to get educated :-)
- zanie 2y agoNo, this is a language standard now (see PEP 723)
- epistasis 2y agoThe PEP page is really good at explaining the status of the proposal, a summary of the discussion to date, and then links to the actual detailed discussion (in Discourse) about it: https://peps.python.org/pep-0723/ https://peps.python.org/pep-0723/
- noitpmeder 2y agoI see this was accepted (I think?); is the implementation available in a released python version? I don't see an "as of" version on the pep page, nor do lite google searches reveal any official python docs of the feature.
- jonesetc 2y agoIt's not a python the language feature, it's for packaging. So no language version is relevant. It's just there for any tool that wants to use it. uv, an IDE, or anything else that manages virtual environments would be the ones who implement it independent of python versions.
- epistasis 2y agoThis is a specification for Python packaging, which is tooling separate from Python releases (for better or worse, IMHO worse but the BDFL disagrees). There's a box below the Table of Contents of the PEP that points here: https://packaging.python.org/en/latest/specifications/inline-script-metadata/ https://packaging.python.org/en/latest/specifications/inline...
- deleted 2y ago[deleted]
- misiek08 2y agoAnd people were laughing at PHP comments configuring framework, right?
- throwup238 2y agoPython was always the late born twin brother of PHP with better hair and teeth, but the same eyes that peered straight into the depths of the abyss.
- franktankbank 2y agoWhy come types?
- throwup238 2y agoThat’s when each language reached sexual maturity but one went on to get a girlfriend and the other discovered internet porn.
- 8n4vidtmkvmk 2y agoI don't know which is which in this story.
- mkl 2y agoPython was first released in 1991, and PHP was first released in 1995.
- blibble 2y agowith that expected use case of uv script run command it effectively makes those comments executable python's wheels are falling off at an ever faster and faster rate
- Spivak 2y agoBecause of a feature that solves the problem of one off scripts being difficult the moment you need a 3rd party library? A more Pythonic way of doing this might be __pyproject__ bit that has the tiiiiny snag of needing to execute the file to figure out its deps. I would have loved if __name__ == "pyproject" but while neat and tidy it is admittedly super confusing for beginners, has a "react hooks" style gotcha where to can't use any deps in that block, and you can't use top level imports. The comment was really the easiest way.
- rtpg 2y agoIt's helpful as a way to publish minimal reproductions of bugs and issues in bug reports (compared to "please clone my repo" which has so many layers of friction involved). I would want distributed projects to do things properly, but as a way to shorthand a lot of futzing about? It's excellent
- epistasis 2y agoAnd for the Jupyter setting, check out Trevor Manz's juv: https://github.com/manzt/juv https://github.com/manzt/juv
- shlomo_z 2y agoIs it possible for my IDE (vscode) to support this? Currently my IDE screams at me for using unknown packages and I have no type hinting, intellisense, etc.
- deleted 2y ago[deleted]
- Zizizizz 2y agoWith your python plugin you should be able choose .venv/bin/python as your interpreter after you've run `uv sync` and everything should resolve
- randomlurking 2y agoSo it doesnt work wirk adhoc venvs, does it? Might still valuable for simply running scripts, but I’m not sure venv-less works for dev
- shlomo_z 2y agoBut if I am using inline metadata to declare the dependencies, uv doesn't tell me where the venv is. And there is no `uv sync` command for single scripts as far as I can tell.
- __MatrixMan__ 2y agoSo it's like a shebang for dependencies. Cool.
- sbene970 2y agoI've started a repo with some of these scripts, the most recent one being my favorite: a wrapper for Microsoft AutoGen's very recent Magentic-1, a generalist LLM-Multi-Agent-System. It can use the python code, the CLI, a browser (Playwright) and the file system to complete tasks. A simple example a came across is having to rename some files: 1. you just open the shell in the location you want 2. and run this command: uv run https://raw.githubusercontent.com/SimonB97/MOS/main/AITaskRunner/m1.py https://raw.githubusercontent.com/SimonB97/MOS/main/AITaskRu... "check the contents of the .md files in the working dir and structure them in folders" There's a link to Magentic-1 docs and further info in the repo: https://github.com/SimonB97/MOS/tree/main/AITaskRunner https://github.com/SimonB97/MOS/tree/main/AITaskRunner (plus two other simple scripts).