I am interested to know if there is a Julia equivalent to the following in Python. Imagine you have a collection of scripts each with their own dependencies. In each script it is possible to declare metadata about the script:
# /// script
# 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])
I can then run uv run example.py which spin up a temporary environment to run the script. Is there a way to do something similar in Julia?
Thanks!
Yes, you can just add Pkg commands at the top of your script:
using Pkg
Pkg.activate(temp=true) # maybe point this to a more permanent project location
Pkg.add("Requests") # these are not Julia packages ...
Pkg.add("Rich") # ... but you get the point.
The point to remember is that this in Julia is implemented using packages rather than scripts.
You can specify which packages version ranges work for yr project and exactly which versions (recursively) you are actually using…
I do think it would be a nice feature to be able to include a manifest into a Julia script so that it’s self-contained. We haven’t designed or implemented that, however. As mentioned, Pluto has this functionality.