Skip to content

Commit

Permalink
feat: preparing for release
Browse files Browse the repository at this point in the history
  • Loading branch information
kszucs committed Jul 30, 2024
1 parent 2ee9d40 commit 97a6964
Show file tree
Hide file tree
Showing 15 changed files with 363 additions and 141 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Build and upload to PyPI

on:
workflow_dispatch:
pull_request:
push:
branches:
- main
release:
types:
- published

jobs:
build_wheels:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
# macos-13 is an intel runner, macos-14 is apple silicon
os: [ubuntu-latest, windows-latest, macos-13, macos-14]

steps:
- uses: actions/checkout@v4

- name: Build wheels
uses: pypa/cibuildwheel@v2.19.2

- uses: actions/upload-artifact@v4
with:
name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
path: ./wheelhouse/*.whl

build_sdist:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Build sdist
run: pipx run build --sdist

- uses: actions/upload-artifact@v4
with:
name: cibw-sdist
path: dist/*.tar.gz

upload_pypi:
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
environment: pypi
permissions:
id-token: write
if: github.event_name == 'release' && github.event.action == 'published'
# or, alternatively, upload to PyPI on every tag starting with 'v' (remove on: release above to use this)
# if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/download-artifact@v4
with:
# unpacks all CIBW artifacts into dist/
pattern: cibw-*
path: dist
merge-multiple: true

- uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
27 changes: 27 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Koerce Tests
on: [push, pull_request]

jobs:
ci:
name: ${{ matrix.os }} - Python ${{ matrix.python-version }}
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12"]
poetry-version: ["1.8"]
os: [ubuntu-22.04, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Run image
uses: abatilo/actions-poetry@v2
with:
poetry-version: ${{ matrix.poetry-version }}
- name: Install Koerce
run: poetry install
- name: Run tests
run: poetry run pytest koerce

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.DS_Store

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ Python Pattern Matching
-----------------------


Python support follows https://numpy.org/neps/nep-0029-deprecation_policy.html
20 changes: 9 additions & 11 deletions build.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
from __future__ import annotations

import os
import shutil
import multiprocessing
from pathlib import Path
from setuptools import Distribution

import Cython.Compiler.Options
from Cython.Build import cythonize
from Cython.Distutils import build_ext
from setuptools import Distribution

Cython.Compiler.Options.cimport_from_pyx = True

SOURCE_DIR = Path("koerce")
BUILD_DIR = Path("cython_build")


# extension_modules = get_extension_modules()
cythonized_modules = cythonize(
[
# "koerce/utils.py",
"koerce/patterns.py",
"koerce/builders.py",
],
# module_list=extension_modules,
# Don't build in source tree (this leaves behind .c files)
build_dir=BUILD_DIR,
# Don't generate an .html output file. Would contain source.
# generate anannotated .html output files.
annotate=True,
# Parallelize our build
# nthreads=multiprocessing.cpu_count() * 2,
# Tell Cython we're using Python 3. Becomes default in Cython 3
compiler_directives={"language_level": "3"},
# (Optional) Always rebuild, even if files untouched
# force=True,
# always rebuild, even if files untouched
force=False,
)

dist = Distribution({"ext_modules": cythonized_modules})
Expand Down
7 changes: 5 additions & 2 deletions koerce/builders.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from __future__ import annotations
import cython
from typing import Any, Callable

import collections.abc
import operator
from collections.abc import Callable
from typing import Any

import cython

Context = dict[str, Any]

Expand Down
36 changes: 20 additions & 16 deletions koerce/patterns.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
from __future__ import annotations
import cython

import importlib
from collections.abc import Callable, Mapping, Sequence
from enum import Enum
from types import UnionType
from typing import (
Annotated,
Any,
TypeVar,
ForwardRef,
Mapping,
Literal,
Sequence,
Union,
Annotated,
Callable,
Optional,
TypeVar,
Union,
)
from typing_extensions import GenericMeta

import cython
from typing_extensions import GenericMeta, get_original_bases

from .builders import Builder, Deferred, Variable, builder
from .utils import (
get_type_origin,
get_type_boundvars,
RewindableIterator,
get_type_args,
get_type_boundvars,
get_type_origin,
get_type_params,
get_original_bases,
RewindableIterator,
)
from abc import abstractmethod

# from cython.cimports.builders import Builder, Deferred, builder
from .builders import Builder, Deferred, builder, Variable


class CoercionError(Exception):
Expand Down Expand Up @@ -815,6 +812,11 @@ def match(self, value, ctx: Context):
return value


def NoneOf(*args) -> Pattern:
"""Match none of the passed patterns."""
return Not(AnyOf(*args))


@cython.final
@cython.cclass
class Option(Pattern):
Expand Down Expand Up @@ -1642,6 +1644,8 @@ def pattern(obj: Any, allow_custom: bool = True) -> Pattern:
obj
The object to create a pattern from. Can be a pattern, a type, a callable,
a mapping, an iterable or a value.
allow_custom
Whether to allow custom functions to be used as patterns.
Examples
--------
Expand Down
7 changes: 5 additions & 2 deletions koerce/sugar.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from .patterns import Pattern, pattern, Context
from typing import Callable, Optional, Any
from __future__ import annotations

import sys
from typing import Any

from .patterns import Context, Pattern, pattern

# if_
# isa
Expand Down
Empty file added koerce/tests/__init__.py
Empty file.
22 changes: 13 additions & 9 deletions koerce/tests/test_builders.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
from __future__ import annotations

import operator

import pytest

from koerce.builders import (
Variable,
Just,
Attr,
Binop,
Call,
Call0,
Call1,
Call2,
Call3,
CallN,
Unop,
Binop,
Custom,
Deferred,
Item,
Attr,
Sequence,
Just,
Mapping,
Custom,
Sequence,
Unop,
Variable,
builder,
)
import pytest
import operator

_ = Deferred(Variable("_"))

Expand Down
Loading

0 comments on commit 97a6964

Please sign in to comment.