From f6059de25e39a4fe26653a9848433720fbd7f805 Mon Sep 17 00:00:00 2001 From: Dan Short Date: Thu, 24 Sep 2020 11:13:02 +0100 Subject: [PATCH 01/33] Use cibuildwheel to create wheels --- .github/workflows/python.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 2c3af7a..141b3b7 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -30,10 +30,13 @@ jobs: cmake .. make sudo make install + - name: Install cibuildwheel + run: | + python -m pip install cibuildwheel==1.6.1 - name: Install plasma source run: | pip install -r requirements-develop.txt - python setup.py bdist_wheel + python -m cibuildwheel --output-dir dist python -m pip install --verbose dist/*.whl - name: Run tests run: | From 3fd24bf57c79d127c4db02163db698f18f852c60 Mon Sep 17 00:00:00 2001 From: Dan Short Date: Thu, 24 Sep 2020 11:27:18 +0100 Subject: [PATCH 02/33] Work in manylinux container --- .github/workflows/python.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 141b3b7..4863fdc 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -10,6 +10,7 @@ jobs: build_and_test: runs-on: ubuntu-latest + container: quay.io/pypa/manylinux2014_x86_64 strategy: matrix: python-version: [3.6, 3.7, 3.8] @@ -30,13 +31,10 @@ jobs: cmake .. make sudo make install - - name: Install cibuildwheel - run: | - python -m pip install cibuildwheel==1.6.1 - name: Install plasma source run: | pip install -r requirements-develop.txt - python -m cibuildwheel --output-dir dist + python setup.py bdist_wheel python -m pip install --verbose dist/*.whl - name: Run tests run: | From f1381ba3acf08331aa387ff489bf216872aaa147 Mon Sep 17 00:00:00 2001 From: Dan Short Date: Thu, 24 Sep 2020 11:29:04 +0100 Subject: [PATCH 03/33] No sudo as we're in a container --- .github/workflows/python.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 4863fdc..1282e42 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -23,14 +23,14 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install OpenMC run: | - sudo apt-get install -y g++ cmake libhdf5-dev + apt-get install -y g++ cmake libhdf5-dev git clone --recurse-submodules https://github.com/openmc-dev/openmc.git cd openmc git checkout mkdir build && cd build cmake .. make - sudo make install + make install - name: Install plasma source run: | pip install -r requirements-develop.txt From 9f5d9e42266f54f69736c0a20359845ac57bc0c5 Mon Sep 17 00:00:00 2001 From: Dan Short Date: Thu, 24 Sep 2020 11:31:46 +0100 Subject: [PATCH 04/33] Use yum rather than apt --- .github/workflows/python.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 1282e42..c337dc1 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -23,7 +23,7 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install OpenMC run: | - apt-get install -y g++ cmake libhdf5-dev + yum install -y g++ cmake libhdf5-dev git clone --recurse-submodules https://github.com/openmc-dev/openmc.git cd openmc git checkout From 00ec010bdc8412e9465d4fcb56be43cccce1c7a4 Mon Sep 17 00:00:00 2001 From: Dan Short Date: Thu, 24 Sep 2020 11:36:08 +0100 Subject: [PATCH 05/33] Use yum package names --- .github/workflows/python.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index c337dc1..130c7ba 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -23,7 +23,7 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install OpenMC run: | - yum install -y g++ cmake libhdf5-dev + yum install -y gcc-c++ cmake hdf5-devel git clone --recurse-submodules https://github.com/openmc-dev/openmc.git cd openmc git checkout From 4972b8607f2271c9f5ec35a51b375c4db6d0bdc9 Mon Sep 17 00:00:00 2001 From: Dan Short Date: Thu, 24 Sep 2020 11:40:13 +0100 Subject: [PATCH 06/33] Use cmake3 --- .github/workflows/python.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 130c7ba..2f35f3d 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -23,7 +23,7 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install OpenMC run: | - yum install -y gcc-c++ cmake hdf5-devel + yum install -y gcc-c++ cmake3 hdf5-devel git clone --recurse-submodules https://github.com/openmc-dev/openmc.git cd openmc git checkout From b7ceb2e2f5cb1c58cc69ddda28914ab4d651ec1c Mon Sep 17 00:00:00 2001 From: Dan Short Date: Thu, 24 Sep 2020 11:45:47 +0100 Subject: [PATCH 07/33] Register cmake3 as alternative for cmake --- .github/workflows/python.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 2f35f3d..43fa84f 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -24,6 +24,11 @@ jobs: - name: Install OpenMC run: | yum install -y gcc-c++ cmake3 hdf5-devel + alternatives --install /usr/local/bin/cmake cmake /usr/bin/cmake3 20 \ + --slave /usr/local/bin/ctest ctest /usr/bin/ctest3 \ + --slave /usr/local/bin/cpack cpack /usr/bin/cpack3 \ + --slave /usr/local/bin/ccmake ccmake /usr/bin/ccmake3 \ + --family cmake git clone --recurse-submodules https://github.com/openmc-dev/openmc.git cd openmc git checkout From b404fd39ee7fff01fc782e60a7e73b2d132bbe49 Mon Sep 17 00:00:00 2001 From: Dan Short Date: Thu, 24 Sep 2020 11:57:00 +0100 Subject: [PATCH 08/33] Run pip as a python module --- .github/workflows/python.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 43fa84f..2847721 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -38,7 +38,7 @@ jobs: make install - name: Install plasma source run: | - pip install -r requirements-develop.txt + python -m pip install -r requirements-develop.txt python setup.py bdist_wheel python -m pip install --verbose dist/*.whl - name: Run tests From a4c46d8b0ba5a893a619eb5fc29bf149148d9128 Mon Sep 17 00:00:00 2001 From: Dan Short Date: Thu, 24 Sep 2020 18:24:10 +0100 Subject: [PATCH 09/33] Use manylinux installed python --- .github/workflows/python.yml | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 2847721..e1644c1 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -17,10 +17,6 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - name: Install OpenMC run: | yum install -y gcc-c++ cmake3 hdf5-devel @@ -38,14 +34,16 @@ jobs: make install - name: Install plasma source run: | + export PYVER=${{ matrix.python-version }} + alias python=$(ls -d /opt/python/* | grep ${PYVER//.})/bin/python python -m pip install -r requirements-develop.txt - python setup.py bdist_wheel - python -m pip install --verbose dist/*.whl + python -m pip wheel . + python -m pip install --verbose wheelhouse/*.whl - name: Run tests run: | - pytest tests + python -m pytest tests - name: Upload wheel artifact uses: actions/upload-artifact@v2 with: name: dist - path: dist + path: wheelhouse From 494abf5d474dae280b8e8e722bf1733afb3269d2 Mon Sep 17 00:00:00 2001 From: Dan Short Date: Thu, 24 Sep 2020 18:40:20 +0100 Subject: [PATCH 10/33] Install auditwheel and repair --- .github/workflows/python.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index e1644c1..8110a5c 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -37,7 +37,10 @@ jobs: export PYVER=${{ matrix.python-version }} alias python=$(ls -d /opt/python/* | grep ${PYVER//.})/bin/python python -m pip install -r requirements-develop.txt - python -m pip wheel . + python -m pip install auditwheel + python setup.py bdist_wheel + python -m auditwheel show dist/*.whl + python -m auditwheel repair dist/*.whl python -m pip install --verbose wheelhouse/*.whl - name: Run tests run: | From 90a2b40ef6a5adb39448bebb4b9f4c51bd76ad9e Mon Sep 17 00:00:00 2001 From: Dan Short Date: Thu, 24 Sep 2020 18:53:23 +0100 Subject: [PATCH 11/33] Test to determine which python is used for test --- .github/workflows/python.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 8110a5c..743207c 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -44,6 +44,7 @@ jobs: python -m pip install --verbose wheelhouse/*.whl - name: Run tests run: | + which python python -m pytest tests - name: Upload wheel artifact uses: actions/upload-artifact@v2 From d83d4cd078986869da73c0bb7a587d633575f319 Mon Sep 17 00:00:00 2001 From: Dan Short Date: Fri, 25 Sep 2020 08:14:12 +0100 Subject: [PATCH 12/33] Use correct python version for tests --- .github/workflows/python.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 743207c..f52ea14 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -44,7 +44,8 @@ jobs: python -m pip install --verbose wheelhouse/*.whl - name: Run tests run: | - which python + export PYVER=${{ matrix.python-version }} + alias python=$(ls -d /opt/python/* | grep ${PYVER//.})/bin/python python -m pytest tests - name: Upload wheel artifact uses: actions/upload-artifact@v2 From 037f1b1d316ac20614395a991c102f3134e84861 Mon Sep 17 00:00:00 2001 From: Dan Short Date: Fri, 25 Sep 2020 08:45:41 +0100 Subject: [PATCH 13/33] Run tests from within tests directory Ensures we use the installed version of the package --- .github/workflows/python.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index f52ea14..044f755 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -46,7 +46,8 @@ jobs: run: | export PYVER=${{ matrix.python-version }} alias python=$(ls -d /opt/python/* | grep ${PYVER//.})/bin/python - python -m pytest tests + cd tests + python -m pytest - name: Upload wheel artifact uses: actions/upload-artifact@v2 with: From c3e9ebe86404ab58bbe4bfc66920c3a576b16ba5 Mon Sep 17 00:00:00 2001 From: Dan Short Date: Fri, 25 Sep 2020 08:57:08 +0100 Subject: [PATCH 14/33] Support Python 3.9 --- .github/workflows/python.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 044f755..3ad3288 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -13,7 +13,7 @@ jobs: container: quay.io/pypa/manylinux2014_x86_64 strategy: matrix: - python-version: [3.6, 3.7, 3.8] + python-version: [3.6, 3.7, 3.8, 3.9] steps: - uses: actions/checkout@v2 From 1883ec679bb08794a4449724c020e831b493973e Mon Sep 17 00:00:00 2001 From: Dan Short Date: Fri, 25 Sep 2020 09:11:34 +0100 Subject: [PATCH 15/33] Publish wheel to test PyPI --- .github/workflows/python.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 3ad3288..41c6de4 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -53,3 +53,12 @@ jobs: with: name: dist path: wheelhouse + - name: Publish wheel artifact + env: + TWINE_USERNAME: ${{ secrets.TEST_PYPI_USERNAME }} + TWINE_PASSWORD: ${{ secrets.TEST_PYPI_PASSWORD }} + run: | + export PYVER=${{ matrix.python-version }} + alias python=$(ls -d /opt/python/* | grep ${PYVER//.})/bin/python + python -m pip install twine + python -m twine upload --repository testpypi wheelhouse/* From c54d596d97c175592511cdc742a0f44946ee3639 Mon Sep 17 00:00:00 2001 From: Dan Short Date: Fri, 25 Sep 2020 09:12:52 +0100 Subject: [PATCH 16/33] Fix indentation --- .github/workflows/python.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 41c6de4..5e352c8 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -57,7 +57,7 @@ jobs: env: TWINE_USERNAME: ${{ secrets.TEST_PYPI_USERNAME }} TWINE_PASSWORD: ${{ secrets.TEST_PYPI_PASSWORD }} - run: | + run: | export PYVER=${{ matrix.python-version }} alias python=$(ls -d /opt/python/* | grep ${PYVER//.})/bin/python python -m pip install twine From 6e66b5227f421639213c307b6e3c0a7d55d4ca5a Mon Sep 17 00:00:00 2001 From: Dan Short Date: Fri, 25 Sep 2020 09:27:30 +0100 Subject: [PATCH 17/33] Don't upload to TestPyPI for now Avoids having to re-version on each push --- .github/workflows/python.yml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 5e352c8..3ad3288 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -53,12 +53,3 @@ jobs: with: name: dist path: wheelhouse - - name: Publish wheel artifact - env: - TWINE_USERNAME: ${{ secrets.TEST_PYPI_USERNAME }} - TWINE_PASSWORD: ${{ secrets.TEST_PYPI_PASSWORD }} - run: | - export PYVER=${{ matrix.python-version }} - alias python=$(ls -d /opt/python/* | grep ${PYVER//.})/bin/python - python -m pip install twine - python -m twine upload --repository testpypi wheelhouse/* From 8144f7779b12f3dcf0bdfb36c6711126fc6de171 Mon Sep 17 00:00:00 2001 From: Dan Short Date: Mon, 28 Sep 2020 11:34:55 +0100 Subject: [PATCH 18/33] Generate version from git tags and commits Formats the version in a way that handles Python versioning standard (PEP 440) by appending the number of commits since the last tag to a dev pre-release identifier. Allows override if release not yet found (we don't have tags yet). --- setup.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index ede8bd3..7aa85a0 100644 --- a/setup.py +++ b/setup.py @@ -58,12 +58,35 @@ def build_extension(self, ext): ) +def get_version(release_override="0.0.1"): + cwd = os.path.dirname(os.path.realpath(__file__)) + version = subprocess.check_output( + ["git", "describe", "--always", "--tags"], stderr=None, cwd=cwd + ).strip().decode("utf-8") + if "." not in version: + # Git doesn't know about a tag yet, so manually set a version and get the total + # number of commits + num_commits = subprocess.check_output( + ["git", "rev-list", "--count", "HEAD"], stderr=None, cwd=cwd + ).strip().decode("utf-8") + version = release_override + ".dev" + num_commits + else: + if "-" in version: + # This commit doesn't correspond to an annotated tag, so mark it as dev and + # get the number of commits since the last annotated tag + version_split = version.split("-") + tag_version = version_split[0] + num_commits = version_split[1] + version = tag_version + ".dev" + num_commits + return version + + with open("README.md", "r") as fh: long_description = fh.read() setup( name="parametric_plasma_source", - version="0.0.6", + version=get_version("0.0.6"), author="Andrew Davis", author_email="jonathan.shimwell@ukaea.uk", description="Parametric plasma source for fusion simulations in OpenMC", From 7e499ad6b4ee043b87b6a930e4d8bb77c2c24093 Mon Sep 17 00:00:00 2001 From: Dan Short Date: Mon, 28 Sep 2020 12:07:24 +0100 Subject: [PATCH 19/33] Refactor actions and include publish to PyPI --- .github/workflows/python.yml | 60 ++++++++++++++++++++++++++++++------ 1 file changed, 51 insertions(+), 9 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 3ad3288..39001fa 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -7,7 +7,7 @@ on: branches: [ master ] jobs: - build_and_test: + build: runs-on: ubuntu-latest container: quay.io/pypa/manylinux2014_x86_64 @@ -32,7 +32,7 @@ jobs: cmake .. make make install - - name: Install plasma source + - name: Build plasma source run: | export PYVER=${{ matrix.python-version }} alias python=$(ls -d /opt/python/* | grep ${PYVER//.})/bin/python @@ -41,15 +41,57 @@ jobs: python setup.py bdist_wheel python -m auditwheel show dist/*.whl python -m auditwheel repair dist/*.whl - python -m pip install --verbose wheelhouse/*.whl - - name: Run tests - run: | - export PYVER=${{ matrix.python-version }} - alias python=$(ls -d /opt/python/* | grep ${PYVER//.})/bin/python - cd tests - python -m pytest - name: Upload wheel artifact uses: actions/upload-artifact@v2 with: name: dist path: wheelhouse + + test: + runs-on: ubuntu-latest + needs: build + strategy: + matrix: + python-version: [3.6, 3.7, 3.8, 3.9] + + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + -name: Download build + uses: actions/download-artifact@v2 + with: + name: dist + - name: Install plasma source + python -m pip install --no-index --find-links=file:dist parametric-plasma-source + - name: Run tests + run: | + python -m pip install -r requirements-develop.txt + cd tests + python -m pytest + + publish: + runs-on: ubuntu-latest + needs: test + + - name: Publish wheel artifact to TestPyPI + env: + TWINE_USERNAME: ${{ secrets.TEST_PYPI_USERNAME }} + TWINE_PASSWORD: ${{ secrets.TEST_PYPI_PASSWORD }} + run: | + export PYVER=${{ matrix.python-version }} + alias python=$(ls -d /opt/python/* | grep ${PYVER//.})/bin/python + python -m pip install twine + python -m twine upload --repository testpypi wheelhouse/* + - name: Release wheel artifact to PyPI + if: startsWith(github.ref, 'refs/tags') + env: + TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} + TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + run: | + export PYVER=${{ matrix.python-version }} + alias python=$(ls -d /opt/python/* | grep ${PYVER//.})/bin/python + python -m pip install twine + python -m twine upload wheelhouse/* From 9b2ecf2d04760e4ff754339059fcc77ce9f4f3a8 Mon Sep 17 00:00:00 2001 From: Dan Short Date: Mon, 28 Sep 2020 12:08:51 +0100 Subject: [PATCH 20/33] Fix yaml syntax error --- .github/workflows/python.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 39001fa..61f5cea 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -60,7 +60,7 @@ jobs: uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - -name: Download build + - name: Download build uses: actions/download-artifact@v2 with: name: dist From 319d3617fdf31626eed004f7766924858bcbf398 Mon Sep 17 00:00:00 2001 From: Dan Short Date: Mon, 28 Sep 2020 12:10:45 +0100 Subject: [PATCH 21/33] Add missing steps identifier --- .github/workflows/python.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 61f5cea..406a30d 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -76,6 +76,7 @@ jobs: runs-on: ubuntu-latest needs: test + steps: - name: Publish wheel artifact to TestPyPI env: TWINE_USERNAME: ${{ secrets.TEST_PYPI_USERNAME }} From ada610aea3f676b1a4fccf7c2c7b4bc842e5be88 Mon Sep 17 00:00:00 2001 From: Dan Short Date: Mon, 28 Sep 2020 12:12:08 +0100 Subject: [PATCH 22/33] Add missing run identifier --- .github/workflows/python.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 406a30d..137ced4 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -65,6 +65,7 @@ jobs: with: name: dist - name: Install plasma source + run: | python -m pip install --no-index --find-links=file:dist parametric-plasma-source - name: Run tests run: | From a8109aa173eba380131fb89663ecbe2b55f087f8 Mon Sep 17 00:00:00 2001 From: Dan Short Date: Mon, 28 Sep 2020 13:01:13 +0100 Subject: [PATCH 23/33] Action not finding artifact after download --- .github/workflows/python.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 137ced4..9dfc2d1 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -64,8 +64,10 @@ jobs: uses: actions/download-artifact@v2 with: name: dist + path: dist - name: Install plasma source run: | + ls -la python -m pip install --no-index --find-links=file:dist parametric-plasma-source - name: Run tests run: | From 4feb6f31c3330842d1b020d52aab35820c86b479 Mon Sep 17 00:00:00 2001 From: Dan Short Date: Mon, 28 Sep 2020 13:22:17 +0100 Subject: [PATCH 24/33] GitHub doesn't have 3.9 installed Also fix publish commands --- .github/workflows/python.yml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 9dfc2d1..a9b0626 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -13,7 +13,7 @@ jobs: container: quay.io/pypa/manylinux2014_x86_64 strategy: matrix: - python-version: [3.6, 3.7, 3.8, 3.9] + python-version: [3.6, 3.7, 3.8] steps: - uses: actions/checkout@v2 @@ -52,7 +52,7 @@ jobs: needs: build strategy: matrix: - python-version: [3.6, 3.7, 3.8, 3.9] + python-version: [3.6, 3.7, 3.8] steps: - uses: actions/checkout@v2 @@ -67,7 +67,6 @@ jobs: path: dist - name: Install plasma source run: | - ls -la python -m pip install --no-index --find-links=file:dist parametric-plasma-source - name: Run tests run: | @@ -80,22 +79,23 @@ jobs: needs: test steps: + - name: Download build + uses: actions/download-artifact@v2 + with: + name: dist + path: dist - name: Publish wheel artifact to TestPyPI env: TWINE_USERNAME: ${{ secrets.TEST_PYPI_USERNAME }} TWINE_PASSWORD: ${{ secrets.TEST_PYPI_PASSWORD }} run: | - export PYVER=${{ matrix.python-version }} - alias python=$(ls -d /opt/python/* | grep ${PYVER//.})/bin/python - python -m pip install twine - python -m twine upload --repository testpypi wheelhouse/* + python3 -m pip install twine + python3 -m twine upload --repository testpypi dist/* - name: Release wheel artifact to PyPI if: startsWith(github.ref, 'refs/tags') env: TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} run: | - export PYVER=${{ matrix.python-version }} - alias python=$(ls -d /opt/python/* | grep ${PYVER//.})/bin/python - python -m pip install twine - python -m twine upload wheelhouse/* + python3 -m pip install twine + python3 -m twine upload dist/* From b943a17ce3f930ebfdc505ceb1b3115d6545d998 Mon Sep 17 00:00:00 2001 From: Dan Short Date: Mon, 28 Sep 2020 15:07:11 +0100 Subject: [PATCH 25/33] Add some log messages when creating version --- setup.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/setup.py b/setup.py index 7aa85a0..9dc2049 100644 --- a/setup.py +++ b/setup.py @@ -69,6 +69,10 @@ def get_version(release_override="0.0.1"): num_commits = subprocess.check_output( ["git", "rev-list", "--count", "HEAD"], stderr=None, cwd=cwd ).strip().decode("utf-8") + print( + f"Creating version with overridden release tag = {release_override} " + f"and num commits = {num_commits}" + ) version = release_override + ".dev" + num_commits else: if "-" in version: @@ -77,7 +81,12 @@ def get_version(release_override="0.0.1"): version_split = version.split("-") tag_version = version_split[0] num_commits = version_split[1] + print( + f"Creating version with overridden tag = {tag_version} " + f"and num commits = {num_commits}" + ) version = tag_version + ".dev" + num_commits + print(f"Using version = {version}") return version From a76d50c26b08ac7bff05654c38a80427c518c26e Mon Sep 17 00:00:00 2001 From: Dan Short Date: Mon, 28 Sep 2020 15:25:28 +0100 Subject: [PATCH 26/33] Get full repo history so we know number of commits --- .github/workflows/python.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index a9b0626..6453362 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -17,6 +17,8 @@ jobs: steps: - uses: actions/checkout@v2 + with: + fetch-depth: 0 # Get the repo history so we can version by number of commits - name: Install OpenMC run: | yum install -y gcc-c++ cmake3 hdf5-devel From 51690614199c9476fd11ef429e73bbcb72a5e209 Mon Sep 17 00:00:00 2001 From: Dan Short Date: Mon, 28 Sep 2020 15:44:48 +0100 Subject: [PATCH 27/33] Use post as the version extension This allows TestPyPI to understand the ordering of versions. --- setup.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/setup.py b/setup.py index 9dc2049..556eac1 100644 --- a/setup.py +++ b/setup.py @@ -69,24 +69,15 @@ def get_version(release_override="0.0.1"): num_commits = subprocess.check_output( ["git", "rev-list", "--count", "HEAD"], stderr=None, cwd=cwd ).strip().decode("utf-8") - print( - f"Creating version with overridden release tag = {release_override} " - f"and num commits = {num_commits}" - ) - version = release_override + ".dev" + num_commits + version = release_override + ".post" + num_commits else: if "-" in version: - # This commit doesn't correspond to an annotated tag, so mark it as dev and + # This commit doesn't correspond to an annotated tag, so mark it as post and # get the number of commits since the last annotated tag version_split = version.split("-") tag_version = version_split[0] num_commits = version_split[1] - print( - f"Creating version with overridden tag = {tag_version} " - f"and num commits = {num_commits}" - ) - version = tag_version + ".dev" + num_commits - print(f"Using version = {version}") + version = tag_version + ".post" + num_commits return version From f01ed2365d8aa68684544d9dc3f079ac72ce05a2 Mon Sep 17 00:00:00 2001 From: Dan Short Date: Mon, 28 Sep 2020 16:29:09 +0100 Subject: [PATCH 28/33] Verbose twine output --- .github/workflows/python.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 6453362..5a8edf9 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -92,7 +92,7 @@ jobs: TWINE_PASSWORD: ${{ secrets.TEST_PYPI_PASSWORD }} run: | python3 -m pip install twine - python3 -m twine upload --repository testpypi dist/* + python3 -m twine upload --repository testpypi dist/* --verbose - name: Release wheel artifact to PyPI if: startsWith(github.ref, 'refs/tags') env: @@ -100,4 +100,4 @@ jobs: TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} run: | python3 -m pip install twine - python3 -m twine upload dist/* + python3 -m twine upload dist/* --verbose From eb070b6900eab36ec36a71aba3809b978825f594 Mon Sep 17 00:00:00 2001 From: Dan Short Date: Wed, 30 Sep 2020 15:08:27 +0100 Subject: [PATCH 29/33] Run workflow when a release is created --- .github/workflows/python.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 5a8edf9..b045bde 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -5,6 +5,9 @@ on: branches: [ master ] pull_request: branches: [ master ] + release: + types: + - created jobs: build: From 952ff27a91b1ff31cc5d137755516fcf813e1df8 Mon Sep 17 00:00:00 2001 From: Dan Short Date: Wed, 30 Sep 2020 15:08:43 +0100 Subject: [PATCH 30/33] Don't reinstall twine --- .github/workflows/python.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index b045bde..d08b6ec 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -102,5 +102,4 @@ jobs: TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} run: | - python3 -m pip install twine python3 -m twine upload dist/* --verbose From acaff6e15e09495b8c3da841a6bfd4acdcee9ef0 Mon Sep 17 00:00:00 2001 From: Dan Short Date: Wed, 30 Sep 2020 15:12:49 +0100 Subject: [PATCH 31/33] Check TestPyPI and PyPI versions This should be more robust than just using git e.g. if two PRs are worked on simultaneously. --- requirements-develop.txt | 1 + setup.py | 75 ++++++++++++++++++++++++++++++++-------- 2 files changed, 61 insertions(+), 15 deletions(-) diff --git a/requirements-develop.txt b/requirements-develop.txt index 763b67d..50344e4 100644 --- a/requirements-develop.txt +++ b/requirements-develop.txt @@ -1,4 +1,5 @@ black flake8 pytest +requests wheel diff --git a/setup.py b/setup.py index 556eac1..cec54a1 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,6 @@ +import json import os +import requests import subprocess import sys @@ -59,25 +61,68 @@ def build_extension(self, ext): def get_version(release_override="0.0.1"): + def get_last_version_root(last_version): + if ".post" in last_version or ".dev" in last_version: + last_version_root = ".".join(last_version.split(".")[:-1]) + else: + last_version_root = last_version + return last_version_root + cwd = os.path.dirname(os.path.realpath(__file__)) - version = subprocess.check_output( + git_version = subprocess.check_output( ["git", "describe", "--always", "--tags"], stderr=None, cwd=cwd ).strip().decode("utf-8") - if "." not in version: - # Git doesn't know about a tag yet, so manually set a version and get the total - # number of commits - num_commits = subprocess.check_output( - ["git", "rev-list", "--count", "HEAD"], stderr=None, cwd=cwd - ).strip().decode("utf-8") - version = release_override + ".post" + num_commits + + if "." not in git_version: + # Git doesn't know about a tag yet, so set the version root to release_override + version_root = release_override + else: + version_root = git_version.split("-")[0] + + if "." not in git_version or "-" in git_version: + # This commit doesn't correspond to a tag, so mark it as post or dev + response = requests.get( + "https://test.pypi.org/pypi/parametric-plasma-source/json" + ) + if response.status_code == 200: + # Response from TestPyPI was successful - get latest version and increment + last_version = json.loads(response.content)["info"]["version"] + last_version_root = get_last_version_root(last_version) + + if last_version_root == version_root: + # We're still on the same released version, so increment the 'post' + post_count = 1 + if "post" in last_version: + post_index = last_version.rfind("post") + 4 + post_count = int(last_version[post_index:]) + post_count += 1 + version = version_root + ".post" + str(post_count) + else: + response = requests.get( + "https://pypi.org/pypi/parametric-plasma-source/json" + ) + dev_count = 1 + if response.status_code == 200: + # Response from PyPI was successful - get dev version and increment + last_version = json.loads(response.content)["info"]["version"] + last_version_root = get_last_version_root(last_version) + + if last_version_root == version_root: + if "dev" in last_version: + dev_index = last_version.rfind("dev") + 3 + dev_count = int(last_version[dev_index:]) + dev_count += 1 + version = version_root + ".dev" + str(dev_count) + else: + # Bad response from TestPyPI, so use git commits (requires git history) + # NOTE: May cause version clashes on mutliple branches - use test.pypi + # to avoid this. + num_commits = subprocess.check_output( + ["git", "rev-list", "--count", "HEAD"], stderr=None, cwd=cwd + ).strip().decode("utf-8") + version = release_override + ".post" + num_commits else: - if "-" in version: - # This commit doesn't correspond to an annotated tag, so mark it as post and - # get the number of commits since the last annotated tag - version_split = version.split("-") - tag_version = version_split[0] - num_commits = version_split[1] - version = tag_version + ".post" + num_commits + version = version_root return version From 8a21eb9031d8e7b88872a36c0272390dcc5ceb54 Mon Sep 17 00:00:00 2001 From: Dan Short Date: Wed, 30 Sep 2020 15:56:11 +0100 Subject: [PATCH 32/33] Use same account for PyPI and TestPyPI --- .github/workflows/python.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index d08b6ec..d462da3 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -91,8 +91,8 @@ jobs: path: dist - name: Publish wheel artifact to TestPyPI env: - TWINE_USERNAME: ${{ secrets.TEST_PYPI_USERNAME }} - TWINE_PASSWORD: ${{ secrets.TEST_PYPI_PASSWORD }} + TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} + TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} run: | python3 -m pip install twine python3 -m twine upload --repository testpypi dist/* --verbose From e866b3ed16030d3aa036af3d4f61742424c0d2da Mon Sep 17 00:00:00 2001 From: Dan Short Date: Wed, 30 Sep 2020 16:14:19 +0100 Subject: [PATCH 33/33] trigger GitHub actions