Developing a standalone application in Julia

Hello,

I’m new to Julia (my experience being mostly in Python), I work in the field of bioinformatics, and I work on Linux systems.

I would like to develop a Julia version of a standalone application for which I already have a Python version. My hope is to obtain something faster to insert into some of my bioinformatics automated pipelines.

So far, I’m more or less managing to do the programming part (I have a .jl script that can take input from the command-line and generates at least part of the output I want).
Where I’m more puzzled is regarding the surrounding development ecosystem and best practice in development workflows.

From what I’ve seen online, Julia usage seems strongly biased towards doing things from the REPL, not writing standalone scripts. I apparently have a quite different approach, so it may be that Julia is not at all the right tool for what I want to do. My practice of REPL (or notebooks like Jupyter) is testing things before using them in re-usable scripts that I can insert into an automated reproducible workflow.

I had a look at 5. Creating Packages · Pkg.jl, but I’m having a hard time finding up-to-date concrete examples on how to do the kind of tasks I have in mind.

I initiated a package in the REPL in pkg mode, using generate, activated the corresponding environment using activate, I added dependencies using add, and this created me a Project.toml file.

But then, how do I go actually building my application? It seems that the dependencies that have been added are only active in the REPL, when the environment is activated. If I try to call Julia to run the script, this only works if I have globally installed the dependencies. Otherwise, I have LoadErrors.

I suppose the solution lies in the content of the deps/build.jl script, but I failed to understand what I should put there. Is it possible to make a standalone executable with all the necessary dependencies somehow “included”?

I also tried to set up documentation using Documenter, creating a docs/make.jl and a docs/src/index.md, and I’m able to build the doc by executing the make.jl script with julia, but only if the required packages are globally installed.

Do you know of standalone applications that have been build using recent Julia versions, where I could look for setup examples?

3 Likes

For the problem of the dependencies, you can use

julia --project=<directory_environment> script.jl

In that way, you will use the dependencies of the environment (is similar to activate from the REPL). If the script is in the same directory, you can put:

julia --project=. script.jl.

Also, you can set the shell variable JULIA_PROJECT

export JULIA_PROJECT=.

to avoid the –project argument calling to julia.

The same thing with running the make.jl for the generation of documentation (considering that Documenter are in the dependences).

3 Likes

Thanks, that’s a useful piece of information.

I can now imagine that one way of doing would be to provide a wrapper script that would take charge of specifying the project directory:

Suppose the actual script is in bin/foo.jl. There would be a bin/foo.sh wrapper containing the following:

#/bin/bash

wrapper=$(readlink -f "${BASH_SOURCE[0]}")
PACKAGEDIR=$( cd "$( dirname "${wrapper}" )/.." && pwd )
wrapper_name=$(basename "${wrapper}")

julia_script="${PACKAGEDIR}/bin/${wrapper_name%.sh}.jl"

/usr/bin/env julia --project=${PACKAGEDIR} ${julia_script} "$@"

The install would then consist in getting the whole package directory, and making a symbolic link to the wrapper, in a directory somewhere in the PATH.

2 Likes