Skip to content

Commit

Permalink
Merge pull request #10 from open-radiation-sources/develop
Browse files Browse the repository at this point in the history
update of main with new pip installer
  • Loading branch information
shimwell authored Nov 4, 2020
2 parents 143d3b3 + 9882a56 commit 924d23f
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 15 deletions.
88 changes: 74 additions & 14 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,104 @@ name: python_package

on:
push:
branches: [ master ]
branches: [ main, develop ]
pull_request:
branches: [ master ]
branches: [ main, develop ]
release:
types:
- created

jobs:
build_and_test:
build:

runs-on: ubuntu-latest
container: quay.io/pypa/manylinux2014_x86_64
strategy:
matrix:
python-version: [3.6, 3.7, 3.8]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
fetch-depth: 0 # Get the repo history so we can version by number of commits
- name: Install OpenMC
run: |
sudo apt-get install -y g++ cmake libhdf5-dev
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
mkdir build && cd build
cmake ..
make
sudo make install
- name: Install plasma source
make install
- name: Build plasma source
run: |
pip install -r requirements-develop.txt
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 install auditwheel
python setup.py bdist_wheel
python -m pip install --verbose dist/*.whl
- name: Run tests
run: |
pytest tests
python -m auditwheel show dist/*.whl
python -m auditwheel repair dist/*.whl
- 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]

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
path: dist
- name: Install plasma source
run: |
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

steps:
- name: Download build
uses: actions/download-artifact@v2
with:
name: dist
path: dist
- name: Publish wheel artifact to TestPyPI
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python3 -m pip install twine
python3 -m twine upload --repository testpypi dist/* --verbose
- name: Release wheel artifact to PyPI
if: startsWith(github.ref, 'refs/tags')
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python3 -m twine upload dist/* --verbose
1 change: 1 addition & 0 deletions requirements-develop.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
black
flake8
pytest
requests
wheel
70 changes: 69 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import json
import os
import requests
import subprocess
import sys

Expand Down Expand Up @@ -58,12 +60,78 @@ 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__))
git_version = subprocess.check_output(
["git", "describe", "--always", "--tags"], stderr=None, cwd=cwd
).strip().decode("utf-8")

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:
version = version_root
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="[email protected]",
description="Parametric plasma source for fusion simulations in OpenMC",
Expand Down

0 comments on commit 924d23f

Please sign in to comment.