SelfStarter: make Julia scripts self-starters

I would like to share a package I wrote a first draft of today called SelfStarter. Essentially, it’s a way to make your script self-contained via a simple macro, @selfstart, and Julia’s standard library package, Pkg. It’s similar to Pluto but focuses on scripts. I look forward to hearing everyone’s thoughts.

3 Likes

It is unclear to me what problem you attempt to solve. Could you elaborate?
If I want to run a julia script, I do julia script.jl (maybe with --project). What is different when using SelfStarter.jl?

4 Likes

Yeah, this is fair. For anything more permanent than SelfStarter’s intended use case, using the --project option is more useful. The idea was to have a script that makes it easier to share scripts; essentially, it is for convenience, where the package shallowly scans the script for what dependencies are needed and creates a provisional package for the script to run in. Ideally, to run the script, all one needs to do is execute julia script.jl.

Does that mean SelfStarter would download and precompile all dependencies?

I’m afraid that would lead to a horrible startup time, or did I misunderstand?

If one doesn’t want to add any runtime argument one can also activate the script specific environment by:

using Pkg; Pkg.activate(@__DIR__)

BR Stefan

1 Like

Does that mean SelfStarter would download and precompile all dependencies?
I’m afraid that would lead to a horrible startup time, or did I misunderstand?

Yes, the current version would be slow (possibly horribly) at first. The package caches the packages as a whole, so subsequent runs should be faster. I was thinking of adding a feature that would allow SelfStarter to consider using globally installed packages as well. If a package is already installed, it would default to the global version—think of plotting packages. I believe this is possible because Julia uses stacked environments.

If one doesn’t want to add any runtime argument, one can also activate the script-specific environment by: using Pkg; Pkg.activate(@DIR).

Very true! I have used this for some Jupyter notebooks. It can definitely be better for the use case where the script is embedded in a project directory. With SelfStarter, a goal is to make it convenient to share a Julia script via a single .jl file.

1 Like

You may find ShareAdd.jl interesting.

1 Like