Skip to content

Commit

Permalink
Merge pull request #25 from tomaroberts/23-gha-testpypi
Browse files Browse the repository at this point in the history
Adds GitHub Action to automatically publish every pushed version to TestPyPI, then verifies build
  • Loading branch information
tomaroberts authored Aug 24, 2023
2 parents a1e988e + 2d72880 commit a24a553
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 50 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build_and_test_cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ jobs:
- name: Test nii2dcm install
run: |
nii2dcm -h
nii2dcm -v
- name: Test DicomMRISVR creation
run: |
Expand Down
82 changes: 82 additions & 0 deletions .github/workflows/publish_testpypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Publish to TestPyPI
#
# This workflow publishes nii2dcm on TestPyPI prior to production release onto PyPI. The workflow is intended to catch
# any issues arising during the release procedure to prevent unnecessary versioning issues on PyPI
#
# This workflow will upload a Python Package using Twine when a release is created. For more information see:
# https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
#
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Publish package to TestPyPI

on:
pull_request

permissions:
contents: read

jobs:
testpypi-publish:

name: Publish release to TestPyPI
runs-on: ubuntu-latest
environment:
name: testpypi
url: https://test.pypi.org/p/nii2dcm
permissions:
id-token: write # IMPORTANT: this permission is mandatory for PyPI trusted publishing

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build --sdist --wheel --outdir dist/

- name: Display nii2dcm version
id: nii2dcm-version
run: |
pip install -e .
echo "nii2dcm version:"
nii2dcm -v
- name: Publish package to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.TESTPYPI_API_TOKEN }}
repository-url: https://test.pypi.org/legacy/
verbose: true

- name: Wait to allow TestPyPI to update
uses: GuillaumeFalourd/wait-sleep-action@v1
with:
time: '150' # seconds

- name: Install latest TestPyPI version in fresh venv
run: |
NII2DCM_VERSION=`echo "$(nii2dcm -v)"`
echo $NII2DCM_VERSION
python -m venv nii2dcm-temp
source nii2dcm-temp/bin/activate
pip install --upgrade pip
pip install setuptools wheel
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ nii2dcm==$NII2DCM_VERSION
nii2dcm -h
echo "nii2dcm version:"
nii2dcm -v
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,8 @@ _im*
*.nii
*.nii.gz

# Omit _version.py as required by setuptools_scm
nii2dcm/_version.py

# Permit Test Data
!tests/data/DicomMRISVR/t2-svr-atlas-35wk.nii.gz
3 changes: 2 additions & 1 deletion nii2dcm/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import argparse
from pathlib import Path
from nii2dcm.run import run_nii2dcm
from nii2dcm._version import __version__


def cli(args=None):
Expand All @@ -24,7 +25,7 @@ def cli(args=None):
parser.add_argument("output_dir", type=str, help="[directory] output DICOM path")
parser.add_argument("-d", "--dicom_type", type=str, help="[string] type of DICOM. e.g. MR, CT, US, XR, etc.")
parser.add_argument("-r", "--ref_dicom", type=str, help="[.dcm] Reference DICOM file for Attribute transfer")
parser.add_argument("-v", "--version", action="version", version="0.1.0")
parser.add_argument("-v", "--version", action="version", version=__version__)

args = parser.parse_args()

Expand Down
6 changes: 3 additions & 3 deletions nii2dcm/modules/image_pixel.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ def __init__(self):
self.ds.BitsAllocated = 1
self.ds.BitsStored = ''
self.ds.HighBit = ''

# PixelRepresentation
# Enumerated values either: unsigned integer or two's complement
# Setting = 0, as observed in real DICOM
self.ds.PixelRepresentation = 0

self.ds.SmallestImagePixelValue = ''
self.ds.LargestImagePixelValue = ''

# PixelData written in dcm_writer via Pydicom
self.ds.PixelData = ''
2 changes: 1 addition & 1 deletion nii2dcm/nii.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def fnT1N(A, N):
sliceIndices = np.repeat(range(1, nZ+1), nF)
voxelSpacing = dimZ
zLocLast = (voxelSpacing * nZ) - voxelSpacing
sliceLoca = np.repeat( np.linspace(0, zLocLast, num=nZ), nF)
sliceLoca = np.repeat(np.linspace(0, zLocLast, num=nZ), nF)

# Windowing & Signal Intensity
maxI = np.amax(nii_img)
Expand Down
11 changes: 11 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[build-system]
requires = ["setuptools>=64.0.0", "wheel", "setuptools_scm[toml]>=6.2"]
build-backend = "setuptools.build_meta"

[project]
name = "nii2dcm"
dynamic = ["version"]

[tool.setuptools_scm]
local_scheme = "no-local-version" # required for PyPI and TestPyPI
write_to = "nii2dcm/_version.py"
13 changes: 0 additions & 13 deletions pyprojects.toml

This file was deleted.

4 changes: 2 additions & 2 deletions scripts/create_3d_dicom.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@


NII2DCM_DIR = r'/Users/tr17/code/nii2dcm'
INPUT_DIR = r'/Users/tr17/code/nii2dcm/input/'
OUTPUT_DIR = r'/Users/tr17/code/nii2dcm/output'
INPUT_DIR = r'/Users/tr17/code/nii2dcm/input/'
OUTPUT_DIR = r'/Users/tr17/code/nii2dcm/output'

if not os.path.isdir(OUTPUT_DIR):
os.makedirs(OUTPUT_DIR)
Expand Down
24 changes: 24 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[metadata]
name = nii2dcm
version = attr: nii2dcm._version.__version__
description= nii2dcm: NIfTI to DICOM creation with Python
url = https://github.com/tomaroberts/nii2dcm
author = Tom Roberts
author_email = t.roberts@kcl.ac.uk
long_description = file:README.md
long_description_content_type = text/markdown

[options]
packages = find:
python_requires = <3.11
install_requires =
numpy==1.23.2
matplotlib==3.6.2
nibabel==5.0.0
pydicom==2.3.0
twine==4.0.2
include_package_data=True

[options.entry_points]
console_scripts =
nii2dcm = nii2dcm.__main__:cli
30 changes: 0 additions & 30 deletions setup.py

This file was deleted.

0 comments on commit a24a553

Please sign in to comment.