Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 38 additions & 6 deletions .github/workflows/publish-to-pypi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ on:
types: [published]

jobs:
publish:
runs-on: ubuntu-latest
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- name: Checkout code
Expand All @@ -15,13 +18,42 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.9
python-version: 3.11

- name: Install build tools
run: pip install build twine wheel
run: pip install build twine wheel cibuildwheel

- name: Build wheel with cibuildwheel
env:
CIBW_BUILD: cp37-*,cp38-*,cp39-*,cp310-*,cp311-*,cp312-*,cp313-*,cp314-*
run: cibuildwheel --output-dir wheelhouse

- name: Upload wheels
uses: actions/upload-artifact@v3
with:
name: wheels-${{ matrix.os }}
path: wheelhouse/

publish:
needs: build
runs-on: ubuntu-latest

steps:
- name: Download wheels
uses: actions/download-artifact@v3
with:
name: wheels-ubuntu-latest
- name: Download wheels
uses: actions/download-artifact@v3
with:
name: wheels-windows-latest
- name: Download wheels
uses: actions/download-artifact@v3
with:
name: wheels-macos-latest

- name: Build package
run: python setup.py sdist bdist_wheel
- name: Combine wheels
run: mkdir dist && mv wheelhouse/* dist/

- name: Publish to PyPI
env:
Expand Down
31 changes: 18 additions & 13 deletions .github/workflows/test-lib-building.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build and Test Library
name: Run Tests on all environments

on:
push:
Expand All @@ -8,7 +8,10 @@ on:

jobs:
build-and-test:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- name: Checkout code
Expand All @@ -17,26 +20,28 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.9
python-version: 3.11

- name: Install build tools and test dependencies
run: |
pip install build pytest
run: pip install build pytest cython cibuildwheel

- name: Build the library
run: |
python -m build
id: build
- name: Build wheel with cibuildwheel
env:
CIBW_BUILD: cp311-*
run: cibuildwheel --output-dir wheelhouse

- name: Install built library
run: |
pip install dist/*.whl
run: pip install flask_inputfilter --find-links=wheelhouse/ --force-reinstall

- name: Verify library usage - Part I
run: |
echo "import flask_inputfilter" > test_script.py
python -c "import shutil; shutil.rmtree('flask_inputfilter', ignore_errors=True)"

echo "import flask_inputfilter.InputFilter" > test_script.py
python test_script.py

- name: Verify library usage - Part II
run: |
PYTHONPATH="" pytest test/
python -c "import shutil; shutil.rmtree('flask_inputfilter', ignore_errors=True)"

pytest test/
59 changes: 59 additions & 0 deletions .github/workflows/test-publish-to-pypi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Publish to PyPI

on:
release:
types: [published]

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.11

- name: Install build tools
run: pip install build twine wheel cibuildwheel

- name: Build wheel with cibuildwheel
env:
CIBW_BUILD: cp37-*,cp38-*,cp39-*,cp310-*,cp311-*,cp312-*,cp313-*,cp314-*
run: cibuildwheel --output-dir wheelhouse

- name: Upload wheels
uses: actions/upload-artifact@v3
with:
name: wheels-${{ matrix.os }}
path: wheelhouse/

publish:
needs: build
runs-on: ubuntu-latest

steps:
- name: Download wheels
uses: actions/download-artifact@v3
with:
name: wheels-ubuntu-latest
- name: Download wheels
uses: actions/download-artifact@v3
with:
name: wheels-windows-latest
- name: Download wheels
uses: actions/download-artifact@v3
with:
name: wheels-macos-latest

- name: Combine wheels
run: mkdir dist && mv wheelhouse/* dist/

- name: Publish to PyPI
run: ls -la dist
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run Tests
name: Run Tests and Lint

on: [push]

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_env.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run Tests on all environments
name: Run Tests on all python versions

on: [push]

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,5 @@ cython_debug/
.vscode/
.DS_Store
_build

*.c
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ COPY . /app

COPY scripts /usr/local/bin
RUN find /usr/local/bin -type f -name "*" -exec chmod +x {} \;

ENV flask_inputfilter_dev=true
6 changes: 6 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
include README.rst
include LICENSE
include docs/changelog.rst
include flask_inputfilter/*.py
include flask_inputfilter/*.pyx
include flask_inputfilter/*.pxd
include flask_inputfilter/*.so

exclude test/*
8 changes: 0 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build

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

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
8 changes: 8 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ Changelog

All notable changes to this project will be documented in this file.

[0.2.0] - 2025-03-26
--------------------

Changed
^^^^^^^
- Uses compiled version of InputFilter class to increase speed drastically.


[0.1.0] - 2025-03-26
--------------------

Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
project = "flask-inputfilter"
copyright = "2025, Leander Cain Slotosch"
author = "Leander Cain Slotosch"
release = "0.1.0"
release = "0.2.0"

extensions = ["sphinx_rtd_theme"]

Expand Down
2 changes: 2 additions & 0 deletions env_configs/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@ COPY ../requirements.txt /app
RUN pip install --no-cache-dir -r requirements.txt && pip install tox

COPY .. /app

ENV flask_inputfilter_dev=true
1 change: 1 addition & 0 deletions env_configs/requirements-py310.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
cython
flask==2.1
pillow==8.0.0
pytest
Expand Down
1 change: 1 addition & 0 deletions env_configs/requirements-py311.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
cython
flask==2.1
pillow==8.0.0
pytest
Expand Down
2 changes: 2 additions & 0 deletions env_configs/requirements-py312.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
cython
flask
pillow
pytest
requests
typing_extensions
setuptools
2 changes: 2 additions & 0 deletions env_configs/requirements-py313.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
cython
flask
pillow
pytest
requests
typing_extensions
setuptools
2 changes: 2 additions & 0 deletions env_configs/requirements-py314.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
cython
flask
pillow
pytest
requests
typing_extensions
setuptools
1 change: 1 addition & 0 deletions env_configs/requirements-py37.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
cython
flask==2.1
pillow==8.0.0
pytest
Expand Down
1 change: 1 addition & 0 deletions env_configs/requirements-py38.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
cython
flask==2.1
pillow==8.0.0
pytest
Expand Down
1 change: 1 addition & 0 deletions env_configs/requirements-py39.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
cython
flask==2.1
pillow==8.0.0
pytest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@
API_PLACEHOLDER_PATTERN = re.compile(r"{{(.*?)}}")


class InputFilter:
cdef class InputFilter:
"""
Base class for input filters.
"""
cdef readonly list __methods
cdef readonly dict __fields
cdef readonly list __conditions
cdef readonly list __global_filters
cdef readonly list __global_validators
cdef public dict __data
cdef readonly dict __validated_data
cdef readonly str __error_message

def __init__(self, methods: Optional[List[str]] = None) -> None:
self.__methods = methods or ["GET", "POST", "PATCH", "PUT", "DELETE"]
self.__methods: List[str] = methods or ["GET", "POST", "PATCH", "PUT", "DELETE"]
self.__fields: Dict[str, FieldModel] = {}
self.__conditions: List[BaseCondition] = []
self.__global_filters: List[BaseFilter] = []
Expand Down
2 changes: 1 addition & 1 deletion flask_inputfilter/Validator/IsIntegerValidator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ def __init__(self, error_message: Optional[str] = None) -> None:
def validate(self, value: Any) -> None:
if not isinstance(value, int):
raise ValidationError(
self.error_message, f"Value '{value}' is not an integer."
self.error_message or f"Value '{value}' is not an integer."
)
7 changes: 7 additions & 0 deletions flask_inputfilter/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
import os

if os.getenv("flask_inputfilter_dev"):
import pyximport

pyximport.install()

from .InputFilter import InputFilter
2 changes: 1 addition & 1 deletion make.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

pushd %~dp0

REM Command file for Sphinx documentation
REM

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["setuptools", "wheel"]
requires = ["setuptools", "wheel", "Cython"]
build-backend = "setuptools.build_meta"

[tool.black]
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ autoflake
black
coverage
coveralls
docformatter
cython
#docformatter
flake8==4.0.0
flask==2.1
isort
Expand Down
4 changes: 2 additions & 2 deletions scripts/lint
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ autoflake --in-place --remove-all-unused-imports --ignore-init-module-imports --
echo 'Running black'
black .

echo 'Running docformatter'
docformatter --in-place .
# echo 'Running docformatter'
# docformatter --in-place .
Loading