Skip to content

Commit

Permalink
Fix GHA pypi-publish and UDUNITS2 XML read (#196)
Browse files Browse the repository at this point in the history
* Fix GHA pypi-publish and UDUNITS2 XML read

* add publish to pypi job

* turn codecov patch off
  • Loading branch information
bjlittle authored Aug 4, 2021
1 parent 05ed292 commit 6e42f39
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 67 deletions.
27 changes: 23 additions & 4 deletions .github/workflows/actions/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,37 @@
#!/bin/sh
#!/usr/bin/env bash

trap 'echo "Aborted!"; exit 1' ERR
set -e


yum install -y udunits2-devel

PYTHONS=("cp37-cp37m" "cp38-cp38" "cp39-cp39")
WHEELHOUSE="/github/workspace/wheelhouse/"
WHEELHOUSE="/github/workspace/wheelhouse"
MANYLINUX="manylinux2014_x86_64"
DISTRIBUTION="dist"

export UDUNITS2_INCDIR="/usr/include/udunits2"
export UDUNITS2_LIBDIR="/usr/lib64"
export UDUNITS2_XML_PATH="/usr/share/udunits/udunits2.xml"

# Create the distribution directory.
mkdir ${DISTRIBUTION}

# Build the wheels in the wheelhouse.
for PYTHON in ${PYTHONS[@]}; do
/opt/python/${PYTHON}/bin/pip install --upgrade pip wheel setuptools setuptools_scm build twine auditwheel
/opt/python/${PYTHON}/bin/python -m build --sdist --wheel . --outdir ${WHEELHOUSE}
PYBIN="/opt/python/${PYTHON}/bin/python"
${PYBIN} -m pip install --upgrade pip wheel setuptools setuptools_scm build twine auditwheel
${PYBIN} -m build --wheel . --outdir ${WHEELHOUSE}
done

# Build the sdist in the distribution.
${PYBIN} -m build --sdist . --outdir ${DISTRIBUTION}

# Convert to manylinux wheels in the wheelhouse.
for BDIST_WHEEL in ${WHEELHOUSE}/cf_units*.whl; do
auditwheel repair ${BDIST_WHEEL}
done

# Populate distribution with the manylinux wheels.
cp ${WHEELHOUSE}/cf_units*${MANYLINUX}.whl ${DISTRIBUTION}
7 changes: 0 additions & 7 deletions .github/workflows/actions/manylinux2010_x86_64/action.yml

This file was deleted.

7 changes: 7 additions & 0 deletions .github/workflows/actions/manylinux2014_x86_64/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: 'build wheels with manylinux2014_x86_64'
description: 'build wheels with manylinux2014_x86_64'
runs:
using: 'docker'
image: docker://quay.io/pypa/manylinux2014_x86_64
args:
- .github/workflows/actions/entrypoint.sh
40 changes: 0 additions & 40 deletions .github/workflows/build_linux.yml

This file was deleted.

102 changes: 102 additions & 0 deletions .github/workflows/pypi_publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: pypi-publish

on:
release:
types:
- published

jobs:
build-artifacts:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Get tags
shell: bash
run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*

- name: Build linux wheels
uses: ./.github/workflows/actions/manylinux2014_x86_64

- name: List built artifacts
shell: bash
working-directory: dist
run: ls

- name: Check built artifacts
shell: bash
working-directory: dist
run: |
python -m pip install wheel twine
python -m twine check *
- name: Inspect built wheels
shell: bash
working-directory: dist
run: |
for WHEEL in *.whl; do
echo -e "\n${WHEEL}"
python -m zipfile --list ${WHEEL}
done
- name: Upload built artifacts
uses: actions/upload-artifact@v2
with:
name: pypi-artifacts
path: dist

test-artifacts:
needs: build-artifacts
name: Test ${{ matrix.tag }} for Python ${{ matrix.python }}
runs-on: ubuntu-latest
strategy:
matrix:
python: [3.7, 3.8, 3.9]
include:
- python: 3.7
tag: cp37-cp37m
- python: 3.8
tag: cp38-cp38
- python: 3.9
tag: cp39-cp39
steps:
- name: Download built artifacts
uses: actions/download-artifact@v2
with:
name: pypi-artifacts
path: dist

- name: Setup Python ${{ matrix.python }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}

- name: Install ${{ matrix.tag }}
env:
TAG: ${{ matrix.tag }}
shell: bash
working-directory: dist
run: python -m pip install cf_units-*-${TAG}-*.whl

- name: Test ${{ matrix.tag }}
shell: bash
run: |
python -m pip install pytest
python -m pytest --pyargs cf_units
publish-artifacts:
needs: [build-artifacts, test-artifacts]
name: Publish built artifacts to PyPI
runs-on: ubuntu-latest
steps:
- name: Download built artifacts
uses: actions/download-artifact@v2
with:
name: pypi-artifacts
path: dist

- name: Publish artifacts
uses: pypa/[email protected]
with:
user: __token__
password: ${{ secrets.PYPI_PASSWORD }}
11 changes: 1 addition & 10 deletions cf_units/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
"""

import copy
import os.path
import sys
from contextlib import contextmanager

import cftime
Expand Down Expand Up @@ -187,15 +185,8 @@ def suppress_errors():
try:
_ud_system = _ud.read_xml()
except _ud.UdunitsError:
_alt_xml_path = config.get_option(
"System",
"udunits2_xml_path",
default=os.path.join(
sys.prefix, "share", "udunits", "udunits2.xml"
),
)
try:
_ud_system = _ud.read_xml(_alt_xml_path.encode())
_ud_system = _ud.read_xml(config.get_xml_path())
except _ud.UdunitsError as e:
error_msg = ': "%s"' % e.error_msg() if e.errnum else ""
raise OSError(
Expand Down
12 changes: 12 additions & 0 deletions cf_units/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@


import configparser
import sys
from pathlib import Path
from tempfile import NamedTemporaryFile

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


def get_xml_path():
"""Return the alternative path to the UDUNITS2 XMl file"""
default = Path(sys.prefix) / "share" / "udunits" / "udunits2.xml"
path = get_option(
"System",
"udunits2_xml_path",
default=str(default),
)
return path.encode()


# Figure out the full path to the "cf_units" package.
ROOT_PATH = Path(__file__).resolve().parent

Expand Down
23 changes: 19 additions & 4 deletions cf_units/tests/unit/test__udunits2.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import numpy as np

from cf_units import _udunits2 as _ud
from cf_units.config import get_xml_path

_ud.set_error_message_handler(_ud.ignore)

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

def test_read_xml(self):
system = _ud.read_xml()
try:
system = _ud.read_xml()
except _ud.UdunitsError:
system = _ud.read_xml(get_xml_path())

self.assertIsNotNone(system)

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

def setUp(self):
self.system = _ud.read_xml()
try:
self.system = _ud.read_xml()
except _ud.UdunitsError:
self.system = _ud.read_xml(get_xml_path())

def test_get_unit_by_name(self):
unit = _ud.get_unit_by_name(self.system, b"metre")
Expand Down Expand Up @@ -91,7 +98,11 @@ class Test_unit(unittest.TestCase):
"""

def setUp(self):
self.system = _ud.read_xml()
try:
self.system = _ud.read_xml()
except _ud.UdunitsError:
self.system = _ud.read_xml(get_xml_path())

self.metre = _ud.get_unit_by_name(self.system, b"metre")
self.yard = _ud.get_unit_by_name(self.system, b"yard")
self.second = _ud.get_unit_by_name(self.system, b"second")
Expand Down Expand Up @@ -267,7 +278,11 @@ class Test_convert(unittest.TestCase):
"""

def setUp(self):
system = _ud.read_xml()
try:
system = _ud.read_xml()
except _ud.UdunitsError:
system = _ud.read_xml(get_xml_path())

metre = _ud.get_unit_by_name(system, b"metre")
yard = _ud.get_unit_by_name(system, b"yard")
self.converter = _ud.get_converter(metre, yard)
Expand Down
5 changes: 3 additions & 2 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ coverage:
status:
project:
default:
target: auto # auto compares coverage to the previous base commit
threshold: 0.5% # coverage can drop by up to 0.5% while still posting success
target: auto
threshold: 0.5% # coverage can drop by up to <threshold>% while still posting success
patch: off
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ include_package_data = True
install_requires =
antlr4-python3-runtime ==4.7.2
cftime >=1.2
jinja2
numpy
# udunits2 cannot be installed with pip, and it is expected to be
# installed separately.
Expand Down

0 comments on commit 6e42f39

Please sign in to comment.