`jlpkg` -- a command line interface to Pkg

Hello everyone!

I’d like to announce jlpkg, a command line interface (CLI) to Julia’s package manager Pkg. jlpkg is essentially a wrapper around the Pkg REPL mode so all of you are probably familiar with the commands already.

How do I install the CLI?

Installation is as easy as

pkg> add jlpkg

julia> import jlpkg; jlpkg.install()

This will place an executable in ~/.julia/bin by default, so make sure that is on your PATH, or alternatively, symlink to it from a folder that is in your PATH. The installation is fairly customizable via keyword arguments, so make sure to check out the docstring for the jlpkg.install function.

How do I use the CLI?

Once the installation is done you can start using it. Available commmands can be listed with jlpkg --help. For example, add the Literate package:

$ jlpkg add Literate

show the project status

$ jlpkg st

test a package

$ jpkg test Example

add Documenter to your docs project

$ jlpkg --project=docs add Documenter

etc.

Why should I use the CLI instead of the Pkg REPL mode?

The Pkg REPL mode is great, I use it all the time, but sometimes it is just quicker to grab another tool from the toolbox. If you just need to run some quick Pkg commands it can be much quicker to call jlpkg cmd instead of (i) start julia (ii) enter the Pkg REPL (iii) enter cmd.

Since jlpkg is run from the shell you can utilize other cool things, like redirecting output to /dev/null:

$ jlpkg add Literate > /dev/null

or filter status output with grep

$ jlpkg st | grep Ex
  [7876af07] Example v0.5.1

etc.

It is also worth noting that, by default, the CLI runs in interpreted julia mode (--compile=min), which for this case turns out to be much faster. Compare for example the following script time.sh:

#!/bin/sh
jlpkg add Example DataFrames JSON StaticArrays
jlpkg rm Example DataFrames JSON StaticArrays
jlpkg dev Literate
jlpkg rm Literate

with default julia settings you get:

$ time ./time.sh > /dev/null
real    0m5.051s
user    0m4.896s
sys     0m0.667s

and with --compile=min you get:

$ time ./time.sh > /dev/null
real    0m1.033s
user    0m1.073s
sys     0m0.636s

which is almost 5 times faster. So if all you want to do is to check the status of your project, jlpkg st is much faster compared to julia -e 'using Pkg; Pkg.status()', or (i) open julia, (ii) enter the repl mode, (iii) run the command, (iv) exit julia.

I hope that some of you might find this tool useful and want to try it out. Please get back to me with any feedback, comments or issues, either here or on the GitHub repository. Happy package managing!

53 Likes

Quick update with things that has been added since the initial release

Bash completion

The only thing that I have found annoying when using jlpkg compared to the real Pkg REPL is tab-completion. jlpkg now provides Bash completion. It completes the CLI switches, the Pkg REPL commands (including options), and also some more fancy things. Here are some examples:

After the project flag, the completion filters out any paths that is not a directory or a toml file:

$ ls
A  file.jl  Project.toml

$ jlpkg --project=<TAB>
A/            Project.toml

The add command completes packages found in installed registries:

$ jlpkg add Exa<TAB>
ExactDiagonalization  ExactPredicates       ExactReals            ExactWrightFisher     Example

Any command that acts on packages in the current project completes only those, in project/manifest mode as appropriate:

$ pkg status <TAB>
Example  JSON     

$ pkg status --manifest <TAB>
Dates    Example  JSON     Mmap     Parsers  Printf   Unicode

The completion has been written with compatibility with Bash 3 in mind, to properly function on macOs too.

Alternative installation methods

See the README, in addition to installing from Julia you there are now two additional methods:

  1. Tarball download: You can now download jlpkg from GitHub releases and unpack in some folder on PATH. With this methods you don’t have to start Julia nor add the jlpkg Julia package:

    $ curl -fsSL https://github.com/fredrikekre/jlpkg/releases/download/v1.3.2/jlpkg-v1.3.2.tar.gz | \
      tar -xzC ~/bin
    
  2. asdf package manager: You can install and update jlpkg using the asdf version manager using the asdf-jlpkg plugin. See the plugin README for details. This is probably mostly useful if you use asdf for other things, for example for managing Julia version.

New CLI options

There are some nice new CLI options:

  • The --julia flag can be used for specifying the Julia binary. This is sometimes useful if you want to repeat something for multiple Julia versions, for example:

    $ for julia in julia10 julia11 julia12 julia13 julia14 julia15; do
        jlpkg --julia=$julia test Example
    done
    
  • The --offline flag can be used to enable Pkg’s offline mode.

13 Likes