From 841dcaa4122eba9cba67ee1e8d0cb152a92e45ed Mon Sep 17 00:00:00 2001 From: Max Jones Date: Thu, 13 Oct 2022 16:25:57 -0400 Subject: [PATCH 01/12] Add GitHub workflow for PyPI releases --- .github/workflows/pypi-release.yml | 103 +++++++++++++++++++++++++++++ xbatcher/util/print_versions.py | 4 ++ 2 files changed, 107 insertions(+) create mode 100644 .github/workflows/pypi-release.yml diff --git a/.github/workflows/pypi-release.yml b/.github/workflows/pypi-release.yml new file mode 100644 index 0000000..7377216 --- /dev/null +++ b/.github/workflows/pypi-release.yml @@ -0,0 +1,103 @@ +name: Build and Upload xbatcher to PyPI +on: + release: + types: + - published + # Runs for pull requests should be disabled other than for testing purposes + #pull_request: + # branches: + # - main + +jobs: + build-artifacts: + runs-on: ubuntu-latest + if: github.repository == 'xarray-contrib/xbatcher' + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - uses: actions/setup-python@v4 + name: Install Python + with: + python-version: 3.8 + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install build twine + + # This step is only necessary for testing purposes and for TestPyPI + - name: Fix up version string for TestPyPI + if: ${{ !startsWith(github.ref, 'refs/tags') }} + run: | + # Change setuptools-scm local_scheme to "no-local-version" so the + # local part of the version isn't included, making the version string + # compatible with PyPI. + sed --in-place "s/dirty-tag/no-local-version/g" pyproject.toml + + - name: Build tarball and wheels + run: | + git clean -xdf + git restore -SW . + python -m build + - name: Check built artifacts + run: | + python -m twine check --strict dist/* + pwd + if [ -f dist/xbatcher-0.0.0.tar.gz ]; then + echo "❌ INVALID VERSION NUMBER" + exit 1 + else + echo "✅ Looks good" + fi + - uses: actions/upload-artifact@v3 + with: + name: releases + path: dist + + test-built-dist: + needs: build-artifacts + runs-on: ubuntu-latest + steps: + - uses: actions/setup-python@v4 + name: Install Python + with: + python-version: 3.8 + - uses: actions/download-artifact@v3 + with: + name: releases + path: dist + - name: List contents of built dist + run: | + ls -ltrh + ls -ltrh dist + - name: Verify the built dist/wheel is valid + if: github.event_name == 'push' + run: | + python -m pip install --upgrade pip + python -m pip install dist/xbatcher*.whl + python -m xbatcher.show_versions + - name: Publish package to TestPyPI + if: github.event_name == 'push' + uses: pypa/gh-action-pypi-publish@v1.5.1 + with: + user: __token__ + password: ${{ secrets.TESTPYPI_TOKEN }} + repository_url: https://test.pypi.org/legacy/ + verbose: true + + upload-to-pypi: + needs: test-built-dist + if: github.event_name == 'release' + runs-on: ubuntu-latest + steps: + - uses: actions/download-artifact@v3 + with: + name: releases + path: dist + - name: Publish package to PyPI + uses: pypa/gh-action-pypi-publish@v1.5.1 + with: + user: __token__ + password: ${{ secrets.PYPI_TOKEN }} + verbose: true diff --git a/xbatcher/util/print_versions.py b/xbatcher/util/print_versions.py index 122140c..0d44aa2 100644 --- a/xbatcher/util/print_versions.py +++ b/xbatcher/util/print_versions.py @@ -63,3 +63,7 @@ def _get_module_version(modname): print("Dependency information:", file=file) for modname in deps: print(f" {modname}: {_get_module_version(modname)}", file=file) + + +if __name__ == "__main__": + show_versions() From c88949ff51218490f20fdbd7ae1eb8492840e07f Mon Sep 17 00:00:00 2001 From: Max Jones Date: Thu, 13 Oct 2022 16:31:18 -0400 Subject: [PATCH 02/12] Comment verbose setting --- .github/workflows/pypi-release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pypi-release.yml b/.github/workflows/pypi-release.yml index 7377216..121d745 100644 --- a/.github/workflows/pypi-release.yml +++ b/.github/workflows/pypi-release.yml @@ -84,7 +84,7 @@ jobs: user: __token__ password: ${{ secrets.TESTPYPI_TOKEN }} repository_url: https://test.pypi.org/legacy/ - verbose: true + # verbose: true upload-to-pypi: needs: test-built-dist @@ -100,4 +100,4 @@ jobs: with: user: __token__ password: ${{ secrets.PYPI_TOKEN }} - verbose: true + # verbose: true From 5748982b309cf4fea2bac13e418f578077ff4923 Mon Sep 17 00:00:00 2001 From: Max Jones Date: Tue, 18 Oct 2022 15:59:28 -0400 Subject: [PATCH 03/12] Omit direct invocation code from coverage --- xbatcher/util/print_versions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xbatcher/util/print_versions.py b/xbatcher/util/print_versions.py index 0d44aa2..2eed240 100644 --- a/xbatcher/util/print_versions.py +++ b/xbatcher/util/print_versions.py @@ -65,5 +65,5 @@ def _get_module_version(modname): print(f" {modname}: {_get_module_version(modname)}", file=file) -if __name__ == "__main__": +if __name__ == "__main__": # pragma: no cover show_versions() From 1c42f97e77d0213e9185310a0cc8b11cca468b11 Mon Sep 17 00:00:00 2001 From: Max Jones Date: Tue, 25 Oct 2022 16:21:10 -0400 Subject: [PATCH 04/12] Apply suggestions from code review Co-authored-by: Wei Ji <23487320+weiji14@users.noreply.github.com> --- .github/workflows/pypi-release.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pypi-release.yml b/.github/workflows/pypi-release.yml index 121d745..fbe931d 100644 --- a/.github/workflows/pypi-release.yml +++ b/.github/workflows/pypi-release.yml @@ -8,6 +8,9 @@ on: # branches: # - main +permissions: + contents: read + jobs: build-artifacts: runs-on: ubuntu-latest @@ -81,7 +84,6 @@ jobs: if: github.event_name == 'push' uses: pypa/gh-action-pypi-publish@v1.5.1 with: - user: __token__ password: ${{ secrets.TESTPYPI_TOKEN }} repository_url: https://test.pypi.org/legacy/ # verbose: true @@ -98,6 +100,5 @@ jobs: - name: Publish package to PyPI uses: pypa/gh-action-pypi-publish@v1.5.1 with: - user: __token__ password: ${{ secrets.PYPI_TOKEN }} # verbose: true From b95bcd970f838977c8c831f0e27897a1b2b820d2 Mon Sep 17 00:00:00 2001 From: Max Jones Date: Wed, 26 Oct 2022 15:32:23 -0400 Subject: [PATCH 05/12] Use consistent file extension --- .github/workflows/{pypi-release.yml => pypi-release.yaml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{pypi-release.yml => pypi-release.yaml} (100%) diff --git a/.github/workflows/pypi-release.yml b/.github/workflows/pypi-release.yaml similarity index 100% rename from .github/workflows/pypi-release.yml rename to .github/workflows/pypi-release.yaml From b741b8cd41dc6a5c6811c225a66e8a1cc9eaf6f9 Mon Sep 17 00:00:00 2001 From: Max Jones Date: Wed, 26 Oct 2022 15:37:48 -0400 Subject: [PATCH 06/12] Document workflow --- doc/contributing.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/contributing.rst b/doc/contributing.rst index 803d2bc..31ebd04 100644 --- a/doc/contributing.rst +++ b/doc/contributing.rst @@ -246,3 +246,5 @@ Continuous integration is done with `GitHub Actions `_ - Run test suite with pytest. +- `pypi-release.yaml `_ - Publish + wheels to TestPyPI and PyPI on a tagged release. The pull request trigger can be uncommented to test a release using Test PyPI. From 2e1b57fd1daaf6c08c5a3d397576074fd636d363 Mon Sep 17 00:00:00 2001 From: Max Jones Date: Wed, 26 Oct 2022 15:46:30 -0400 Subject: [PATCH 07/12] Test workflow --- .github/workflows/pypi-release.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pypi-release.yaml b/.github/workflows/pypi-release.yaml index fbe931d..4afc935 100644 --- a/.github/workflows/pypi-release.yaml +++ b/.github/workflows/pypi-release.yaml @@ -4,9 +4,9 @@ on: types: - published # Runs for pull requests should be disabled other than for testing purposes - #pull_request: - # branches: - # - main + pull_request: + branches: + - main permissions: contents: read @@ -84,7 +84,7 @@ jobs: if: github.event_name == 'push' uses: pypa/gh-action-pypi-publish@v1.5.1 with: - password: ${{ secrets.TESTPYPI_TOKEN }} + password: ${{ secrets.TEST_PYPI_API_TOKEN }} repository_url: https://test.pypi.org/legacy/ # verbose: true From f9bc5bd99828cec5cba4aa34a33ce3fcb88d1957 Mon Sep 17 00:00:00 2001 From: Max Jones Date: Wed, 26 Oct 2022 15:57:57 -0400 Subject: [PATCH 08/12] Specify readme in project metadata --- pyproject.toml | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 31153e3..6d11e6a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,21 +6,22 @@ requires = [ build-backend = "setuptools.build_meta" [project] -name = 'xbatcher' -description = 'Batch generation from Xarray objects' +name = "xbatcher" +description = "Batch generation from Xarray objects" +readme = "README.rst" license = {text = "Apache"} authors = [{name = "xbatcher Developers", email = "rpa@ldeo.columbia.edu"}] classifiers = [ - 'Development Status :: 4 - Beta', + "Development Status :: 4 - Beta", "License :: OSI Approved :: Apache Software License", - 'Operating System :: OS Independent', - 'Intended Audience :: Science/Research', - 'Programming Language :: Python', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10', - 'Topic :: Scientific/Engineering', + "Operating System :: OS Independent", + "Intended Audience :: Science/Research", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Topic :: Scientific/Engineering", ] dynamic = ["version"] dependencies = [ @@ -52,12 +53,12 @@ repository = "https://github.com/xarray-contrib/xbatcher" include = ["xbatcher*"] [tool.setuptools_scm] -version_scheme = 'post-release' -local_scheme = 'dirty-tag' +version_scheme = "post-release" +local_scheme = "dirty-tag" fallback_version = "999" [tool.isort] -profile = 'black' +profile = "black" known_third_party = ["numpy", "pytest", "setuptools", "sphinx_autosummary_accessors", "torch", "xarray"] [tool.pytest.ini_options] From f93aced2e1b98ec54525d0dcb4238e9ccb46442b Mon Sep 17 00:00:00 2001 From: Max Jones Date: Wed, 26 Oct 2022 16:08:13 -0400 Subject: [PATCH 09/12] Upload to TestPyPI on PR --- .github/workflows/pypi-release.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/pypi-release.yaml b/.github/workflows/pypi-release.yaml index 4afc935..c7cd16e 100644 --- a/.github/workflows/pypi-release.yaml +++ b/.github/workflows/pypi-release.yaml @@ -75,13 +75,11 @@ jobs: ls -ltrh ls -ltrh dist - name: Verify the built dist/wheel is valid - if: github.event_name == 'push' run: | python -m pip install --upgrade pip python -m pip install dist/xbatcher*.whl python -m xbatcher.show_versions - name: Publish package to TestPyPI - if: github.event_name == 'push' uses: pypa/gh-action-pypi-publish@v1.5.1 with: password: ${{ secrets.TEST_PYPI_API_TOKEN }} From e7cf1a0f8593af0387bbd69a8baaa59a3b77c7de Mon Sep 17 00:00:00 2001 From: Max Jones Date: Wed, 26 Oct 2022 16:17:28 -0400 Subject: [PATCH 10/12] Fix test command --- .github/workflows/pypi-release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pypi-release.yaml b/.github/workflows/pypi-release.yaml index c7cd16e..5d17816 100644 --- a/.github/workflows/pypi-release.yaml +++ b/.github/workflows/pypi-release.yaml @@ -78,7 +78,7 @@ jobs: run: | python -m pip install --upgrade pip python -m pip install dist/xbatcher*.whl - python -m xbatcher.show_versions + python -m xbatcher.util.print_versions - name: Publish package to TestPyPI uses: pypa/gh-action-pypi-publish@v1.5.1 with: From e4c46eba36b0026b5433c22a0885104620a9258c Mon Sep 17 00:00:00 2001 From: Max Jones Date: Wed, 26 Oct 2022 17:59:39 -0400 Subject: [PATCH 11/12] Update token name --- .github/workflows/pypi-release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pypi-release.yaml b/.github/workflows/pypi-release.yaml index 5d17816..a5ae7f2 100644 --- a/.github/workflows/pypi-release.yaml +++ b/.github/workflows/pypi-release.yaml @@ -98,5 +98,5 @@ jobs: - name: Publish package to PyPI uses: pypa/gh-action-pypi-publish@v1.5.1 with: - password: ${{ secrets.PYPI_TOKEN }} + password: ${{ secrets.PYPI_API_TOKEN }} # verbose: true From 12ecb3f595498f3b7586024d621fd1d59846495a Mon Sep 17 00:00:00 2001 From: Max Jones Date: Wed, 26 Oct 2022 18:45:30 -0400 Subject: [PATCH 12/12] Apply suggestions from code review --- .github/workflows/pypi-release.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pypi-release.yaml b/.github/workflows/pypi-release.yaml index a5ae7f2..cd4899d 100644 --- a/.github/workflows/pypi-release.yaml +++ b/.github/workflows/pypi-release.yaml @@ -4,9 +4,9 @@ on: types: - published # Runs for pull requests should be disabled other than for testing purposes - pull_request: - branches: - - main + #pull_request: + # branches: + # - main permissions: contents: read