Skip to content

Commit

Permalink
Adds support for pypoetry (https://python-poetry.org) (#222)
Browse files Browse the repository at this point in the history
* introduces python poetry to maintain and build the package

* allows building wheels for PyPI  (fixes #212) 

* uses `pyproject.toml` instead of `setup.py` and thus fixes  #143 and fixes #137 

* sets up Github Actions for general testing (replaces Travis)

* bumps version to 1.0.0-beta

Co-authored-by: Konstantin (Tino) Sering <[email protected]>
  • Loading branch information
Trybnetic and derNarr authored Aug 11, 2022
1 parent dc5acf7 commit a47618c
Show file tree
Hide file tree
Showing 21 changed files with 317 additions and 457 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Linux & OSX tests

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
build:
name: ${{ matrix.os }} ${{ matrix.python-version }}
strategy:
matrix:
os: [ubuntu-latest, macOS-latest]
python-version: ['3.8', '3.10']
poetry-version: [1.1.13]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2

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

- name: Get full Python version
id: full-python-version
run: echo ::set-output name=version::$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")

- name: Setup poetry
uses: abatilo/[email protected]
with:
poetry-version: ${{ matrix.poetry-version }}

- name: Update PATH
if: ${{ runner.os != 'Windows' }}
run: echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: Update Path for Windows
if: ${{ runner.os == 'Windows' }}
run: echo "$APPDATA\Python\Scripts" >> $GITHUB_PATH

- name: Configure poetry
run: poetry config virtualenvs.in-project true

- name: Set up cache
uses: actions/cache@v2
id: cache
with:
path: .venv
key: venv-cache-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }}

- name: Install dependencies
run: poetry install

- name: Run linux tests
if: ${{ runner.os == 'Linux' }}
run: poetry run pytest --cov=pyndl --cov-report=xml --disable-pytest-warnings

- name: Run tests on other distributions (skip linux-only tests)
if: ${{ runner.os != 'Linux' }}
run: poetry run pytest --no-linux

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
file: ./coverage.xml
flags: unittests
env_vars: OS,PYTHON
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pyndl/ndl_parallel.c
pyndl/ndl_openmp.c
pyndl/corr_parallel.c
pyndl/wh_parallel.c
pyndl/correlation_openmp.c
latex/
*.pyc
__pycache__/
Expand All @@ -28,4 +29,7 @@ doc/data/levent.tab.filtered
doc/data/weights.nc

# copybutton js script
doc/source/_static/copybutton.js
copybutton.js

# pypoetry
poetry.lock
28 changes: 24 additions & 4 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# .readthedocs.yaml
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the version of Python and other tools you might need
build:
os: ubuntu-20.04
tools:
python: "3.9"

# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: doc/source/conf.py

# If using Sphinx, optionally build your docs in additional formats such as PDF
formats: all

# Optionally declare the Python requirements required to build your docs
python:
setup_py_install: true
pip_install: true
extra_requirements:
- docs
install:
- path: .
- requirements: doc/requirements.txt
29 changes: 0 additions & 29 deletions .travis.yml

This file was deleted.

16 changes: 0 additions & 16 deletions MANIFEST.in

This file was deleted.

28 changes: 0 additions & 28 deletions Makefile

This file was deleted.

9 changes: 4 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
Pyndl - Naive Discriminative Learning in Python
===============================================

.. image:: https://travis-ci.com/quantling/pyndl.svg?branch=master
:target: https://travis-ci.com/quantling/pyndl
.. image:: https://github.com/quantling/pyndl/actions/workflows/python-test.yml/badge.svg?branch=master
:target: https://github.com/quantling/pyndl/actions/workflows/python-test.yml

.. image:: https://coveralls.io/repos/github/quantling/pyndl/badge.svg?branch=master
:target: https://coveralls.io/github/quantling/pyndl?branch=master
.. image:: https://codecov.io/gh/quantling/pyndl/branch/master/graph/badge.svg?token=2GWUXRA9PD
:target: https://codecov.io/gh/quantling/pyndl

