Skip to content

Commit 9a6ffb2

Browse files
committed
31 | Update implementation to include .so file
1 parent 34f97f3 commit 9a6ffb2

File tree

13 files changed

+105
-93
lines changed

13 files changed

+105
-93
lines changed

.github/workflows/publish-to-pypi.yaml

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ on:
55
types: [published]
66

77
jobs:
8-
publish:
9-
runs-on: ubuntu-latest
8+
build:
9+
runs-on: ${{ matrix.os }}
10+
strategy:
11+
matrix:
12+
os: [ubuntu-latest, windows-latest, macos-latest]
1013

1114
steps:
1215
- name: Checkout code
@@ -18,12 +21,39 @@ jobs:
1821
python-version: 3.9
1922

2023
- name: Install build tools
21-
run: pip install build twine wheel cython
24+
run: pip install build twine wheel cibuildwheel
25+
26+
- name: Build wheel with cibuildwheel
27+
env:
28+
CIBW_BUILD: cp37-*,cp38-*,cp39-*,cp310-*,cp311-*,cp312-*,cp313-*,cp314-*
29+
run: cibuildwheel --output-dir wheelhouse
30+
31+
- name: Upload wheels
32+
uses: actions/upload-artifact@v3
33+
with:
34+
name: wheels-${{ matrix.os }}
35+
path: wheelhouse/
36+
37+
publish:
38+
needs: build
39+
runs-on: ubuntu-latest
40+
41+
steps:
42+
- name: Download wheels
43+
uses: actions/download-artifact@v3
44+
with:
45+
name: wheels-ubuntu-latest
46+
- name: Download wheels
47+
uses: actions/download-artifact@v3
48+
with:
49+
name: wheels-windows-latest
50+
- name: Download wheels
51+
uses: actions/download-artifact@v3
52+
with:
53+
name: wheels-macos-latest
2254

23-
- name: Compile and Build package
24-
run: |
25-
python setup.py build_ext --inplace
26-
python setup.py sdist bdist_wheel
55+
- name: Combine wheels
56+
run: mkdir dist && mv wheelhouse/* dist/
2757

2858
- name: Publish to PyPI
2959
env:
Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build and Test Library
1+
name: Run Tests on all environments
22

33
on:
44
push:
@@ -8,7 +8,10 @@ on:
88

99
jobs:
1010
build-and-test:
11-
runs-on: ubuntu-latest
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
matrix:
14+
os: [ubuntu-latest, windows-latest, macos-latest]
1215

1316
steps:
1417
- name: Checkout code
@@ -20,22 +23,23 @@ jobs:
2023
python-version: 3.9
2124

2225
- name: Install build tools and test dependencies
23-
run: pip install build pytest cython
26+
run: pip install build pytest cython cibuildwheel
2427

25-
- name: Compile Cython code
26-
run: python setup.py build_ext --inplace
27-
28-
- name: Build the library
29-
run: python -m build
30-
id: build
28+
- name: Build wheel with cibuildwheel
29+
env:
30+
CIBW_BUILD: cp39-*
31+
run: cibuildwheel --output-dir wheelhouse
3132

3233
- name: Install built library
33-
run: pip install dist/*.whl
34+
run: pip install flask_inputfilter --find-links=wheelhouse/ --force-reinstall
3435

3536
- name: Verify library usage - Part I
3637
run: |
37-
echo "import flask_inputfilter" > test_script.py
38+
rm -rf flask_inputfilter
39+
echo "import flask_inputfilter.InputFilter" > test_script.py
3840
python test_script.py
3941
4042
- name: Verify library usage - Part II
41-
run: PYTHONPATH="" pytest test/
43+
run: |
44+
rm -rf flask_inputfilter
45+
pytest test/

.github/workflows/test_env.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Run Tests on all environments
1+
name: Run Tests on all python versions
22

33
on: [push]
44

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ COPY . /app
1414

1515
COPY scripts /usr/local/bin
1616
RUN find /usr/local/bin -type f -name "*" -exec chmod +x {} \;
17+
18+
ENV flask_inputfilter_dev=true

MANIFEST.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ include docs/changelog.rst
44
include flask_inputfilter/*.py
55
include flask_inputfilter/*.pyx
66
include flask_inputfilter/*.pxd
7+
include flask_inputfilter/*.so
8+
9+
exclude test/*

Makefile

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
1-
# Minimal makefile for Sphinx documentation
2-
#
3-
4-
# You can set these variables from the command line, and also
5-
# from the environment for the first two.
61
SPHINXOPTS ?=
72
SPHINXBUILD ?= sphinx-build
83
SOURCEDIR = source
94
BUILDDIR = build
105

11-
# Put it first so that "make" without argument is like "make help".
126
help:
137
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
148

159
.PHONY: help Makefile
1610

17-
# Catch-all target: route all unknown targets to Sphinx using the new
18-
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
1911
%: Makefile
2012
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

env_configs/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,5 @@ COPY ../requirements.txt /app
4949
RUN pip install --no-cache-dir -r requirements.txt && pip install tox
5050

5151
COPY .. /app
52+
53+
ENV flask_inputfilter_dev=true

flask_inputfilter/InputFilter.pyx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,21 @@ from flask_inputfilter.Validator import BaseValidator
1313
API_PLACEHOLDER_PATTERN = re.compile(r"{{(.*?)}}")
1414

1515

16-
class InputFilter:
16+
cdef class InputFilter:
1717
"""
1818
Base class for input filters.
1919
"""
20+
cdef readonly list __methods
21+
cdef readonly dict __fields
22+
cdef readonly list __conditions
23+
cdef readonly list __global_filters
24+
cdef readonly list __global_validators
25+
cdef public dict __data
26+
cdef readonly dict __validated_data
27+
cdef readonly str __error_message
2028

2129
def __init__(self, methods: Optional[List[str]] = None) -> None:
22-
self.__methods = methods or ["GET", "POST", "PATCH", "PUT", "DELETE"]
30+
self.__methods: List[str] = methods or ["GET", "POST", "PATCH", "PUT", "DELETE"]
2331
self.__fields: Dict[str, FieldModel] = {}
2432
self.__conditions: List[BaseCondition] = []
2533
self.__global_filters: List[BaseFilter] = []

flask_inputfilter/Validator/IsIntegerValidator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ def __init__(self, error_message: Optional[str] = None) -> None:
1515
def validate(self, value: Any) -> None:
1616
if not isinstance(value, int):
1717
raise ValidationError(
18-
self.error_message, f"Value '{value}' is not an integer."
18+
self.error_message or f"Value '{value}' is not an integer."
1919
)

flask_inputfilter/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
try:
2-
from .InputFilter import InputFilter
3-
except ImportError:
1+
import os
2+
3+
if os.getenv("flask_inputfilter_dev"):
44
import pyximport
55

66
pyximport.install()
7-
from .InputFilter import InputFilter
7+
8+
from .InputFilter import InputFilter

0 commit comments

Comments
 (0)