Skip to content

Commit

Permalink
Merge branch 'main' into MSEDataConsistency
Browse files Browse the repository at this point in the history
  • Loading branch information
rkcatarina authored Nov 13, 2024
2 parents 7603375 + 798f1e2 commit 57c3193
Show file tree
Hide file tree
Showing 120 changed files with 5,538 additions and 965 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.github
.vscode
binder
examples
docs
tests
59 changes: 39 additions & 20 deletions .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Publish to PyPI
name: Build and Deploy Package

on:
push:
Expand All @@ -7,21 +7,31 @@ on:

jobs:
build-testpypi-package:
name: Modify version and build package for TestPyPI
name: Build Package for TestPyPI
runs-on: ubuntu-latest
outputs:
version: ${{ steps.set_suffix.outputs.version }}
suffix: ${{ steps.set_suffix.outputs.suffix }}
version_changed: ${{ steps.changes.outputs.version_changed }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"

- name: Set environment variable for version suffix
- name: Checkout Code
uses: actions/checkout@v4

- name: Check if VERSION file is modified compared to main
uses: dorny/paths-filter@v3
id: changes
with:
base: main
filters: |
version_changed:
- 'src/mrpro/VERSION'
- name: Set Version Suffix
id: set_suffix
run: |
VERSION=$(cat src/mrpro/VERSION)
Expand All @@ -30,12 +40,12 @@ jobs:
echo "suffix=$SUFFIX" >> $GITHUB_OUTPUT
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Build package with version suffix
- name: Build Package
run: |
python -m pip install --upgrade build
python -m build
- name: Store TestPyPi distribution
- name: Upload TestPyPI Distribution Artifact
uses: actions/upload-artifact@v4
with:
name: testpypi-package-distribution
Expand All @@ -46,6 +56,7 @@ jobs:
needs:
- build-testpypi-package
runs-on: ubuntu-latest
if: needs.build-testpypi-package.outputs.version_changed == 'true'

environment:
name: testpypi
Expand All @@ -55,7 +66,7 @@ jobs:
id-token: write

steps:
- name: Download TestPyPi distribution
- name: Download TestPyPI Distribution
uses: actions/download-artifact@v4
with:
name: testpypi-package-distribution
Expand All @@ -68,7 +79,7 @@ jobs:
verbose: true

test-install-from-testpypi:
name: Test installation from TestPyPI
name: Test Installation from TestPyPI
needs:
- testpypi-deployment
- build-testpypi-package
Expand All @@ -83,40 +94,48 @@ jobs:
run: |
VERSION=${{ needs.build-testpypi-package.outputs.version }}
SUFFIX=${{ needs.build-testpypi-package.outputs.suffix }}
python -m pip install mrpro==$VERSION$SUFFIX --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/
for i in {1..3}; do
if python -m pip install mrpro==$VERSION$SUFFIX --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/; then
echo "Package installed successfully."
break
else
echo "Attempt $i failed. Retrying in 10 seconds..."
sleep 10
fi
done
build-pypi-package:
name: Build package for PyPI
name: Build Package for PyPI
runs-on: ubuntu-latest
needs:
- test-install-from-testpypi
outputs:
version: ${{ steps.get_version.outputs.version }}
steps:
- name: Checkout code
- name: Checkout Code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"

- name: Install setuptools_git_versioning
- name: Install Automatic Versioning Tool
run: |
python -m pip install setuptools-git-versioning
- name: Get current version
- name: Get Current Version
id: get_version
run: |
VERSION=$(python -m setuptools_git_versioning)
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
- name: Build package
- name: Build Package
run: |
python -m pip install --upgrade build
python -m build
- name: Store PyPi distribution
- name: Store PyPI Distribution
uses: actions/upload-artifact@v4
with:
name: pypi-package-distribution
Expand All @@ -138,13 +157,13 @@ jobs:
id-token: write

steps:
- name: Download PyPi distribution
- name: Download PyPI Distribution
uses: actions/download-artifact@v4
with:
name: pypi-package-distribution
path: dist/

- name: Create tag
- name: Create Tag
uses: actions/github-script@v7
with:
script: |
Expand All @@ -155,7 +174,7 @@ jobs:
sha: context.sha
})
- name: Create release
- name: Create Release
uses: actions/github-script@v7
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ jobs:
permissions:
packages: write
strategy:
fail-fast: false
matrix:
dockerfile: ${{ fromJson(needs.get_dockerfiles.outputs.dockerfiles) }}
steps:
Expand All @@ -87,7 +88,9 @@ jobs:
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: ./docker
context: .
cache-from: type=gha,scope=${{ matrix.dockerfile }}
cache-to: type=gha,mode=max,scope=${{ matrix.dockerfile }}
file: ./docker/${{ matrix.dockerfile }}
push: true
tags: ${{ steps.image_name.outputs.image_name }}:test
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ jobs:
image: ghcr.io/ptb-mr/mrpro_py311:latest
options: --user root
strategy:
fail-fast: false
matrix:
notebook: ${{ fromJson(needs.get_notebooks.outputs.notebooks) }}
steps:
Expand Down
47 changes: 25 additions & 22 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@ name: PyTest

on:
pull_request:
push:
branches:
- main