.. image:: https://img.shields.io/lgtm/grade/python/g/quantling/pyndl.svg?logo=lgtm&logoWidth=18
:target: https://lgtm.com/projects/g/quantling/pyndl/context:python
Expand Down Expand Up @@ -87,4 +87,3 @@ Acknowledgments
This research was supported by an ERC advanced Grant (no. 742545) and by the
Alexander von Humboldt Professorship awarded to R. H. Baayen and by the
University of Tübingen.

58 changes: 13 additions & 45 deletions setup.py → build.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from setuptools import setup, Extension
from setuptools import Extension
from setuptools.command.build_ext import build_ext as _build_ext
import sys

Expand All @@ -9,27 +9,11 @@ class build_ext(_build_ext):
def finalize_options(self):
_build_ext.finalize_options(self)
# Prevent numpy from thinking it is still in its setup process:
__builtins__.__NUMPY_SETUP__ = False
#__builtins__.__NUMPY_SETUP__ = False
import numpy
self.include_dirs.append(numpy.get_include())


pkg = __import__('pyndl')

author = pkg.__author__
email = pkg.__author_email__

version = pkg.__version__
classifiers = pkg.__classifiers__

description = pkg.__description__

def load_requirements(fn):
"""Read a requirements file and create a list that can be used in setup."""
with open(fn, 'r') as f:
return [x.rstrip() for x in list(f) if x and not x.startswith('#')]


ndl_parallel = Extension("pyndl.ndl_parallel", ["pyndl/ndl_parallel.pyx"])
ndl_openmp = Extension("pyndl.ndl_openmp", ["pyndl/ndl_openmp.pyx"],
extra_compile_args=['-fopenmp'], extra_link_args=['-fopenmp'])
Expand All @@ -46,30 +30,14 @@ def load_requirements(fn):
elif sys.platform.startswith('darwin'):
ext_modules = [ndl_parallel] # skip openmp installation on macos for now

setup(
name='pyndl',
version=version,
license='MIT',
description=description,
long_description=open('README.rst', encoding="utf-8").read(),
author=author,
author_email=email,
url='https://github.com/quantling/pyndl',
classifiers=classifiers,
platforms='Linux',
packages=['pyndl'],
setup_requires=['numpy', 'cython'],
install_requires=load_requirements('requirements.txt'),
extras_require={
'tests': [
'pylint',
'pytest',
'pycodestyle'],
'docs': [
'sphinx >= 1.4',
'sphinx_rtd_theme',
'numpydoc',
'easydev']},
ext_modules=ext_modules,
cmdclass={'build_ext': build_ext}
)

def build(setup_kwargs):
"""
This function is mandatory in order to build the extensions.
"""
setup_kwargs.update({
'ext_modules': ext_modules,
'cmdclass': {
'build_ext': build_ext
}
})
7 changes: 7 additions & 0 deletions doc/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
sphinx>=1.4
sphinx_rtd_theme>=1.0.0
notebook>=6.4.10
seaborn>=0.11.2
numpydoc>=1.2
easydev>=0.9.35
nbsphinx>=0.8.8
5 changes: 3 additions & 2 deletions doc/source/about.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ Authors
*pyndl* was mainly developed by
`Konstantin Sering <https://github.com/derNarr>`_,
`Marc Weitz <https://github.com/trybnetic>`_,
`David-Elias Künstle <https://github.com/dekuenstle/>`_
and `Lennart Schneider <https://github.com/sumny>`_. For the full list of
`David-Elias Künstle <https://github.com/dekuenstle/>`_,
`Lennart Schneider <https://github.com/sumny>`_ and
`Elnaz Shafaei-Bajestan <https://github.com/elnazsh>`_. For the full list of
contributors have a look at `Github's Contributor summary
<https://github.com/quantling/pyndl/contributors>`_.

Expand Down
Loading

0 comments on commit a47618c

Please sign in to comment.