Skip to content

Commit 6e42f39

Browse files
authoredAug 4, 2021
Fix GHA pypi-publish and UDUNITS2 XML read (#196)
* Fix GHA pypi-publish and UDUNITS2 XML read * add publish to pypi job * turn codecov patch off
1 parent 05ed292 commit 6e42f39

File tree

10 files changed

+168
-67
lines changed

10 files changed

+168
-67
lines changed
 
+23-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,37 @@
1-
#!/bin/sh
1+
#!/usr/bin/env bash
2+
3+
trap 'echo "Aborted!"; exit 1' ERR
4+
set -e
5+
26

37
yum install -y udunits2-devel
8+
49
PYTHONS=("cp37-cp37m" "cp38-cp38" "cp39-cp39")
5-
WHEELHOUSE="/github/workspace/wheelhouse/"
10+
WHEELHOUSE="/github/workspace/wheelhouse"
11+
MANYLINUX="manylinux2014_x86_64"
12+
DISTRIBUTION="dist"
613

714
export UDUNITS2_INCDIR="/usr/include/udunits2"
815
export UDUNITS2_LIBDIR="/usr/lib64"
916
export UDUNITS2_XML_PATH="/usr/share/udunits/udunits2.xml"
1017

18+
# Create the distribution directory.
19+
mkdir ${DISTRIBUTION}
20+
21+
# Build the wheels in the wheelhouse.
1122
for PYTHON in ${PYTHONS[@]}; do
12-
/opt/python/${PYTHON}/bin/pip install --upgrade pip wheel setuptools setuptools_scm build twine auditwheel
13-
/opt/python/${PYTHON}/bin/python -m build --sdist --wheel . --outdir ${WHEELHOUSE}
23+
PYBIN="/opt/python/${PYTHON}/bin/python"
24+
${PYBIN} -m pip install --upgrade pip wheel setuptools setuptools_scm build twine auditwheel
25+
${PYBIN} -m build --wheel . --outdir ${WHEELHOUSE}
1426
done
1527

28+
# Build the sdist in the distribution.
29+
${PYBIN} -m build --sdist . --outdir ${DISTRIBUTION}
30+
31+
# Convert to manylinux wheels in the wheelhouse.
1632
for BDIST_WHEEL in ${WHEELHOUSE}/cf_units*.whl; do
1733
auditwheel repair ${BDIST_WHEEL}
1834
done
35+
36+
# Populate distribution with the manylinux wheels.
37+
cp ${WHEELHOUSE}/cf_units*${MANYLINUX}.whl ${DISTRIBUTION}

‎.github/workflows/actions/manylinux2010_x86_64/action.yml

-7
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name: 'build wheels with manylinux2014_x86_64'
2+
description: 'build wheels with manylinux2014_x86_64'
3+
runs:
4+
using: 'docker'
5+
image: docker://quay.io/pypa/manylinux2014_x86_64
6+
args:
7+
- .github/workflows/actions/entrypoint.sh

‎.github/workflows/build_linux.yml

-40
This file was deleted.

‎.github/workflows/pypi_publish.yml

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
name: pypi-publish
2+
3+
on:
4+
release:
5+
types:
6+
- published
7+
8+
jobs:
9+
build-artifacts:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
14+
- name: Get tags
15+
shell: bash
16+
run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
17+
18+
- name: Build linux wheels
19+
uses: ./.github/workflows/actions/manylinux2014_x86_64
20+
21+
- name: List built artifacts
22+
shell: bash
23+
working-directory: dist
24+
run: ls
25+
26+
- name: Check built artifacts
27+
shell: bash
28+
working-directory: dist
29+
run: |
30+
python -m pip install wheel twine
31+
python -m twine check *
32+
33+
- name: Inspect built wheels
34+
shell: bash
35+
working-directory: dist
36+
run: |
37+
for WHEEL in *.whl; do
38+
echo -e "\n${WHEEL}"
39+
python -m zipfile --list ${WHEEL}
40+
done
41+
42+
- name: Upload built artifacts
43+
uses: actions/upload-artifact@v2
44+
with:
45+
name: pypi-artifacts
46+
path: dist
47+
48+
test-artifacts:
49+
needs: build-artifacts
50+
name: Test ${{ matrix.tag }} for Python ${{ matrix.python }}
51+
runs-on: ubuntu-latest
52+
strategy:
53+
matrix:
54+
python: [3.7, 3.8, 3.9]
55+
include:
56+
- python: 3.7
57+
tag: cp37-cp37m
58+
- python: 3.8
59+
tag: cp38-cp38
60+
- python: 3.9
61+
tag: cp39-cp39
62+
steps:
63+
- name: Download built artifacts
64+
uses: actions/download-artifact@v2
65+
with:
66+
name: pypi-artifacts
67+
path: dist
68+
69+
- name: Setup Python ${{ matrix.python }}
70+
uses: actions/setup-python@v2
71+
with:
72+
python-version: ${{ matrix.python }}
73+
74+
- name: Install ${{ matrix.tag }}
75+
env:
76+
TAG: ${{ matrix.tag }}
77+
shell: bash
78+
working-directory: dist
79+
run: python -m pip install cf_units-*-${TAG}-*.whl
80+
81+
- name: Test ${{ matrix.tag }}
82+
shell: bash
83+
run: |
84+
python -m pip install pytest
85+
python -m pytest --pyargs cf_units
86+
87+
publish-artifacts:
88+
needs: [build-artifacts, test-artifacts]
89+
name: Publish built artifacts to PyPI
90+
runs-on: ubuntu-latest
91+
steps:
92+
- name: Download built artifacts
93+
uses: actions/download-artifact@v2
94+
with:
95+
name: pypi-artifacts
96+
path: dist
97+
98+
- name: Publish artifacts
99+
uses: pypa/gh-action-pypi-publish@v1.4.2
100+
with:
101+
user: __token__
102+
password: ${{ secrets.PYPI_PASSWORD }}

‎cf_units/__init__.py

+1-10
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
"""
1616

1717
import copy
18-
import os.path
19-
import sys
2018
from contextlib import contextmanager
2119

2220
import cftime
@@ -187,15 +185,8 @@ def suppress_errors():
187185
try:
188186
_ud_system = _ud.read_xml()
189187
except _ud.UdunitsError:
190-
_alt_xml_path = config.get_option(
191-
"System",
192-
"udunits2_xml_path",
193-
default=os.path.join(
194-
sys.prefix, "share", "udunits", "udunits2.xml"
195-
),
196-
)
197188
try:
198-
_ud_system = _ud.read_xml(_alt_xml_path.encode())
189+
_ud_system = _ud.read_xml(config.get_xml_path())
199190
except _ud.UdunitsError as e:
200191
error_msg = ': "%s"' % e.error_msg() if e.errnum else ""
201192
raise OSError(

‎cf_units/config.py

+12
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77

88
import configparser
9+
import sys
910
from pathlib import Path
1011
from tempfile import NamedTemporaryFile
1112

@@ -23,6 +24,17 @@ def get_option(section, option, default=None):
2324
return value
2425

2526

27+
def get_xml_path():
28+
"""Return the alternative path to the UDUNITS2 XMl file"""
29+
default = Path(sys.prefix) / "share" / "udunits" / "udunits2.xml"
30+
path = get_option(
31+
"System",
32+
"udunits2_xml_path",
33+
default=str(default),
34+
)
35+
return path.encode()
36+
37+
2638
# Figure out the full path to the "cf_units" package.
2739
ROOT_PATH = Path(__file__).resolve().parent
2840

‎cf_units/tests/unit/test__udunits2.py

+19-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import numpy as np
1616

1717
from cf_units import _udunits2 as _ud
18+
from cf_units.config import get_xml_path
1819

1920
_ud.set_error_message_handler(_ud.ignore)
2021

@@ -26,7 +27,10 @@ class Test_get_system(unittest.TestCase):
2627
"""
2728

2829
def test_read_xml(self):
29-
system = _ud.read_xml()
30+
try:
31+
system = _ud.read_xml()
32+
except _ud.UdunitsError:
33+
system = _ud.read_xml(get_xml_path())
3034

3135
self.assertIsNotNone(system)
3236

@@ -46,7 +50,10 @@ class Test_system(unittest.TestCase):
4650
"""
4751

4852
def setUp(self):
49-
self.system = _ud.read_xml()
53+
try:
54+
self.system = _ud.read_xml()
55+
except _ud.UdunitsError:
56+
self.system = _ud.read_xml(get_xml_path())
5057

5158
def test_get_unit_by_name(self):
5259
unit = _ud.get_unit_by_name(self.system, b"metre")
@@ -91,7 +98,11 @@ class Test_unit(unittest.TestCase):
9198
"""
9299

93100
def setUp(self):
94-
self.system = _ud.read_xml()
101+
try:
102+
self.system = _ud.read_xml()
103+
except _ud.UdunitsError:
104+
self.system = _ud.read_xml(get_xml_path())
105+
95106
self.metre = _ud.get_unit_by_name(self.system, b"metre")
96107
self.yard = _ud.get_unit_by_name(self.system, b"yard")
97108
self.second = _ud.get_unit_by_name(self.system, b"second")
@@ -267,7 +278,11 @@ class Test_convert(unittest.TestCase):
267278
"""
268279

269280
def setUp(self):
270-
system = _ud.read_xml()
281+
try:
282+
system = _ud.read_xml()
283+
except _ud.UdunitsError:
284+
system = _ud.read_xml(get_xml_path())
285+
271286
metre = _ud.get_unit_by_name(system, b"metre")
272287
yard = _ud.get_unit_by_name(system, b"yard")
273288
self.converter = _ud.get_converter(metre, yard)

‎codecov.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ coverage:
55
status:
66
project:
77
default:
8-
target: auto # auto compares coverage to the previous base commit
9-
threshold: 0.5% # coverage can drop by up to 0.5% while still posting success
8+
target: auto
9+
threshold: 0.5% # coverage can drop by up to <threshold>% while still posting success
10+
patch: off

‎setup.cfg

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ include_package_data = True
4040
install_requires =
4141
antlr4-python3-runtime ==4.7.2
4242
cftime >=1.2
43+
jinja2
4344
numpy
4445
# udunits2 cannot be installed with pip, and it is expected to be
4546
# installed separately.

0 commit comments

Comments
 (0)
Please sign in to comment.