Skip to content

Commit

Permalink
Merge pull request #13 from nstarman/test-building
Browse files Browse the repository at this point in the history
Test building wheels
  • Loading branch information
nstarman authored Sep 23, 2022
2 parents e68beb0 + 2e003ac commit 6f819a2
Show file tree
Hide file tree
Showing 19 changed files with 110 additions and 79 deletions.
1 change: 1 addition & 0 deletions .github/mypyc-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mypy >= 0.971
mypy-extensions >= 0.4.3
numpy>=1.18

# And because build isolation is disabled, we'll need to pull this too
setuptools-scm[toml] >= 6.3.1
Expand Down
9 changes: 9 additions & 0 deletions .github/test-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# TODO! figure out how to source from [project.optional-dependencies]
coverage[toml]
hypothesis
numpy>=1.18
pytest>=6.1.1
pytest-astropy-header
pytest-cov
pytest-doctestplus
typing_extensions>=4.2
63 changes: 55 additions & 8 deletions .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ on:
- '*'
pull_request:

permissions:
contents: read

env:
ARCH_ON_CI: "normal"
IS_CRON: "false"
Expand Down Expand Up @@ -35,6 +38,7 @@ jobs:
core.info(`PR opened correctly against ${allowed_basebranch}`);
}
tests:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
Expand All @@ -44,13 +48,6 @@ jobs:
matrix:
include:

# Run faster by the pre-commit bot
# - name: Code style checks
# os: ubuntu-latest
# python: 3.x
# toxenv: codestyle
# toxposargs: --all-files -v

# NOTE: this coverage test is needed for tests and code that
# run only with minimal dependencies.
- name: Python 3.10 with minimal dependencies and full coverage
Expand Down Expand Up @@ -110,4 +107,54 @@ jobs:
file: ./coverage.xml


# TODO! a mypyc compiled test
test_pure_wheel_building:
uses: OpenAstronomy/github-actions-workflows/.github/workflows/publish_pure_python.yml@v1
if: (github.event_name == 'push' || github.event_name == 'pull_request')
needs: initial_checks
with:
upload_to_pypi: false
upload_to_anaconda: false
test_extras: test
test_command: ls $GITHUB_WORKSPACE; pytest $GITHUB_WORKSPACE/tests $GITHUB_WORKSPACE/docs

test_wheel_building:
# This ensures that a couple of targets work fine in pull requests and pushes
# FIXME! use OpenAstronomy/github-actions-workflows/.github/workflows/publish.yml@v1
name: mypyc wheels (${{ matrix.name }})
if: (github.event_name == 'push' || github.event_name == 'pull_request')
needs: initial_checks
runs-on: ${{ matrix.os }}

strategy:
fail-fast: true
matrix:
include:
- os: ubuntu-latest
name: linux-x86_64
- os: windows-2019
name: windows-amd64
- os: macos-11
name: macos-x86_64
macos_arch: "x86_64"
- os: macos-11
name: macos-arm64
macos_arch: "arm64"
- os: macos-11
name: macos-universal2
macos_arch: "universal2"

steps:
- uses: actions/checkout@v3

- name: Build wheels via cibuildwheel
uses: pypa/[email protected]
env:
CIBW_ARCHS_MACOS: "${{ matrix.macos_arch }}"
# This isn't supported in pyproject.toml which makes sense (but is annoying).
CIBW_PROJECT_REQUIRES_PYTHON: ">=3.8"