jobs:
get_dockerfiles:
name: Get list of dockerfiles for different containers
name: Get List of Dockerfiles for Containers
runs-on: ubuntu-latest
permissions:
packages: read
outputs:
imagenames: ${{ steps.set-matrix.outputs.imagenames }}
steps:
- id: set-matrix
- name: Retrieve Docker Image Names
id: set-matrix
env:
GH_TOKEN: ${{ secrets.GHCR_TOKEN }}
run: |
Expand All @@ -35,57 +39,56 @@ jobs:
echo "image names with tag latest: $imagenames_latest"
echo "imagenames=$imagenames_latest" >> $GITHUB_OUTPUT
- name: Dockerfile overview
- name: Dockerfile Overview
run: |
echo "final list of images with tag latest: ${{ steps.set-matrix.outputs.imagenames }}"
echo "Final list of images with tag latest: ${{ steps.set-matrix.outputs.imagenames }}"
test:
name: Run tests and get coverage report
name: Run Tests and Coverage Report
needs: get_dockerfiles
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: write
strategy:
fail-fast: false
matrix:
imagename: ${{ fromJson(needs.get_dockerfiles.outputs.imagenames) }}
# runs within Docker container
container:
image: ghcr.io/ptb-mr/${{ matrix.imagename }}:latest
options: --user runner

steps:
- name: Checkout repo
- name: Checkout Repository
uses: actions/checkout@v4

- name: Install mrpro and dependencies
run: pip install --upgrade --upgrade-strategy "eager" .[test]
- name: Install MRpro and Dependencies
run: pip install --upgrade --upgrade-strategy eager .[test]

- name: Install pytest-github-actions-annotate-failures plugin
- name: Install PyTest GitHub Annotation Plugin
run: pip install pytest-github-actions-annotate-failures

- name: Run PyTest
- name: Run PyTest and Generate Coverage Report
run: |
pytest -n 4 -m "not cuda" --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=mrpro | tee pytest-coverage.txt
pytest -n 4 -m "not cuda" --junitxml=pytest.xml \
--cov-report=term-missing:skip-covered --cov=mrpro | tee pytest-coverage.txt
- name: Check for pytest.xml
- name: Verify PyTest XML Output
run: |
if [ -f pytest.xml ]; then
echo "pytest.xml file found. Continuing..."
else
echo "pytest.xml file not found. Please check previous 'Run PyTest' section for errors."
if [ ! -f pytest.xml ]; then
echo "PyTest XML report not found. Please check the previous 'Run PyTest' step for errors."
exit 1
fi
- name: Pytest coverage comment
- name: Post PyTest Coverage Comment
id: coverageComment
uses: MishaKav/pytest-coverage-comment@v1.1.53
with:
pytest-coverage-path: ./pytest-coverage.txt
junitxml-path: ./pytest.xml

- name: Create the Badge
- name: Create Coverage Badge on Main Branch Push
uses: schneegans/dynamic-badges-action@v1.7.0
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
with:
auth: ${{ secrets.GIST_SECRET }}
gistID: 48e334a10caf60e6708d7c712e56d241
Expand All @@ -95,12 +98,12 @@ jobs:
color: ${{ steps.coverageComment.outputs.color }}
namedLogo: python

- name: Set pipeline status
- name: Set Pipeline Status Based on Test Results
if: steps.coverageComment.outputs.errors != 0 || steps.coverageComment.outputs.failures != 0
uses: actions/github-script@v7
with:
script: |
core.setFailed('PyTest workflow failed with ${{ steps.coverageComment.outputs.errors }} errors and ${{ steps.coverageComment.outputs.failures }} failures.')
core.setFailed("PyTest workflow failed with ${{ steps.coverageComment.outputs.errors }} errors and ${{ steps.coverageComment.outputs.failures }} failures.")
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
Expand Down
34 changes: 21 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-added-large-files
- id: check-docstring-first
- id: check-merge-conflict
- id: check-yaml
- id: check-toml
Expand All @@ -15,19 +14,26 @@ repos:
- id: mixed-line-ending

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.9
rev: v0.7.2
hooks:
- id: ruff # linter
args: [--fix]
- id: ruff-format # formatter

- repo: https://github.com/crate-ci/typos
rev: v1.25.0
rev: v1.27.0
hooks:
- id: typos

- repo: https://github.com/fzimmermann89/check_all
rev: v1.0
hooks:
- id: check-init-all
args: [--double-quotes]
exclude: ^tests/

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.2
rev: v1.13.0
hooks:
- id: mypy
pass_filenames: false
Expand All @@ -37,19 +43,21 @@ repos:
- numpy
- torch>=2.4.0
- types-requests
- typing-extensions
- einops
- pydicom
- matplotlib
- pytest
- xsdata
- "--index-url=https://download.pytorch.org/whl/cpu"
- "--extra-index-url=https://pypi.python.org/simple"

ci:
autofix_commit_msg: |
[pre-commit] auto fixes from pre-commit hooks
autofix_prs: false
autoupdate_branch: ''
autoupdate_commit_msg: '[pre-commit] pre-commit autoupdate'
autoupdate_schedule: monthly
skip: [mypy]
submodules: false
autofix_commit_msg: |
[pre-commit] auto fixes from pre-commit hooks
autofix_prs: false
autoupdate_branch: ""
autoupdate_commit_msg: "[pre-commit] pre-commit autoupdate"
autoupdate_schedule: monthly
skip: [mypy]
submodules: false
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"davidanson.vscode-markdownlint",
"editorconfig.editorconfig",
"kevinrose.vsc-python-indent",
"ms-python.black-formatter",
"charliermarsh.ruff",
"ms-python.isort",
"ms-python.python",
"ms-python.vscode-pylance",
Expand Down
Loading

0 comments on commit 57c3193

Please sign in to comment.