Skip to content

Commit

Permalink
build: don't ship cythonized wheel for now (and add isgeneratorfuncti…
Browse files Browse the repository at this point in the history
…on test) (#27)

* test: add generator test

* test: fail fast false

* fix: don't ship compiled

* fix: raise error when injecting processors on generator function

* build: skip cython on build
  • Loading branch information
tlambert03 committed Jul 13, 2022
1 parent 8f3b565 commit a5c1803
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 44 deletions.
121 changes: 79 additions & 42 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
runs-on: ${{ matrix.platform }}

strategy:
fail-fast: true
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10"]
platform: ["ubuntu-latest"]
Expand Down Expand Up @@ -105,55 +105,92 @@ jobs:
fail_ci_if_error: true
verbose: true

build:
name: Build wheels on ${{ matrix.os }}
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/v')
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04, windows-2019, macos-10.15]
# SKIPPING CYTHON WHEELS UNTIL # https://github.com/cython/cython/issues/4888
# build:
# name: Build wheels on ${{ matrix.os }}
# if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/v')
# runs-on: ${{ matrix.os }}
# strategy:
# fail-fast: false
# matrix:
# os: [ubuntu-20.04, windows-2019, macos-10.15]

# steps:
# - uses: actions/checkout@v3

# - uses: actions/setup-python@v4
# with:
# python-version: "3.9"

# - name: Build wheels
# uses: pypa/[email protected]

# - uses: actions/upload-artifact@v3
# with:
# path: ./wheelhouse/*.whl

# - name: Build sdist
# if: matrix.os == 'ubuntu-20.04'
# run: |
# python -m pip install build
# python -m build --sdist

# - uses: actions/upload-artifact@v3
# if: matrix.os == 'ubuntu-20.04'
# with:
# path: dist/*.tar.gz

# upload_pypi:
# name: Deploy
# needs: [check-manifest, build]
# runs-on: ubuntu-latest
# if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/v')
# steps:
# - uses: actions/download-artifact@v3
# with:
# name: artifact
# path: dist

# - uses: pypa/[email protected]
# with:
# user: __token__
# password: ${{ secrets.pypi_token }}

# - uses: softprops/action-gh-release@v1
# with:
# generate_release_notes: true


deploy:
name: Deploy
needs: test
if: "success() && startsWith(github.ref, 'refs/tags/')"
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: "3.9"

- name: Build wheels
uses: pypa/[email protected]

- uses: actions/upload-artifact@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
path: ./wheelhouse/*.whl
python-version: "3.x"

- name: Build sdist
if: matrix.os == 'ubuntu-20.04'
- name: install
run: |
python -m pip install build
python -m build --sdist
- uses: actions/upload-artifact@v3
if: matrix.os == 'ubuntu-20.04'
with:
path: dist/*.tar.gz

upload_pypi:
name: Deploy
needs: [check-manifest, build]
runs-on: ubuntu-latest
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/v')
steps:
- uses: actions/download-artifact@v3
with:
name: artifact
path: dist
git tag
pip install -U pip
pip install -U build twine
python -m build
twine check dist/*
ls -lh dist
env:
SKIP_CYTHON: 1

- uses: pypa/[email protected]
with:
user: __token__
password: ${{ secrets.pypi_token }}
- name: Build and publish
run: twine upload dist/*
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}

- uses: softprops/action-gh-release@v1
with:
Expand Down
5 changes: 5 additions & 0 deletions src/in_n_out/_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,11 @@ def inject_processors(
"""

def _deco(func: Callable[P, R]) -> Callable[P, R]:
if isgeneratorfunction(func):
raise TypeError(
"Cannot decorate a generator function with inject_processors"
)

nonlocal type_hint
if type_hint is None:
annotations = getattr(func, "__annotations__", {})
Expand Down
25 changes: 23 additions & 2 deletions tests/test_injection.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from contextlib import nullcontext
from typing import ContextManager, Optional
from inspect import isgeneratorfunction
from typing import ContextManager, Generator, Optional
from unittest.mock import Mock

import pytest

from in_n_out import Store, inject, inject_processors, register
from in_n_out import Store, _compiled, inject, inject_processors, register


def test_injection():
Expand Down Expand Up @@ -216,3 +217,23 @@ def test_inject_instance_into_unbound_method():
foo = Foo()
with register(providers={Foo: lambda: foo}):
assert inject(Foo.method)() == foo


# https://github.com/cython/cython/issues/4888
@pytest.mark.xfail(bool(_compiled), reason="Cython doesn't support this", strict=True)
def test_generators():
def generator_func() -> Generator:
yield 1
yield 2
yield 3

assert isgeneratorfunction(generator_func)
assert list(generator_func()) == [1, 2, 3]

injected = inject(generator_func)

assert isgeneratorfunction(injected)
assert list(injected()) == [1, 2, 3]

with pytest.raises(TypeError, match="generator function"):
inject(generator_func, processors=True)

0 comments on commit a5c1803

Please sign in to comment.