This document provides step-by-step instructions for creating and maintaining Spack packages.
- Access to the spack-repo workspace
- Have access to a VM built using softpack-vm-setup
First, verify if a recipe already exists in the packages/
directory:
- For Python packages: look for
py-{package_name}
- For R packages: look for
r-{package_name}
- For other packages: look for
{package_name}
Action: Browse the packages/
directory or use search tools to locate existing recipes.
If the recipe exists but you need a specific version:
# Get available versions
spack versions {package_name}
# Get SHA256 checksum for new version
spack checksum -b {package_name}
Action: Modify the existing recipe to add the new version with its corresponding SHA256 checksum.
If the package request includes a URL (e.g., GitHub repository, documentation site):
- Visit and thoroughly review the URL content
- Take notes on important information such as:
- Build requirements and dependencies
- Installation instructions
- Available versions and releases
- Licence information
- Import/usage examples
- This information will help guide your recipe creation decisions
For Python packages, attempt to use the internal PyPackageCreator tool:
cd ~/r-spack-recipe-builder
./PyPackageCreator.py -f {package_name}
If successful, copy the generated recipe:
del_empty
mv ~/r-spack-recipe-builder/packages/py-* ~/spack-repo/packages
If PyPI fails or for non-Python packages:
create {py-/r-}{package_name}
What the create
function does:
The create
command is a custom function defined in .zshrc
that automates the process of checking for and copying recipes from the official Spack repository. It performs the following steps:
- Creates a temporary recipe: Runs
spack create --skip-editor {package_name}
to generate a basic recipe - Updates official repository: Navigates to
~/work/spack-packages
and runsgit pull
to get the latest official Spack recipes - Copies existing recipe: If the package exists in the official repository, copies
package.py
and any.patch
files from~/work/spack-packages/repos/spack_repo/builtin/packages/
to your local~/spack-repo/packages/
directory - Cleans up the recipe: Automatically performs several cleanup operations:
- Comments out generic build dependencies (
c
,cxx
,fortran
) - Removes
checked_by
parameters from licence declarations - Removes imports from
spack_repo.builtin
- Comments out generic build dependencies (
Note: Use appropriate prefix (py-
for Python, r-
for R packages)
If the package doesn't exist in official repositories:
- Navigate to the package's GitHub page
- Check
{url}/releases
or{url}/tags
for available versions - Get the source archive URL (typically
.tar.gz
format) - Create recipe:
spack create --skip-editor -b {archive_url}
Example URL format: https://github.com/theislab/scarches/archive/refs/tags/v0.5.1.tar.gz
- Clone the repository to a scratch location
- Get the latest commit SHA
- Add version using commit date format:
version("20250411", commit="82a307f19fb8188373fdd6838be92d457bf65e06")
- Reference Examples: Use examples in the
examples/
folder to guide you through the structure:py-agate
for Python packagesr-archr
andr-plotlistr
for R packagessamtools
for other packages
- Add docstring and homepage
- Add Build Requirements: Include all dependencies found in the package documentation in the recipe's
depends_on()
statements. Set all optional dependencies toTrue
(avoid using variants) - Configure Installation Process: Adapt the package's installation instructions into appropriate build phases and methods in the recipe
- Specify Available Versions: Add all relevant versions and releases with their corresponding checksums to the recipe
- Include Licence Information: Add the correct licence declaration based on the package's licence information
Install the package using Spack:
spack install {package_name}
Error Handling: If build errors occur:
- Read the error logs carefully
- Fix the recipe based on the error messages
- Reinstall until successful
Validate the installation using Singularity:
singularity exec --bind /mnt/data /home/ubuntu/spack.sif bash -c "source <(/opt/spack/bin/spack load --sh {package_name}); {validation_script}"
R Packages:
Rscript -e \"library({package_name})\"
Python Packages:
python -c \"import {package_name}\"
Note: Check PyPI page or package homepage for correct import syntax as it may differ from package name.
Other Packages: Consult the package documentation/webpage for appropriate validation commands.
If validation fails:
- Uninstall the package and dependencies:
spack uninstall -y --all --dependents {package_name}
- Fix the recipe based on error messages
- Reinstall and revalidate
- Repeat until successful
Once validation succeeds:
- Generate an appropriate commit message (keep it concise - max 2 sentences)
- Create a branch (don't push to main directly)
- Commit changes to git
- Push to repository
- Create a Pull Request on Github
- A Github Action is set up to validate the recipe automatically. Once the validation passed, the pull request can be merged)
- Always read package documentation before creating recipes
- Test thoroughly in the validation step
- Keep commit messages short and descriptive
- Follow existing recipe patterns in the
examples/
folder - Document any special scenarios and how you resolved them in the troubleshooting.md
- Official Spack documentation
- PyPI (for Python packages)
- CRAN (for R packages)
- Bioconductor (for R packages)
- Package homepages and documentation