From 7668d4c626e0f413ee5bc0aca255d100973f930e Mon Sep 17 00:00:00 2001 From: Philip Cook Date: Wed, 13 Mar 2024 15:14:04 -0400 Subject: [PATCH 1/7] WIP: Faster tests --- .github/workflows/ci-pytest.yml | 76 +++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 .github/workflows/ci-pytest.yml diff --git a/.github/workflows/ci-pytest.yml b/.github/workflows/ci-pytest.yml new file mode 100644 index 00000000..33e81cdc --- /dev/null +++ b/.github/workflows/ci-pytest.yml @@ -0,0 +1,76 @@ +name: ci-pytest + +on: pull_request + +env: + # Changing either of these two things will invalidate the cache and cause a full re-install + # of ANTsPy and its dependencies + # Update this hash whenever there is a change that affects ANTsPy libraries or dependencies + # Updates or changes to the runner OS or arch will also invalidate the cache + antspy_ref_hash: 'ff7413a5e7685b94ad7fc9a9b2553656f3bd005e' + python_version: '3.9' # Python version to use for testing - update when needed + +jobs: + test: + runs-on: ubuntu-22.04 + + steps: + - name: Setup Miniconda + uses: conda-incubator/setup-miniconda@v3 + with: + auto-update-conda: true + python-version: ${{ env.python_version }} + activate-environment: antspy-env + + - name: Cache Conda environment + id: cache-env + uses: actions/cache@v4 + with: + path: ~/conda-env.tar.gz + key: ${{ runner.os }}-${{ runner.arch }}-conda-${{ env.python_version }}-${{ env.antspy_ref_hash }} + + - name: Unpack cached environment + if: steps.cache-env.outputs.cache-hit == 'true' + run: | + tar -xzf ~/conda-env.tar.gz -C ${CONDA}/envs/antspy-env + + - name: Checkout ANTsPy at specific commit + if: steps.cache-env.outputs.cache-hit != 'true' + uses: actions/checkout@v4 + with: + repository: ANTsX/ANTsPy + ref: ${{ env.antspy_ref_hash }} + token: ${{ secrets.GITHUB_TOKEN }} + path: antspy-temp + + - name: Install dependencies and ANTsPy from commit + if: steps.cache-env.outputs.cache-hit != 'true' + run: | + conda install -c conda-forge conda-pack + source $CONDA/etc/profile.d/conda.sh + conda activate antspy-env + pip install ./antspy-temp + # Pack the environment + conda-pack -n antspy-env -o ~/conda-env.tar.gz + + - name: Cache Conda environment + if: steps.cache-env.outputs.cache-hit != 'true' + uses: actions/cache@v4 + with: + path: ~/conda-env.tar.gz + key: ${{ runner.os }}-${{ runner.arch }}-conda-${{ env.python_version }}-${{ env.antspy_ref_hash }} + + - uses: actions/checkout@v4 # Checkout PR code to 'antspy-pr' + with: + path: antspy-pr + + - name: Replace installed ANTsPy with PR code + run: | + rm -rf $ANTS_SITE_PACKAGES/ants + cp -r antspy-pr/ants/ $ANTS_SITE_PACKAGES/ants + + - name: Run tests + run: | + source $CONDA/etc/profile.d/conda.sh + conda activate antspy-env + bash antspy-pr/tests/run_tests.sh From 1b1992a3f6149aea054ba037ac83533d3fe754e2 Mon Sep 17 00:00:00 2001 From: Philip Cook Date: Wed, 13 Mar 2024 16:29:29 -0400 Subject: [PATCH 2/7] BUG: keep track of conda env --- .github/workflows/ci-pytest.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-pytest.yml b/.github/workflows/ci-pytest.yml index 33e81cdc..5ff1fb42 100644 --- a/.github/workflows/ci-pytest.yml +++ b/.github/workflows/ci-pytest.yml @@ -22,7 +22,7 @@ jobs: python-version: ${{ env.python_version }} activate-environment: antspy-env - - name: Cache Conda environment + - name: Load conda environment from cache if available id: cache-env uses: actions/cache@v4 with: @@ -46,11 +46,13 @@ jobs: - name: Install dependencies and ANTsPy from commit if: steps.cache-env.outputs.cache-hit != 'true' run: | - conda install -c conda-forge conda-pack source $CONDA/etc/profile.d/conda.sh + conda install -c conda-forge conda-pack + conda create -n antspy-env python=${{ env.python_version }} -y conda activate antspy-env pip install ./antspy-temp # Pack the environment + conda deactivate conda-pack -n antspy-env -o ~/conda-env.tar.gz - name: Cache Conda environment From 673f1fc36ffa23f600e4b2fe60556a5a45ffeb96 Mon Sep 17 00:00:00 2001 From: Philip Cook Date: Wed, 13 Mar 2024 16:36:22 -0400 Subject: [PATCH 3/7] BUG: Fix path to ants in conda env --- .github/workflows/ci-pytest.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-pytest.yml b/.github/workflows/ci-pytest.yml index 5ff1fb42..61d41b30 100644 --- a/.github/workflows/ci-pytest.yml +++ b/.github/workflows/ci-pytest.yml @@ -68,8 +68,9 @@ jobs: - name: Replace installed ANTsPy with PR code run: | + ANTS_SITE_PACKAGES=$(python -c "import os, ants; print(os.path.dirname(ants.__file__))") rm -rf $ANTS_SITE_PACKAGES/ants - cp -r antspy-pr/ants/ $ANTS_SITE_PACKAGES/ants + cp -r antspy-pr/ants $ANTS_SITE_PACKAGES/ants - name: Run tests run: | From 5ea82b5e8caba9106a960a4be7a7e7b8754e5b5f Mon Sep 17 00:00:00 2001 From: Philip Cook Date: Thu, 14 Mar 2024 09:16:03 -0400 Subject: [PATCH 4/7] BUG: conda pack --- .github/workflows/ci-pytest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-pytest.yml b/.github/workflows/ci-pytest.yml index 61d41b30..b7e64807 100644 --- a/.github/workflows/ci-pytest.yml +++ b/.github/workflows/ci-pytest.yml @@ -53,7 +53,7 @@ jobs: pip install ./antspy-temp # Pack the environment conda deactivate - conda-pack -n antspy-env -o ~/conda-env.tar.gz + conda pack -n antspy-env -o ~/conda-env.tar.gz - name: Cache Conda environment if: steps.cache-env.outputs.cache-hit != 'true' From 97356cd84f09d6cfa2cc147d5efd613f84e40b9e Mon Sep 17 00:00:00 2001 From: Philip Cook Date: Thu, 14 Mar 2024 10:14:53 -0400 Subject: [PATCH 5/7] BUG: conda activate --- .github/workflows/ci-pytest.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci-pytest.yml b/.github/workflows/ci-pytest.yml index b7e64807..de3c57ce 100644 --- a/.github/workflows/ci-pytest.yml +++ b/.github/workflows/ci-pytest.yml @@ -68,6 +68,8 @@ jobs: - name: Replace installed ANTsPy with PR code run: | + source $CONDA/etc/profile.d/conda.sh + conda activate antspy-env ANTS_SITE_PACKAGES=$(python -c "import os, ants; print(os.path.dirname(ants.__file__))") rm -rf $ANTS_SITE_PACKAGES/ants cp -r antspy-pr/ants $ANTS_SITE_PACKAGES/ants From 1e10dc879437dfb74e2adc1468a4d918060d648c Mon Sep 17 00:00:00 2001 From: Philip Cook Date: Thu, 14 Mar 2024 10:21:46 -0400 Subject: [PATCH 6/7] ENH: Hash files to track when cache should miss --- .github/workflows/ci-pytest.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-pytest.yml b/.github/workflows/ci-pytest.yml index de3c57ce..3f4c0fd8 100644 --- a/.github/workflows/ci-pytest.yml +++ b/.github/workflows/ci-pytest.yml @@ -7,7 +7,6 @@ env: # of ANTsPy and its dependencies # Update this hash whenever there is a change that affects ANTsPy libraries or dependencies # Updates or changes to the runner OS or arch will also invalidate the cache - antspy_ref_hash: 'ff7413a5e7685b94ad7fc9a9b2553656f3bd005e' python_version: '3.9' # Python version to use for testing - update when needed jobs: @@ -27,7 +26,10 @@ jobs: uses: actions/cache@v4 with: path: ~/conda-env.tar.gz - key: ${{ runner.os }}-${{ runner.arch }}-conda-${{ env.python_version }}-${{ env.antspy_ref_hash }} + key: >- + ${{ runner.os }}-conda-${{ env.python_version }}- + ${{ hashFiles('environment.yml', 'requirements.txt', 'setup.py', + 'scripts/configure_ITK.sh', 'scripts/configure_ANTsPy.sh') }} - name: Unpack cached environment if: steps.cache-env.outputs.cache-hit == 'true' @@ -60,7 +62,10 @@ jobs: uses: actions/cache@v4 with: path: ~/conda-env.tar.gz - key: ${{ runner.os }}-${{ runner.arch }}-conda-${{ env.python_version }}-${{ env.antspy_ref_hash }} + key: >- + ${{ runner.os }}-conda-${{ env.python_version }}- + ${{ hashFiles('environment.yml', 'requirements.txt', 'setup.py', + 'scripts/configure_ITK.sh', 'scripts/configure_ANTsPy.sh') }} - uses: actions/checkout@v4 # Checkout PR code to 'antspy-pr' with: From 63b760fb3d4f74d2fffaa750b51f9d6826f37a38 Mon Sep 17 00:00:00 2001 From: Philip Cook Date: Thu, 14 Mar 2024 10:22:24 -0400 Subject: [PATCH 7/7] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e7907287..6e383a96 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # Advanced Normalization Tools in Python +Hashin' [![Coverage Status](https://coveralls.io/repos/github/ANTsX/ANTsPy/badge.svg?branch=master)](https://coveralls.io/github/ANTsX/ANTsPy?branch=master)