Debugging a Bioconda build - a reference guide
In the third part of this three part guide, we will go through an (opinionated) approach to debug a Bioconda recipe or build.
- For part one of this guide, see adding a new tool or package to Bioconda.
- For part two of this guide, see updating a package on Bioconda.
The conda package manager combined with the Bioconda repository has become a de facto gold-standard way for distributing bioinformatics software (Grüning et al. 2018). The associated Biocontainer project serves to provide complementary Docker and Singularity containers from the same conda (da Veiga Leprevost et al. 2017).
During the recipe creation (see part one) or updating process (see part two), we may encounter problems or issues.
This guide provides steps how to test both a standard conda-build
build, but also a bioconda-utils
process that occurs within a Docker container.
Debugging the build with conda-build
If we have issues with the build process when using conda-build
., we can try to debug it in the following ways.
-
Read carefully the very long log that gets generated from bottom to top. While tedious, often we can find the issue there, such as if the
test
command didn’t work correctly. -
Inspect the resulting environment itself.
We can do this by changing into the
conda-bld/
directory of our Bioconda build conda environment (called herebioconda-bld/
).Then we can try installing the environment but specifying that the conda channel to take the software from is the directory we’re in with
-c ./
(if we miss this, we’ll install existing versions of the tool if they exist, or have an error that conda can’t find the tool):cd /<path>/<to>/<conda-install>/envs/<toolname>/conda-bld/linux-64 conda create -n <debugging-env-name> -c ./ <toolname_as_in_recipe>
-
Run the build process again but keeping all work directories, and investigate these (if the error message refers to one of those directories):
conda build recipes/<toolname> --keep-old-work
Debugging the build with bioconda-utils
If build with the bioconda-utils
command, and this fails (and we’ve used the --docker
command), and the error isn’t obvious, we can deep dive into the Docker container that was created by the build process (i.e. recreating the ‘exact’ environment Bioconda itself will use), and follow the exact steps the build process goes through:
-
The error will produce a
COMMAND FAILED
message with a Docker command. It will look something like:docker run -t --net host --rm -v /tmp/tmp<randomletters>/build_script.bash:/opt/build_script.bash -v /<path>/<to>/<conda-install>/envs/<toolname>/conda-bld/:/opt/host-conda-bld -v /<path>/<to>/<recipes_local_clone>/recipes/<tool_name>:/opt/recipe -e LC_ADDRESS=en_GB.UTF-8 -e LC_NAME=en_GB.UTF-8 -e LC_MONETARY=en_GB.UTF-8 -e LC_PAPER=en_GB.UTF-8 -e LANG=en_GB.UTF-8 -e LC_IDENTIFICATION=en_GB.UTF-8 -e LC_TELEPHONE=en_GB.UTF-8 -e LC_MEASUREMENT=en_GB.UTF-8 -e LC_TIME=en_GB.UTF-8 -e LC_NUMERIC=en_GB.UTF-8 -e HOST_USER_ID=1000 quay.io/bioconda/bioconda-utils-build-env-cos7:2.11.1 bash
-
Copy and paste that command, but replace
docker run -t
todocker run -it
. This will open an ‘interactive’ session so we can play around within the container.⚠ Basic tools such as
vim
are not in there! So depending on our preference, we will have to exit the Docker container to edit ourmeta.yaml
orbuild.sh
file each time, and re-run the command/ 3. Once in, there are two main locations of interest:/opt/recipe
: contains our entire recipe directory (e.g. withmeta.yaml
andbuild.sh
)./opt/build_script.sh
: the commands that Bioconda actually run during the build process.
- To carry out the manual debugging,
cat build_script.sh
and run one-by-one each command in that file. Alternatively, copy and paste the entire contents, but DO NOT run theset -eo pipefile
command at the top (this will exit the Docker container if something goes wrong). -
The first command I found commonly resulted in errors is:
conda mambabuild -c file:///opt/host-conda-bld --override-channels --no-anaconda-upload -c conda-forge -c bioconda -c defaults -e /opt/host-conda-bld/conda_build_config_0_-e_conda_build_config.yaml -e /opt/host-conda-bld/conda_build_config_1_-e_bioconda_utils-conda_build_config.yaml /opt/recipe/meta.yaml 2>&1
This is the primary command that runs the entire building of the recipe.
-
If step 6 fails during the
build.sh
steps (as indicated by the console log), we will want to manually execute thebuild.sh
script. Before we do this, we must make sure to activate the build environment (the one within which we would e.g. compile ac++
tool):conda activate /opt/conda/conda-bld/<packagename_hash>/_build_env
When running the commands in the
build.sh
, we may also need to manuallyexport
thePREFIX
bash environment variable when dealing withbuild.sh
. To find this, look for the long horrible_test_env_placehold_placehold_placehold_placehold_p<...>
directory that gets reported in the log during our initial building run. -
To check the actual build output files, i.e., the working directory that
build.sh
is executed in:/opt/conda/conda-bld/<tool/package-name>_<random-numbers>/work
It’s still not working!
If none of this solves your issue, we can ask for help from the Bioconda community by opening a Pull Request and leaving a comment pinging /<team> (replacing ‘<team>’ with the respective one from the list that should come up).
Once everything is solved, you can proceed with the last three sections in the part one of this guide, to open the Pull Request and get a review.
Conclusion
In this third and final part of this guide, we given you enough pointers on how debug a Bioconda recipe build both using conda-build
and bioconda-utils
approaches.
As with all bioinformatics and software development in general, things rarely just ‘work’ straight out of the box. My three biggest points of advice:
- Always copy and paste from other similar tools or packages on the Bioconda recipes repository.
- Take the time to read through the whole log messages (sometimes you can find critical clues hidden amongst the verbose information).
- Take the time to go step by step trying to follow exactly what Bioconda is doing within
bioconda-utils
.
I found by taking the time, I very quickly learnt common issues and how to solve them.
Worst comes to worst, you can always ask the very friendly Bioconda team on the Bioconda gitter/matrix channel.
References
- Veiga Leprevost, F. da, B. A. Grüning, S. Alves Aflitos, H. L. Röst, J. Uszkoreit et al., 2017 BioContainers: an open-source and community-driven framework for software standardization. Bioinformatics (Oxford, England) 33: 2580–2582. 10.1093/bioinformatics/btx192 https://academic.oup.com/bioinformatics/article-pdf/33/16/2580/49041124/bioinformatics_33_16_2580.pdf
- Grüning, B., R. Dale, A. Sjödin, B. A. Chapman, J. Rowe et al., 2018 Bioconda: sustainable and comprehensive software distribution for the life sciences. Nature Methods 15: 475–476. 10.1038/s41592-018-0046-7
Citing this Post
@misc{debugging-bioconda-build-quickguide,
author = "",
title = "Debugging a Bioconda build - a reference guide",
year = "2024",
month = "08",
day = "16",
url = "https://ubinfie.github.io/2024/08/16/debugging-bioconda-build-quickguide.html",
note = "[Online; accessed TODAY]"
}
Comments