Skip to content

Commit

Permalink
Merge pull request #687 from wkharold/apptainer
Browse files Browse the repository at this point in the history
Apptainer definition file for PySR
  • Loading branch information
MilesCranmer authored Aug 12, 2024
2 parents 14401b0 + 9ca474a commit f363946
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/CI_apptainer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Apptainer

on:
push:
branches:
- 'master'
paths:
- '**'
tags:
- 'v*.*.*'
pull_request:
branches:
- 'master'
paths:
- '**'

jobs:
test:
runs-on: ${{ matrix.os }}
timeout-minutes: 60
defaults:
run:
shell: bash
strategy:
matrix:
os: [ubuntu-latest]

steps:
- uses: actions/checkout@v4
- uses: eWaterCycle/setup-apptainer@v2
with:
apptainer-version: 1.3.0
- name: Build apptainer
run: apptainer build --notest pysr.sif Apptainer.def
- name: Test apptainer
run: |
TMPDIR=$(mktemp -d)
cp pysr.sif $TMPDIR
cd $TMPDIR
apptainer test ./pysr.sif
55 changes: 55 additions & 0 deletions Apptainer.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Build an Apptainer SIF file containing a working copy of PySR and its prereqs
Bootstrap: docker
From: julia:1.10.4-bullseye
Stage: jl

Bootstrap: docker
From: python:3.12-bullseye
Stage: runtime

%environment
# Use the container Julia binary
export PATH="/usr/local/julia/bin:$PATH"

# Create a stacked environment for additional Julia packages
export JULIA_DEPOT_PATH="$HOME/.pysr:/pysr/depot:$JULIA_DEPOT_PATH"
export JULIA_LOAD_PATH="$HOME/.pysr:/pysr:$JULIA_LOAD_PATH"

%files from jl
/usr/local/julia /usr/local/julia

%files
./requirements.txt /pysr/requirements.txt
./pyproject.toml /pysr/pyproject.toml
./setup.py /pysr/setup.py
./pysr /pysr/pysr

%post
# Ensure we don't use the local pysr commands:
cd $(mktemp -d)

export PATH="/usr/local/julia/bin:$PATH"

# Install IPython and other useful libraries:
pip3 install --no-cache-dir ipython matplotlib pytest nbval
# Install PySR and requirements:
pip3 install --no-cache-dir /pysr

# Put the Julia dependencies in /pysr/depot
mkdir /pysr/depot
export JULIA_DEPOT_PATH="/pysr/depot"

# And set a specific environment for Julia dependencies
mkdir /pysr/env
export PYTHON_JULIAPKG_PROJECT="/pysr/env"

# Pull in all the Julia dependencies
python3 -c 'import pysr; pysr.load_all_packages()'

%test
python3 -m pysr test main,cli,startup

%runscript
# Start ipython when the container is executed
[ ! -d $HOME/.pysr ] && mkdir $HOME/.pysr
PYTHONPATH=/pysr ipython
2 changes: 2 additions & 0 deletions pysr/test/test_startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ def test_notebook(self):
self.skipTest("Julia version too old")
if platform.system() == "Windows":
self.skipTest("Notebook test incompatible with Windows")
if not os.access(Path(__file__).parent, os.W_OK):
self.skipTest("Read-only file system")

notebook_file = Path(__file__).parent / "test_nb.ipynb"
sanitize_file = Path(__file__).parent / "nb_sanitize.cfg"
Expand Down

0 comments on commit f363946

Please sign in to comment.