Skip to content

Commit 924d23f

Browse files
authored
Merge pull request #10 from open-radiation-sources/develop
update of main with new pip installer
2 parents 143d3b3 + 9882a56 commit 924d23f

File tree

3 files changed

+144
-15
lines changed

3 files changed

+144
-15
lines changed

.github/workflows/python.yml

Lines changed: 74 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,104 @@ name: python_package
22

33
on:
44
push:
5-
branches: [ master ]
5+
branches: [ main, develop ]
66
pull_request:
7-
branches: [ master ]
7+
branches: [ main, develop ]
8+
release:
9+
types:
10+
- created
811

912
jobs:
10-
build_and_test:
13+
build:
1114

1215
runs-on: ubuntu-latest
16+
container: quay.io/pypa/manylinux2014_x86_64
1317
strategy:
1418
matrix:
1519
python-version: [3.6, 3.7, 3.8]
1620

1721
steps:
1822
- uses: actions/checkout@v2
19-
- name: Set up Python ${{ matrix.python-version }}
20-
uses: actions/setup-python@v2
2123
with:
22-
python-version: ${{ matrix.python-version }}
24+
fetch-depth: 0 # Get the repo history so we can version by number of commits
2325
- name: Install OpenMC
2426
run: |
25-
sudo apt-get install -y g++ cmake libhdf5-dev
27+
yum install -y gcc-c++ cmake3 hdf5-devel
28+
alternatives --install /usr/local/bin/cmake cmake /usr/bin/cmake3 20 \
29+
--slave /usr/local/bin/ctest ctest /usr/bin/ctest3 \
30+
--slave /usr/local/bin/cpack cpack /usr/bin/cpack3 \
31+
--slave /usr/local/bin/ccmake ccmake /usr/bin/ccmake3 \
32+
--family cmake
2633
git clone --recurse-submodules https://github.com/openmc-dev/openmc.git
2734
cd openmc
2835
git checkout
2936
mkdir build && cd build
3037
cmake ..
3138
make
32-
sudo make install
33-
- name: Install plasma source
39+
make install
40+
- name: Build plasma source
3441
run: |
35-
pip install -r requirements-develop.txt
42+
export PYVER=${{ matrix.python-version }}
43+
alias python=$(ls -d /opt/python/* | grep ${PYVER//.})/bin/python
44+
python -m pip install -r requirements-develop.txt
45+
python -m pip install auditwheel
3646
python setup.py bdist_wheel
37-
python -m pip install --verbose dist/*.whl
38-
- name: Run tests
39-
run: |
40-
pytest tests
47+
python -m auditwheel show dist/*.whl
48+
python -m auditwheel repair dist/*.whl
4149
- name: Upload wheel artifact
4250
uses: actions/upload-artifact@v2
51+
with:
52+
name: dist
53+
path: wheelhouse
54+
55+
test:
56+
runs-on: ubuntu-latest
57+
needs: build
58+
strategy:
59+
matrix:
60+
python-version: [3.6, 3.7, 3.8]
61+
62+
steps:
63+
- uses: actions/checkout@v2
64+
- name: Set up Python ${{ matrix.python-version }}
65+
uses: actions/setup-python@v2
66+
with:
67+
python-version: ${{ matrix.python-version }}
68+
- name: Download build
69+
uses: actions/download-artifact@v2
70+
with:
71+
name: dist
72+
path: dist
73+
- name: Install plasma source
74+
run: |
75+
python -m pip install --no-index --find-links=file:dist parametric-plasma-source
76+
- name: Run tests
77+
run: |
78+
python -m pip install -r requirements-develop.txt
79+
cd tests
80+
python -m pytest
81+
82+
publish:
83+
runs-on: ubuntu-latest
84+
needs: test
85+
86+
steps:
87+
- name: Download build
88+
uses: actions/download-artifact@v2
4389
with:
4490
name: dist
4591
path: dist
92+
- name: Publish wheel artifact to TestPyPI
93+
env:
94+
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
95+
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
96+
run: |
97+
python3 -m pip install twine
98+
python3 -m twine upload --repository testpypi dist/* --verbose
99+
- name: Release wheel artifact to PyPI
100+
if: startsWith(github.ref, 'refs/tags')
101+
env:
102+
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
103+
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
104+
run: |
105+
python3 -m twine upload dist/* --verbose

requirements-develop.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
black
22
flake8
33
pytest
4+
requests
45
wheel

setup.py

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import json
12
import os
3+
import requests
24
import subprocess
35
import sys
46

@@ -58,12 +60,78 @@ def build_extension(self, ext):
5860
)
5961

6062

63+
def get_version(release_override="0.0.1"):
64+
def get_last_version_root(last_version):
65+
if ".post" in last_version or ".dev" in last_version:
66+
last_version_root = ".".join(last_version.split(".")[:-1])
67+
else:
68+
last_version_root = last_version
69+
return last_version_root
70+
71+
cwd = os.path.dirname(os.path.realpath(__file__))
72+
git_version = subprocess.check_output(
73+
["git", "describe", "--always", "--tags"], stderr=None, cwd=cwd
74+
).strip().decode("utf-8")
75+
76+
if "." not in git_version:
77+
# Git doesn't know about a tag yet, so set the version root to release_override
78+
version_root = release_override
79+
else:
80+
version_root = git_version.split("-")[0]
81+
82+
if "." not in git_version or "-" in git_version:
83+
# This commit doesn't correspond to a tag, so mark it as post or dev
84+
response = requests.get(
85+
"https://test.pypi.org/pypi/parametric-plasma-source/json"
86+
)
87+
if response.status_code == 200:
88+
# Response from TestPyPI was successful - get latest version and increment
89+
last_version = json.loads(response.content)["info"]["version"]
90+
last_version_root = get_last_version_root(last_version)
91+
92+
if last_version_root == version_root:
93+
# We're still on the same released version, so increment the 'post'
94+
post_count = 1
95+
if "post" in last_version:
96+
post_index = last_version.rfind("post") + 4
97+
post_count = int(last_version[post_index:])
98+
post_count += 1
99+
version = version_root + ".post" + str(post_count)
100+
else:
101+
response = requests.get(
102+
"https://pypi.org/pypi/parametric-plasma-source/json"
103+
)
104+
dev_count = 1
105+
if response.status_code == 200:
106+
# Response from PyPI was successful - get dev version and increment
107+
last_version = json.loads(response.content)["info"]["version"]
108+
last_version_root = get_last_version_root(last_version)
109+
110+
if last_version_root == version_root:
111+
if "dev" in last_version:
112+
dev_index = last_version.rfind("dev") + 3
113+
dev_count = int(last_version[dev_index:])
114+
dev_count += 1
115+
version = version_root + ".dev" + str(dev_count)
116+
else:
117+
# Bad response from TestPyPI, so use git commits (requires git history)
118+
# NOTE: May cause version clashes on mutliple branches - use test.pypi
119+
# to avoid this.
120+
num_commits = subprocess.check_output(
121+
["git", "rev-list", "--count", "HEAD"], stderr=None, cwd=cwd
122+
).strip().decode("utf-8")
123+
version = release_override + ".post" + num_commits
124+
else:
125+
version = version_root
126+
return version
127+
128+
61129
with open("README.md", "r") as fh:
62130
long_description = fh.read()
63131

64132
setup(
65133
name="parametric_plasma_source",
66-
version="0.0.6",
134+
version=get_version("0.0.6"),
67135
author="Andrew Davis",
68136
author_email="jonathan.shimwell@ukaea.uk",
69137
description="Parametric plasma source for fusion simulations in OpenMC",

0 commit comments

Comments
 (0)