Skip to content

Commit

Permalink
Fix installation (#36)
Browse files Browse the repository at this point in the history
* Fix setuptools<60.0

* Add setup.py for editable installs

* Quiet NPY_NO_DEPRECATED_API

* Add wheel building through cibuildwheel
  • Loading branch information
jmyrberg authored Nov 14, 2022
1 parent b49394a commit b8b6990
Show file tree
Hide file tree
Showing 22 changed files with 146 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
max-line-length = 79
exclude = .svn,CVS,.bzr,.hg,.git,__pycache__,.eggs,*.egg,*/_vendor/*,node_modules
per-file-ignores =
tests/test__generalized_assignment.py: E127, E128, E131, E201
mknapsack/tests/test__generalized_assignment.py: E127, E128, E131, E201
10 changes: 6 additions & 4 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ jobs:
- uses: actions/setup-python@v3
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8
python -m pip install --upgrade pip flake8
- name: Lint with flake8
run: |
flake8 .
Expand Down Expand Up @@ -46,10 +45,13 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
- name: Install Python dependencies
env:
# Latest setuptools enables supports pyproject.toml editable install
# ...but fails to build the extensions
SETUPTOOLS_ENABLE_FEATURES: legacy-editable
run: |
python -m pip install --upgrade pip
pip install -e .
pip install -r requirements-dev.txt
pip install -e .[test]
- name: Test with pytest
run: |
pytest -vv
11 changes: 1 addition & 10 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
pytest -vv
draft-release:
name: Draft release and upload distribution to Test PyPi
name: Draft release
runs-on: ubuntu-latest
permissions:
contents: write
Expand All @@ -57,12 +57,3 @@ jobs:
- uses: release-drafter/release-drafter@v5
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_DRAFTER_PAT }}
- name: Build and upload distribution to Test PyPi
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }}
run: |
python -m pip install --upgrade pip
pip install build twine
python -m build --sdist --outdir dist/ .
twine upload -r testpypi dist/*
24 changes: 0 additions & 24 deletions .github/workflows/release.yml

This file was deleted.

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

on:
push:
branches: [master]
release:
types: [published]

env:
IS_PUSH: ${{ github.event_name == 'push' }}

jobs:
build-sdist:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install Fortran compiler on Linux
if: contains(matrix.os, 'ubuntu')
run: |
sudo apt-get install -y gfortran
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install build
- name: Build source distribution
run: |
python -m build --sdist --outdir dist/ .
- uses: actions/upload-artifact@v3
with:
path: ./dist/*.tar.gz

build-wheels:
name: Build wheels on ${{ matrix.buildplat[0] }}-${{ matrix.buildplat[1] }}
runs-on: ${{ matrix.buildplat[0] }}
strategy:
fail-fast: false
matrix:
buildplat:
- [ubuntu-latest, manylinux_x86_64]
- [macos-latest, macosx_x86_64]
- [windows-latest, win_amd64]
# TODO: Add when GHA supports
# - [macos-latest, macosx_arm64]
# - [windows-latest, win32]
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install Fortran compiler on MacOS
if: contains(matrix.buildplat[0], 'macos')
run: |
brew unlink gcc && brew link gcc
- name: Build wheels
uses: pypa/[email protected]
env:
CIBW_BUILD: "*${{ matrix.buildplat[1] }}"
- uses: actions/upload-artifact@v3
with:
path: ./wheelhouse/*.whl

upload-test-pypi:
name: Upload to Test PyPi
if: github.event_name == 'push'
runs-on: ubuntu-latest
needs: [build-sdist, build-wheels]
steps:
- uses: actions/download-artifact@v3
with:
name: artifact
path: dist
- uses: actions/setup-python@v3
- name: Upload artifacts to Test PyPi
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }}
run: |
python -m pip install --upgrade pip
python -m pip install twine
twine upload -r testpypi dist/*
upload-pypi:
name: Upload to PyPi
if: github.event_name == 'release'
runs-on: ubuntu-latest
needs: [build-sdist, build-wheels]
steps:
- uses: actions/download-artifact@v3
with:
name: artifact
path: dist
- uses: actions/setup-python@v3
- name: Upload artifacts to PyPi
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
python -m pip install --upgrade pip
python -m pip install twine
twine upload dist/*
12 changes: 2 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# mknapsack

[![CICD](https://github.com/jmyrberg/mknapsack/actions/workflows/push.yml/badge.svg)](https://github.com/jmyrberg/mknapsack/actions/workflows/push.yml)
[![Build](https://github.com/jmyrberg/mknapsack/actions/workflows/wheels.yml/badge.svg)](https://github.com/jmyrberg/mknapsack/actions/workflows/wheels.yml)
[![Documentation](https://readthedocs.org/projects/mknapsack/badge/?version=latest)](https://mknapsack.readthedocs.io/en/latest/?badge=latest)

![mknapsack cover](https://github.com/jmyrberg/mknapsack/blob/master/docs/cover.png?raw=true)
Expand All @@ -22,16 +23,7 @@ Documentation is available [here](https://mknapsack.readthedocs.io).

## Installation

1. Install Fortran compiler, if you don't already have it
* MacOS / Linux:
`brew install gcc`
* Linux / Windows Subsystem for Linux:
`sudo apt-get install gfortran`
* Windows (experimental):
* `conda install -c conda-forge m2w64-toolchain_win-64`, or
* [Install MSYS2](https://www.msys2.org) and `pacman -S --needed base-devel mingw-w64-x86_64-toolchain`

2. `pip install mknapsack`
`pip install mknapsack`


## Example usage
Expand Down
15 changes: 8 additions & 7 deletions mknapsack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@
]

import os
import sys


# .libs -folder must be added to dll for Windows and Python >=3.8
# https://github.com/numpy/numpy/issues/14923
extra_dll_dir = os.path.join(os.path.dirname(__file__), '.libs')
if sys.platform == 'win32' and os.path.isdir(extra_dll_dir):
os.add_dll_directory(extra_dll_dir)

# https://github.com/isuruf/scipy-feedstock/blob/c36d45b104fc7310f1f4ca45aefd321b2f9b6c59/recipe/_distributor_init.py
basedir = os.path.dirname(__file__)
extra_dll_dir = os.path.abspath(os.path.join(basedir, '.libs'))
if os.name == 'nt' and os.path.isdir(extra_dll_dir):
import glob
from ctypes import WinDLL
for filename in glob.glob(os.path.join(extra_dll_dir, '*dll')):
WinDLL(os.path.abspath(filename))

from mknapsack._exceptions import FortranInputCheckError, NoSolutionError, \
ProblemSizeError # noqa: E402
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from mknapsack._bin_packing import solve_bin_packing
from mknapsack._exceptions import FortranInputCheckError

from tests.utils import get_id
from mknapsack.tests.utils import get_id


bin_packing_case_small = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from mknapsack._bounded import solve_bounded_knapsack
from mknapsack._exceptions import FortranInputCheckError

from tests.utils import get_id
from mknapsack.tests.utils import get_id


bounded_knapsack_case_small = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from mknapsack._bounded_change_making import solve_bounded_change_making
from mknapsack._exceptions import FortranInputCheckError, NoSolutionError

from tests.utils import get_id
from mknapsack.tests.utils import get_id


bounded_change_making_case_small = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from mknapsack._change_making import solve_change_making
from mknapsack._exceptions import FortranInputCheckError, NoSolutionError

from tests.utils import get_id
from mknapsack.tests.utils import get_id


change_making_case_small = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from mknapsack._exceptions import FortranInputCheckError, NoSolutionError, \
ProblemSizeError

from tests.utils import get_id
from mknapsack.tests.utils import get_id


generalized_assignment_case_small = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from mknapsack._multiple import solve_multiple_knapsack
from mknapsack._exceptions import FortranInputCheckError

from tests.utils import get_id
from mknapsack.tests.utils import get_id


multiple_knapsack_case_small = {
Expand Down
2 changes: 1 addition & 1 deletion tests/test__single.py → mknapsack/tests/test__single.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from mknapsack._single import solve_single_knapsack
from mknapsack._exceptions import FortranInputCheckError

from tests.utils import get_id
from mknapsack.tests.utils import get_id


single_knapsack_case_small = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from mknapsack._subset_sum import solve_subset_sum
from mknapsack._exceptions import FortranInputCheckError

from tests.utils import get_id
from mknapsack.tests.utils import get_id


subset_sum_case_small = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from mknapsack._unbounded import solve_unbounded_knapsack
from mknapsack._exceptions import FortranInputCheckError

from tests.utils import get_id
from mknapsack.tests.utils import get_id


unbounded_knapsack_case_small = {
Expand Down
File renamed without changes.
19 changes: 13 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,33 @@ docs = [
"piccolo-theme",
"sphinx"
]
test = [
"pytest"
]

[project.urls]
"Homepage" = "https://github.com/jmyrberg/mknapsack"
"Documentation" = "https://mknapsack.readthedocs.io"

[build-system]
requires = [
"setuptools",
"setuptools>=51.0.0",
"setuptools-scm",
"numpy",
"wheel"
"numpy"
]
build-backend = "setuptools.build_meta"

[tool.setuptools.packages.find]
include = [
"mknapsack*",
"tests*"
"mknapsack*"
]

[tool.setuptools_scm]
write_to = "mknapsack/_version.py"
local_scheme = "no-local-version"
local_scheme = "no-local-version"

[tool.cibuildwheel]
skip = 'pp*'
build-verbosity = "3"
test-extras = ["test"]
test-command = "pytest -vv --import-mode=importlib {package}"
2 changes: 1 addition & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[pytest]
junit_family=xunit1
junit_family = xunit1
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[metadata]
name = mknapsack
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
sources=['mknapsack/_algos.f'],
extra_f77_compile_args=['-std=legacy'],
f2py_options=['--quiet'],
define_macros=[('NPY_NO_DEPRECATED_API', 'NPY_1_7_API_VERSION')]
)
]

Expand Down

0 comments on commit b8b6990

Please sign in to comment.