- name: Upload wheels as workflow artifacts
uses: actions/upload-artifact@v2
with:
name: ${{ matrix.name }}-mypyc-wheels
path: ./wheelhouse/*.whl
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

name: Upload Python Package

on:
Expand All @@ -11,34 +8,21 @@ permissions:
contents: read

jobs:
main:
name: sdist + pure wheel
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up latest Python
uses: actions/setup-python@v4
with:
python-version: "*"

- name: Install dependencies
run: |
python -m pip install --upgrade --disable-pip-version-check pip
python -m pip install --upgrade build twine
- name: Build wheel and source distributions
run: python -m build

- name: Upload to PyPI via Twine
env:
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: twine upload --verbose -u '__token__' dist/*
main:
uses: OpenAstronomy/github-actions-workflows/.github/workflows/publish_pure_python.yml@v1
with:
upload_to_pypi: true
upload_to_anaconda: false # TODO!
test_extras: test
test_command: ls $GITHUB_WORKSPACE; pytest $GITHUB_WORKSPACE/tests $GITHUB_WORKSPACE/docs
secrets:
pypi_token: ${{ secrets.PYPI_API_TOKEN }}

mypyc:
name: mypyc wheels (${{ matrix.name }})
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
Expand Down
9 changes: 4 additions & 5 deletions tests/conftest.py → conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
import os
from typing import Any

# THIRD PARTY
# THIRDPARTY
import pytest

ASTROPY_HEADER: bool
try:
# THIRD PARTY
from pytest_astropy_header.display import PYTEST_HEADER_MODULES # type: ignore
from pytest_astropy_header.display import TESTED_VERSIONS # type: ignore
# THIRDPARTY
from pytest_astropy_header.display import PYTEST_HEADER_MODULES, TESTED_VERSIONS

ASTROPY_HEADER = True
except ImportError:
Expand Down Expand Up @@ -63,7 +62,7 @@ def add_numpy(doctest_namespace: dict[str, Any]) -> None:
doctest_namespace : namespace
"""
# THIRD PARTY
# THIRDPARTY
import numpy

# add to namespace
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from importlib import import_module
from importlib.metadata import version as get_version

# THIRD PARTY
# THIRDPARTY
import tomli


Expand Down
23 changes: 10 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
"Programming Language :: Python :: 3",
]
dependencies = [
"mypy",
"typing_extensions>=4.2",
"mypy_extensions>=0.4.3",
]

Expand All @@ -32,6 +30,7 @@
"numpy>=1.18",
"pytest",
"pytest-astropy",
"typing_extensions>=4.2",
]
docs = [
"graphviz",
Expand Down Expand Up @@ -79,14 +78,15 @@
# This is the bare minimum needed to run the test suite. Pulling in the full
# test_requirements.txt would download a bunch of other packages not necessary
# here and would slow down the testing step a fair bit.
test-requires = ["pytest>=6.1.1"]
test-command = 'pytest {project} -k "not incompatible_with_mypyc"'
test-requires = ["pip install -r .github/test-requirements.txt"]
test-command = 'pytest {project}/tests {project}/docs -k "not incompatible_with_mypyc"'
# Skip trying to test arm64 builds on Intel Macs. (so cross-compilation doesn't
# straight up crash)
test-skip = ["*-macosx_arm64", "*-macosx_universal2:arm64"]

[tool.cibuildwheel.environment]
BLACK_USE_MYPYC = "1"
CIBW_BUILD_VERBOSITY = "1"
NPOVERLOAD_USE_MYPYC = "1"
MYPYC_OPT_LEVEL = "3"
MYPYC_DEBUG_LEVEL = "0"
# The dependencies required to build wheels with mypyc aren't specified in
Expand All @@ -98,11 +98,10 @@
"pip install -r .github/mypyc-requirements.txt",
"yum install -y clang",
]
# Newer images break the builds, not sure why. We'll need to investigate more later.
manylinux-x86_64-image = "quay.io/pypa/manylinux2014_x86_64:2021-11-20-f410d11"

[tool.cibuildwheel.linux.environment]
BLACK_USE_MYPYC = "1"
CIBW_BUILD_VERBOSITY = "1"
NPOVERLOAD_USE_MYPYC = "1"
MYPYC_OPT_LEVEL = "3"
MYPYC_DEBUG_LEVEL = "0"
PIP_NO_BUILD_ISOLATION = "no"
Expand Down Expand Up @@ -137,17 +136,15 @@

[tool.isort]
profile = "black"
multi_line_output = 3
include_trailing_comma = "True"
force_grid_wrap = 0
use_parentheses = "True"
ensure_newline_before_comments = "True"
sections = ["FUTURE", "STDLIB", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER"]
known_localfolder = "overload_numpy"
known_third_party = ["numpy", "pytest"]
import_heading_stdlib = "STDLIB"
import_heading_thirdparty = "THIRD PARTY"
import_heading_localfolder = "LOCAL"
import_heading_firstparty = "FIRSTPARTY"
import_heading_thirdparty = "THIRDPARTY"
import_heading_localfolder = "LOCALFOLDER"


[tool.mypy]
Expand Down
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import sys
from pathlib import Path

# THIRD PARTY
# THIRDPARTY
from mypyc.build import mypycify
from setuptools import setup

Expand Down Expand Up @@ -71,8 +71,6 @@ def find_python_files(base: Path, exclude: tuple[str, ...] = ("test_",)) -> list
blocklist = [
# TODO!
"overload_numpy/dispatch.py", # https://github.com/python/mypy/issues/13613
# Never compiled
# "overload_numpy/conftest.py", # test configuration
]
discovered: list[Path] = []
discovered.extend(find_python_files(SRC / "overload_numpy"))
Expand Down
2 changes: 1 addition & 1 deletion src/overload_numpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# LOCAL
# LOCALFOLDER
from overload_numpy import constraints # noqa: F401, TC002
from overload_numpy.mixin import NDFunctionMixin
from overload_numpy.overload import NumPyOverloader
Expand Down
2 changes: 1 addition & 1 deletion src/overload_numpy/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from abc import ABCMeta, abstractmethod
from dataclasses import dataclass

# THIRD PARTY
# THIRDPARTY
from mypy_extensions import mypyc_attr

__all__ = ["TypeConstraint", "Invariant", "Covariant", "Contravariant", "Between"]
Expand Down
2 changes: 1 addition & 1 deletion src/overload_numpy/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from functools import singledispatch
from typing import TYPE_CHECKING, Any, NoReturn, final

# LOCAL
# LOCALFOLDER
from overload_numpy.npinfo import _NOT_DISPATCHED, _NumPyInfo

if TYPE_CHECKING:
Expand Down
4 changes: 2 additions & 2 deletions src/overload_numpy/mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
# STDLIB
from typing import TYPE_CHECKING, Any, Callable, ClassVar, Collection

# THIRD PARTY
# THIRDPARTY
from mypy_extensions import mypyc_attr

if TYPE_CHECKING:
# LOCAL
# LOCALFOLDER
from overload_numpy.constraints import TypeConstraint
from overload_numpy.overload import NumPyOverloader

Expand Down
4 changes: 2 additions & 2 deletions src/overload_numpy/npinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
from dataclasses import dataclass
from typing import Any, Callable, ClassVar, TypeVar, final

# THIRD PARTY
# THIRDPARTY
from mypy_extensions import mypyc_attr

# LOCAL
# LOCALFOLDER
from overload_numpy.constraints import TypeConstraint

__all__: list[str] = []
Expand Down
6 changes: 1 addition & 5 deletions src/overload_numpy/overload.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@
from collections.abc import Collection
from typing import Any, Callable, Final, Iterator, KeysView, Mapping, ValuesView

# LOCAL
# LOCALFOLDER
from overload_numpy.constraints import Covariant, TypeConstraint
from overload_numpy.dispatch import _Dispatcher
from overload_numpy.npinfo import _NumPyInfo

# if TYPE_CHECKING:
# # THIRD PARTY
# from typing_extensions import TypeGuard

__all__: list[str] = []


Expand Down
6 changes: 3 additions & 3 deletions tests/integration/test_array_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, Callable

# THIRD PARTY
# THIRDPARTY
import numpy as np
import pytest

# LOCAL
# LOCALFOLDER
from overload_numpy import NumPyOverloader
from overload_numpy.constraints import Covariant
from overload_numpy.dispatch import _notdispatched_info

if TYPE_CHECKING:
# THIRD PARTY
# THIRDPARTY
from typing_extensions import Self


Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
from dataclasses import dataclass
from typing import Protocol

# THIRD PARTY
# THIRDPARTY
import pytest

# LOCAL
# LOCALFOLDER
from overload_numpy.constraints import (
Between,
Contravariant,
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_dispatch.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
##############################################################################
# IMPORTS

# THIRD PARTY
# THIRDPARTY
import pytest

# LOCAL
# LOCALFOLDER
from overload_numpy.dispatch import _Dispatcher, _notdispatched, _notdispatched_info
from overload_numpy.npinfo import _NOT_DISPATCHED, _NumPyInfo

Expand Down
Loading

0 comments on commit 6f819a2

Please sign in to comment.