Skip to content

Commit

Permalink
Refactor Github Actions, add PyPI release action (cblearn#59)
Browse files Browse the repository at this point in the history
* Get version from git tag
* Add CD to pypi script and docs
* Fix setup.cfg formatting
* Simplify workflow: separate jobs
* Run workflows just on ubuntu-latest
* Support python 3.9 and 3.10
  • Loading branch information
dekuenstle authored Mar 22, 2023
1 parent 13d0b61 commit 7d1bd10
Show file tree
Hide file tree
Showing 15 changed files with 3,018 additions and 92 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ cover_pylib = false
omit =
*/site-packages/*
*/tests/*
*/_version.py

[report]
exclude_lines =
Expand Down
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cblearn/_version.py export-subst
58 changes: 40 additions & 18 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,46 @@
name: Upload Python Package
# Based on:
# https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
name: Publish Python 🐍 distributions 📦 to PyPI and TestPyPI

on:
on:
push:
branches:
- main
release:
types: [created]
types: [published]

jobs:
deploy:
runs-on: ubuntu-20.04

build-n-publish:
name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install pypa/build
run: >-
python -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: >-
python -m
build
--sdist
--wheel
--outdir dist/
- name: Publish distribution 📦 to Test PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy/
skip_existing: true
- name: Publish distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
84 changes: 55 additions & 29 deletions .github/workflows/python-package.yml → .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Tests
name: Lint and test code, test documentation build

on:
push:
Expand All @@ -10,42 +10,70 @@ on:
branches: [ main ]

jobs:
build:
name: ${{ matrix.platform }} ${{ matrix.python-version }}
lint:
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: flake8 Lint Errors
uses: py-actions/flake8@v2
with:
args: --count --select=E9,F63,F7,F82 --show-source --statistics
# stop the build if there are Python syntax errors or undefined names
# E9: Runtime errors (syntax, indentation, io)
# F63: Wrong use of operators and always-true assertion tests
# F7: Wrong position of statements (break, continue, return, ...)
# F82: Undefined (variable) name
- name: flake8 Lint Warnings
uses: py-actions/flake8@v2
with:
args: --count --exit-zero --statistics --show-source
# print warnings if other style errors are found.
# see .flake8 config file for selected/ignored rules.
# warnings can be found in the action logs

docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: pip
cache-dependency-path: setup.cfg
- name: Install package with docs
run: |
python3 -m pip install --upgrade pip
pip install -e .[docs]
- name: Build the documentation
run: |
cd docs && make html
test:
strategy:
matrix:
platform: [ubuntu-latest, windows-latest]
python-version: [3.8]
include:
- platform: ubuntu-latest
python-version: 3.9
runs-on: ${{ matrix.platform }}
python-version:
- "3.9"
- "3.10"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: setup.cfg
- name: Setup R
uses: r-lib/actions/setup-r@v1
uses: r-lib/actions/setup-r@v2
- name: Install package with dependencies
run: |
python3 -m pip install --upgrade pip
pip install -e .[r_wrapper,tests,docs,torch]
pip install -e .[r_wrapper,tests,torch]
pip install h5py
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
# E9: Runtime errors (syntax, indentation, io)
# F63: Wrong use of operators and always-true assertion tests
# F7: Wrong position of statements (break, continue, return, ...)
# F82: Undefined (variable) name
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
#
# print warnings if other style errors are found.
# see .flake8 config file for selected/ignored rules.
# warnings can be found in the action logs
flake8 . --count --exit-zero --statistics --show-source
- name: Test with pytest and measure coverage
run: |
pytest cblearn --cov=cblearn --cov-report=xml --remote-data
Expand All @@ -56,6 +84,4 @@ jobs:
file: ./coverage.xml
flags: unittests
env_vars: OS,PYTHON
- name: Build the documentation
run: |
cd docs && make html

7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changelog

## 0.1.0

- Support python 3.9 and 3.10.
- Introduce semantic versioning
- Publish to PyPI
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ include pyproject.toml
include readthedocs.yml
include .flake8
include MANIFEST.in
include versioneer.py
include cblearn/_version.py

# exclude from sdist
## recursive-exclude folder *
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# cblearn
## Comparison-based Machine Learning in Python
:warning: **cblearn** is **work in progress**. The API can change and bugs appear. Please help us by posting an [issue]( https://github.com/dekuenstle/cblearn/issues/new) :construction:


[![PyPI version](https://img.shields.io/pypi/v/cblearn.svg)](https://pypi.python.org/pypi/cblearn)
[![Documentation](https://readthedocs.org/projects/cblearn/badge/?version=latest)](https://cblearn.readthedocs.io/en/latest/?badge=latest)
[![Unit tests](https://github.com/dekuenstle/cblearn/workflows/Python%20package/badge.svg)](https://github.com/dekuenstle/cblearn/actions)
[![Test Coverage](https://codecov.io/gh/dekuenstle/cblearn/branch/master/graph/badge.svg?token=P9JRT6OK6O)](https://codecov.io/gh/dekuenstle/cblearn)
[![Documentation](https://readthedocs.org/projects/cblearn/badge/?version=latest)](https://cblearn.readthedocs.io/en/latest/?badge=latest)

Comparison-based Learning algorithms are the Machine Learning algorithms to use when training data contains similarity comparisons ("A and B are more similar than C and D") instead of data points.

Expand Down
5 changes: 3 additions & 2 deletions cblearn/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from ._version import __version__
from . import _version

__all__ = ['__version__']

__version__ = _version.get_versions()['version']
Loading

0 comments on commit 7d1bd10

Please sign in to comment.