From 10ec0432cceaafd60852b1603a90c1f46277ff8b Mon Sep 17 00:00:00 2001 From: Tom Roberts Date: Thu, 31 Aug 2023 16:07:46 +0100 Subject: [PATCH 01/12] Integrates dunamai for dynamic version numbering Updates: - requirements.txt - setup.cfg - adds setup.py - removes setuptools-scm code from pyproject.toml - reinstates _version.py so that version propagated through code, such as CLI `nii2dcm -v` --- .gitignore | 3 --- nii2dcm/_version.py | 2 ++ pyproject.toml | 10 +--------- requirements.txt | 3 ++- setup.cfg | 3 ++- setup.py | 7 +++++++ 6 files changed, 14 insertions(+), 14 deletions(-) create mode 100644 nii2dcm/_version.py create mode 100644 setup.py diff --git a/.gitignore b/.gitignore index b0f0c11..d7c3b9c 100644 --- a/.gitignore +++ b/.gitignore @@ -88,8 +88,5 @@ _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 \ No newline at end of file diff --git a/nii2dcm/_version.py b/nii2dcm/_version.py new file mode 100644 index 0000000..b8bebde --- /dev/null +++ b/nii2dcm/_version.py @@ -0,0 +1,2 @@ +from dunamai import Version, Style +__version__ = Version.from_git().serialize(metadata=False, style=Style.SemVer) diff --git a/pyproject.toml b/pyproject.toml index e06e019..4f33390 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,11 +1,3 @@ [build-system] -requires = ["setuptools>=64.0.0", "wheel", "setuptools_scm[toml]>=6.2"] +requires = ["setuptools>=64.0.0", "wheel"] 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" \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 67f6d5e..91edd24 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,5 @@ numpy==1.23.2 matplotlib==3.6.2 nibabel==5.0.0 pydicom==2.3.0 -twine==4.0.2 \ No newline at end of file +twine==4.0.2 +dunamai==1.18.0 \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index 1a38b92..7ad1c06 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = nii2dcm -version = attr: nii2dcm._version.__version__ +version = attr: nii2dcm.__init__.__version__ description= nii2dcm: NIfTI to DICOM creation with Python url = https://github.com/tomaroberts/nii2dcm author = Tom Roberts @@ -17,6 +17,7 @@ install_requires = nibabel==5.0.0 pydicom==2.3.0 twine==4.0.2 + dunamai==1.18.0 include_package_data=True [options.entry_points] diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..ce87831 --- /dev/null +++ b/setup.py @@ -0,0 +1,7 @@ +from setuptools import setup +from dunamai import Version, Style + +setup( + name="nii2dcm", + version=Version.from_git().serialize(metadata=False, style=Style.SemVer), +) \ No newline at end of file From 9c993b849d3e1cfccf1adc5310fa9b002451b53d Mon Sep 17 00:00:00 2001 From: Tom Roberts Date: Thu, 31 Aug 2023 16:15:32 +0100 Subject: [PATCH 02/12] Refactors TestPyPI GHA to use dunamai --- .github/workflows/publish_testpypi.yml | 42 +++++++++++++++++++++----- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/.github/workflows/publish_testpypi.yml b/.github/workflows/publish_testpypi.yml index 79b4420..c31bbb4 100644 --- a/.github/workflows/publish_testpypi.yml +++ b/.github/workflows/publish_testpypi.yml @@ -1,7 +1,9 @@ # 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 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 @@ -14,20 +16,25 @@ name: Publish package to TestPyPI on: - pull_request + push: + branches: + - main + - 24-gha-pypi permissions: contents: read + actions: write jobs: testpypi-publish: - name: Publish release to TestPyPI runs-on: ubuntu-latest environment: name: testpypi url: https://test.pypi.org/p/nii2dcm permissions: + contents: read + actions: write id-token: write # IMPORTANT: this permission is mandatory for PyPI trusted publishing steps: @@ -43,18 +50,37 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install build + pip install setuptools wheel + pip install -r requirements.txt - name: Build package - run: python -m build --sdist --wheel --outdir dist/ + run: python setup.py install + + - name: Display version via dunamai + run: | + echo "dunamai version:" + dunamai from any - - name: Display nii2dcm version + - name: Display version via nii2dcm CLI id: nii2dcm-version run: | - pip install -e . +# pip install -e . echo "nii2dcm version:" nii2dcm -v + - name: Create dist/ + run: | + python setup.py sdist bdist_wheel + twine check dist/* + + - name: Remove .egg + run: | + echo "dist/ before:" + ls dist/ + [ -f "./dist/*.egg" ] && "Deleting .egg file as not permitted on PyPI" || rm ./dist/*.egg + echo "dist/ after:" + ls dist/ + - name: Publish package to TestPyPI uses: pypa/gh-action-pypi-publish@release/v1 with: From eef0adaa43f41cdaa0bc35c68afc216cde0813cb Mon Sep 17 00:00:00 2001 From: Tom Roberts Date: Thu, 31 Aug 2023 16:20:16 +0100 Subject: [PATCH 03/12] Bugfix: line63 & remove id: --- .github/workflows/publish_testpypi.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/publish_testpypi.yml b/.github/workflows/publish_testpypi.yml index c31bbb4..771bf4f 100644 --- a/.github/workflows/publish_testpypi.yml +++ b/.github/workflows/publish_testpypi.yml @@ -62,7 +62,6 @@ jobs: dunamai from any - name: Display version via nii2dcm CLI - id: nii2dcm-version run: | # pip install -e . echo "nii2dcm version:" From 9c155c2627d660e570bd932ac4cbcfafc6acfa95 Mon Sep 17 00:00:00 2001 From: Tom Roberts Date: Thu, 31 Aug 2023 16:21:39 +0100 Subject: [PATCH 04/12] Bugfix: removes first line comment from step --- .github/workflows/publish_testpypi.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/publish_testpypi.yml b/.github/workflows/publish_testpypi.yml index 771bf4f..b2535fa 100644 --- a/.github/workflows/publish_testpypi.yml +++ b/.github/workflows/publish_testpypi.yml @@ -63,7 +63,6 @@ jobs: - name: Display version via nii2dcm CLI run: | -# pip install -e . echo "nii2dcm version:" nii2dcm -v From e61edfa89004cb5ee0f7d7586b59ce48ce77c9f4 Mon Sep 17 00:00:00 2001 From: Tom Roberts Date: Thu, 31 Aug 2023 16:26:40 +0100 Subject: [PATCH 05/12] Add comment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use this commit to create new tag containing "v", i.e. v0.1.1 – required by current dunamai implementation --- .github/workflows/publish_testpypi.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish_testpypi.yml b/.github/workflows/publish_testpypi.yml index b2535fa..b48eaf5 100644 --- a/.github/workflows/publish_testpypi.yml +++ b/.github/workflows/publish_testpypi.yml @@ -54,7 +54,7 @@ jobs: pip install -r requirements.txt - name: Build package - run: python setup.py install + run: python setup.py install # TODO: fix pip install -e . - name: Display version via dunamai run: | From 41abee14b09cfe066f1db277dedd973cebe5a26c Mon Sep 17 00:00:00 2001 From: Tom Roberts Date: Thu, 31 Aug 2023 16:59:54 +0100 Subject: [PATCH 06/12] Remove pyproject.toml as causing pip install to fail - Leftover from setuptools-scm - Potentially reinstate in future --- pyproject.toml | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 pyproject.toml diff --git a/pyproject.toml b/pyproject.toml deleted file mode 100644 index 4f33390..0000000 --- a/pyproject.toml +++ /dev/null @@ -1,3 +0,0 @@ -[build-system] -requires = ["setuptools>=64.0.0", "wheel"] -build-backend = "setuptools.build_meta" From 7bb15a917e25c61c4ec6a961095affaeee2647c2 Mon Sep 17 00:00:00 2001 From: Tom Roberts Date: Thu, 31 Aug 2023 17:07:07 +0100 Subject: [PATCH 07/12] Build via pip instead of python setup.py install --- .github/workflows/publish_testpypi.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish_testpypi.yml b/.github/workflows/publish_testpypi.yml index b48eaf5..dde2e07 100644 --- a/.github/workflows/publish_testpypi.yml +++ b/.github/workflows/publish_testpypi.yml @@ -54,16 +54,16 @@ jobs: pip install -r requirements.txt - name: Build package - run: python setup.py install # TODO: fix pip install -e . + run: pip install . - name: Display version via dunamai run: | - echo "dunamai version:" + echo "version via dunamai:" dunamai from any - name: Display version via nii2dcm CLI run: | - echo "nii2dcm version:" + echo "version via nii2dcm CLI:" nii2dcm -v - name: Create dist/ From 213696a613cdeaa041df47a79a76c9460d1236bb Mon Sep 17 00:00:00 2001 From: Tom Roberts Date: Thu, 31 Aug 2023 17:14:52 +0100 Subject: [PATCH 08/12] Deletes step: Remove .egg Not required now `pip install .` functional --- .github/workflows/publish_testpypi.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/.github/workflows/publish_testpypi.yml b/.github/workflows/publish_testpypi.yml index dde2e07..3feaa42 100644 --- a/.github/workflows/publish_testpypi.yml +++ b/.github/workflows/publish_testpypi.yml @@ -71,14 +71,6 @@ jobs: python setup.py sdist bdist_wheel twine check dist/* - - name: Remove .egg - run: | - echo "dist/ before:" - ls dist/ - [ -f "./dist/*.egg" ] && "Deleting .egg file as not permitted on PyPI" || rm ./dist/*.egg - echo "dist/ after:" - ls dist/ - - name: Publish package to TestPyPI uses: pypa/gh-action-pypi-publish@release/v1 with: From 16701ac9bbb690b9229737858cdc159b9b09c5b1 Mon Sep 17 00:00:00 2001 From: Tom Roberts Date: Thu, 31 Aug 2023 17:24:18 +0100 Subject: [PATCH 09/12] Small change to re-run failed TestPyPI workflow --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7c9e671..68a5b73 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ nii2dcm SVR-output.nii.gz path/to/output/dir/ -d SVR ## Roadmap -This project is in its infancy! Expect :bug::ant::beetle: +This project is in its infancy! Expect bugs :bug::ant::beetle: There are many things I would like to test and implement. [Raise an Issue](https://github.com/tomaroberts/nii2dcm/issues) if you have ideas or suggestions. From b1feb86683f8f4d67a8e318f974e0aefd0ffa400 Mon Sep 17 00:00:00 2001 From: Tom Roberts Date: Thu, 31 Aug 2023 17:37:59 +0100 Subject: [PATCH 10/12] Removes test branch from workflow --- .github/workflows/publish_testpypi.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/publish_testpypi.yml b/.github/workflows/publish_testpypi.yml index 3feaa42..6cafc3e 100644 --- a/.github/workflows/publish_testpypi.yml +++ b/.github/workflows/publish_testpypi.yml @@ -19,7 +19,6 @@ on: push: branches: - main - - 24-gha-pypi permissions: contents: read From 37e7f07edf566927bb27ad324b67be68da385395 Mon Sep 17 00:00:00 2001 From: Tom Roberts Date: Thu, 31 Aug 2023 17:38:35 +0100 Subject: [PATCH 11/12] Adds Github Action to automatically publish to PyPI on release --- .github/workflows/publish_pypi.yml | 99 ++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 .github/workflows/publish_pypi.yml diff --git a/.github/workflows/publish_pypi.yml b/.github/workflows/publish_pypi.yml new file mode 100644 index 0000000..6f37c80 --- /dev/null +++ b/.github/workflows/publish_pypi.yml @@ -0,0 +1,99 @@ +# Publish to PyPI +# +# This workflow publishes nii2dcm on PyPI. The workflow triggers +# on release. The PyPI release is labelled according to the git tag +# specified in the GitHub Release user interface. For instance, +# if the TestPyPI release is v0.1.2.post16, then the GitHub Release +# tag should be entered as v0.1.3, which will propagate to PyPI. +# Subsequent developer commits will become v0.1.3.post1, v0.1.3.post2, +# and so on. +# +# 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 PyPI + +on: + release: + types: [published] + +permissions: + contents: read + actions: write + +jobs: + testpypi-publish: + + name: Publish to PyPI + runs-on: ubuntu-latest + environment: + name: pypi + url: https://pypi.org/p/nii2dcm + permissions: + contents: read + actions: write + 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 setuptools wheel + pip install -r requirements.txt + + - name: Build package + run: pip install . + + - name: Display version via dunamai + run: | + echo "version via dunamai:" + dunamai from any + + - name: Display version via nii2dcm CLI + run: | + echo "version via nii2dcm CLI:" + nii2dcm -v + + - name: Create dist/ + run: | + python setup.py sdist bdist_wheel + twine check dist/* + + - name: Publish package to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} + verbose: true + + - name: Wait to allow PyPI to update + uses: GuillaumeFalourd/wait-sleep-action@v1 + with: + time: '150' # seconds + + - name: Install latest PyPI 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 nii2dcm==$NII2DCM_VERSION + nii2dcm -h + echo "nii2dcm version:" + nii2dcm -v From da523e34aa65b0888bff70af1403423c6278a90e Mon Sep 17 00:00:00 2001 From: Tom Roberts Date: Thu, 31 Aug 2023 17:53:31 +0100 Subject: [PATCH 12/12] Update build_and_test_cli.yml --- .github/workflows/build_and_test_cli.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build_and_test_cli.yml b/.github/workflows/build_and_test_cli.yml index d707658..9c29120 100644 --- a/.github/workflows/build_and_test_cli.yml +++ b/.github/workflows/build_and_test_cli.yml @@ -17,12 +17,10 @@ jobs: os: [ ubuntu-latest ] python-version: [ '3.9' ] - defaults: - run: - shell: bash -l {0} - steps: - uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Set up Python uses: actions/setup-python@v4 @@ -32,6 +30,7 @@ jobs: - name: Install Python packages run: | python -m pip install --upgrade pip + pip install setuptools wheel pip install flake8 pytest pytest-cov if [ -f requirements.txt ]; then pip install -r requirements.txt; fi