Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds GitHub Action to automatically publish to TestPyPI #25

Merged
merged 37 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
af4fa95
Adds _version.py
tomaroberts Aug 22, 2023
d86e897
Correctly name pyproject.toml
tomaroberts Aug 22, 2023
c76f1bf
Replaces setup.py with setup.cfg
tomaroberts Aug 22, 2023
11c72e0
Strips back pyproject.toml so package contents in setup.cfg
tomaroberts Aug 22, 2023
57fa9d3
Updates main to use _version.py
tomaroberts Aug 22, 2023
8959253
Update .gitignore
tomaroberts Aug 22, 2023
bf1e371
Delete _version.py as setuptools_scm generates dynamically
tomaroberts Aug 22, 2023
8738bc8
Bugfix: updates .gitignore
tomaroberts Aug 22, 2023
28c1757
Updates pyproject.toml to use setuptools_scm dynamic versioning
tomaroberts Aug 22, 2023
451dd18
Use setuptools_scm "no-local-version" local_scheme for PyPI compatibi…
tomaroberts Aug 22, 2023
ff83508
Creates TestPyPI GitHub Action
tomaroberts Aug 22, 2023
945409a
Bugfix: adds TestPyPI repository-url to GHA
tomaroberts Aug 22, 2023
af4242f
Trivial change to test GHA version incrementing
tomaroberts Aug 22, 2023
f7b21a4
GHA Test: enable _version.py to be committed to see versioning on Tes…
tomaroberts Aug 22, 2023
503f3f1
Add CLI version command test to GHA
tomaroberts Aug 23, 2023
3915849
GHA test: python build --sdist --wheel
tomaroberts Aug 24, 2023
9ba81a2
Fix error – re-run previous GHA
tomaroberts Aug 24, 2023
5b3ee76
GHA test: adds skip-existing option when publishing on TestPyPI
tomaroberts Aug 24, 2023
79493b4
GHA test: manual update of __version__
tomaroberts Aug 24, 2023
2b37c36
Revert "GHA test: adds skip-existing option when publishing on TestPyPI"
tomaroberts Aug 24, 2023
8269cae
Test GHA: reinstate setuptools-scm
tomaroberts Aug 24, 2023
029d4be
Update .gitignore
tomaroberts Aug 24, 2023
7bf1977
Test GHA: use fetch-depth 0
tomaroberts Aug 24, 2023
aa7072b
GHA Test: display version in GHA for debugging
tomaroberts Aug 24, 2023
e4222b1
Update publish_testpypi.yml
tomaroberts Aug 24, 2023
3c87e59
Update setup.cfg install_requires
tomaroberts Aug 24, 2023
caf5051
Fix dependency versions in setup.cfg
tomaroberts Aug 24, 2023
51e3cf4
GHA Test: verify TestPyPI build in fresh venv
tomaroberts Aug 24, 2023
1a411cd
Get and pass version nii2dcm version with bash echo
tomaroberts Aug 24, 2023
480dc49
Fixes yaml syntax error
tomaroberts Aug 24, 2023
668f0f4
Test GHA: remove erroneous deactivate line
tomaroberts Aug 24, 2023
e39ef90
Update publish_testpypi.yml
tomaroberts Aug 24, 2023
0337121
Pull nii2dcm from TestPyPI / allow dependencies from PyPI
tomaroberts Aug 24, 2023
d0ab098
Add nii2dcm -h test to verify working
tomaroberts Aug 24, 2023
95b8f15
Fixes some linting warnings
tomaroberts Aug 24, 2023
eba4901
Increase wait time for TestPyPI to update
tomaroberts Aug 24, 2023
2d72880
Increase TestPyPI wait time to 2.5 mins
tomaroberts Aug 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading