Downloading package source code without using its git repo

Is there a way to download the source code of a package (given a version or its SHA) directly, without using the package repo?
(I could do a git clone and checkout, but if there is a way to get just the source code directly, without additional git metadata, that would be better for my purpose.)

1 Like

Something like this?

You want to download a snapshot then. If you go to the repository page you can find a big green button above the list of files, from there you can download the snapshot, as zip or tar.gz. In the default view of the repository that’d be a snapshot from the tip of the default branch, if you visit a different branch you get the link to download the snapshot of that other branch, the same for a revision or tag page. Snapshots for tags can also be downloaded from the list of tags/releases of the repository

Or, of you’re comfortable with the command line, git clone --depth=1 <url>

1 Like

I was hoping that Pkg.jl would already have such functionality somewhere. I couldn’t find that in the docs or by brief skimming of the Pkg source code.

I need to get sources of various Julia packages for analysis, so I am looking for a programmable way of downloading package sources for the given package version.

As some packages are hosted on GitLab, I would need to support (and probably maintain) different patterns for GitHub and GitLab to download snapshots. It’s doable but I’d rather use more disk space and rely on clone/checkout rather than bother with snapshotting from different sources.

And it feels like this task must already be solved in Pkg.jl for package installation…

If you have the package UUID and the tree hash of a version you can download a snapshot tarball at$uuid/$tree

Not very human friendly but this is how the package manager gets packages and I suspect that you may be doing scripted analysis of source code. This also has the advantage of being perfectly cacheable if you’re maintaining a collection of source trees for analysis.


Oh great, thanks!

1 Like