From bf7e4b76cd43e4da16cac69b844b0e7cf0477a92 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 e81fb20..c86a5ff 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 90288367828f66a7695c3c4dfa40b5e9d7e59f1e 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 c86a5ff..a4410fd 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 1448b2f1751ddc6fd2223a30aeebd83f9dedc562 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 a4410fd..1c693ab 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 828192d9743a76b13859aaccd323efe4c9e516d9 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 1c693ab..73d001a 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 35c641bfaee8d8d014d6c8c5f927f5a879579831 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 73d001a..64239ca 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 3ac1f98fc267305521d91e4ff4671bc7735f07d3 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 64239ca..e18b946 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 7e71022bf4e6e3fa32bc1c58a3f273b7acd8b436 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 e18b946..7aba6b9 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 0957ca469240719c2e87e76b61f2fd197ecff289 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 7aba6b9..0c0d59d 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 15529f2a29d17ffbe3b01d37158bca90c0b914a7 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 0c0d59d..b66b231 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 fa4a489b6d1df93ac9d3054cea0f2e2f2a56c010 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 b66b231..e7c0e1f 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 0291ab555aea471bf6085aa88480a52e01e6758b 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 e7c0e1f..a77a3e2 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 b65c7382bb53af1bdb2e35544a7ab0908687724a 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 a77a3e2..9ff57b0 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 ff643923665d3381a463ba0c1e8a3bba0b67fdeb 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 9ff57b0..ea83746 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 0962c37ab98c1c3084585ca54a19f120496f2740 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 ea83746..d7d3bba 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 89798faefc11015a401aeae11c161ffa4ee34070 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 d7d3bba..2f64db5 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 0760dccc4f7c2a5a981d1d8dba4b038fb329316d 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 2f64db5..a498a38 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 9537440137b86d7951dad07a0903e53aa7b12c7d 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 a498a38..d7d3bba 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 adb71af18eb0013308e88b2df2c391d4413d5e99 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 e1ffea9b44c6733934f24dd07f1e5cf40bdcda16 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 d7d3bba..d151a80 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 1c7db261ce048cd05d7f4fb70762dbdd0ef486bc 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 d151a80..0b030e8 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 20360325116b4a535415963f5466a7e854adc2ec 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 0b030e8..a0ccc9f 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 3478b537d99f54aa71d90ef8295cc904204ffa1a 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 a0ccc9f..c4a0ce7 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 7ded7c2e396467674bc169a9e339c2ad8530e605 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 c4a0ce7..ff12968 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 027557b19f3618992585068385eb0de083f2b4d0 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 ff12968..6cc4d6a 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 335f23783ec6f6906c141cbe3ab3aa3c799858e1 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 6d9cb9a6a2d5bb768406f837ea35c122630c9023 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 6cc4d6a..b6c10b4 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 538577138f06483f8c53f42728bb9e1e36ee8421 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 13849913e57d3c77736f25d792bd5e87418654b2 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 b6c10b4..c4328ae 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 d3023d1859118714701a51321e1e61bb1b152998 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 c4328ae..1aeca7a 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 8d62d309b8e877e6073b25a858615af918ee1c5b 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 1aeca7a..7d65f23 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 3d306593d4fdf66409b74f9a10c61b1ead538116 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 41aa9ec16575c0eb3f6a146492c93494cb519528 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 7d65f23..bc8cbf5 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 bb4cdaa049265cfcbe54e2d09a3172fe3baa9190 Mon Sep 17 00:00:00 2001 From: Dan Short Date: Thu, 29 Oct 2020 19:24:53 +0000 Subject: [PATCH 33/33] Use new branch names for CI --- .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 e81fb20..3e34105 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -2,9 +2,9 @@ name: python_package on: push: - branches: [ master ] + branches: [ main, develop ] pull_request: - branches: [ master ] + branches: [ main, develop ] jobs: build_and_test: