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
2 changes: 1 addition & 1 deletion .github/workflows/publish-to-pypi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: 3.11

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ jobs:
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-docker-flask-inputfilter-env-${{ hashFiles('env_configs/Dockerfile') }}
key: ${{ runner.os }}-docker-flask-inputfilter-env-${{ hashFiles('env_configs/env.Dockerfile') }}
restore-keys: |
${{ runner.os }}-docker-flask-inputfilter-env-

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3
with:
driver-opts: image=moby/buildkit:latest

Expand All @@ -32,7 +32,7 @@ jobs:
--cache-from=type=local,src=/tmp/.buildx-cache \
--cache-to=type=local,dest=/tmp/.buildx-cache,mode=max \
-t flask-inputfilter-env \
-f env_configs/Dockerfile \
-f env_configs/env.Dockerfile \
. --load

- name: Run tests in Docker
Expand Down
44 changes: 40 additions & 4 deletions .github/workflows/test-lib-building.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ on:
pull_request:

jobs:
build-and-test:
build-and-test-pure:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
- name: Remove g++ compiler
run: sudo apt-get remove --purge -y g++

- uses: actions/setup-python@v5
with:
python-version: 3.11

Expand All @@ -25,10 +28,43 @@ jobs:
id: build

- name: Install built library
run: pip install "$(ls dist/*.whl | head -n 1)[optional]"
run: pip install "$(ls dist/*.tar.gz | head -n 1)[optional]"

- name: Verify library usage - Part I
run: python -c "import flask_inputfilter.InputFilter"
run: |
python -c "import flask_inputfilter.InputFilter"
python -c "from flask_inputfilter import InputFilter"

- name: Verify library usage - Part II
run: pytest tests/

build-and-test-cython:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Install compilers
run: sudo apt-get install -y g++

- uses: actions/setup-python@v5
with:
python-version: 3.11

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

- name: Build the library
run: python -m build
id: build

- name: Install built library
run: pip install "$(ls dist/*.tar.gz | head -n 1)[optional]"

- name: Verify library usage - Part I
run: |
python -c "import flask_inputfilter.InputFilter"
python -c "from flask_inputfilter import InputFilter"

#- name: Verify library usage - Part II
# run: pytest tests/
52 changes: 44 additions & 8 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ permissions:
contents: read

jobs:
build:
build-and-test-pure:
runs-on: ubuntu-latest

steps:
Expand All @@ -17,21 +17,21 @@ jobs:
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-docker-flask-inputfilter-${{ hashFiles('Dockerfile') }}
key: ${{ runner.os }}-docker-flask-inputfilter-pure-${{ hashFiles('env_configs/pure.Dockerfile') }}
restore-keys: |
${{ runner.os }}-docker-flask-inputfilter-
${{ runner.os }}-docker-flask-inputfilter-pure-

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3
with:
driver-opts: image=moby/buildkit:latest

- name: Build flask-inputfilter image with cache
- name: Build flask-inputfilter-pure image with cache
run: |
docker buildx build \
--cache-from=type=local,src=/tmp/.buildx-cache \
--cache-to=type=local,dest=/tmp/.buildx-cache,mode=max \
-t flask-inputfilter . --load
-t flask-inputfilter-pure -f env_configs/pure.Dockerfile . --load

- name: Run tests in Docker and upload coverage to Coveralls
env:
Expand All @@ -41,12 +41,48 @@ jobs:
set -e # Exit immediately if a command exits with a non-zero status.
set -u # Exit immediately if a variable is not defined.

docker run --rm -e COVERALLS_REPO_TOKEN=${{ secrets.COVERALLS_REPO_TOKEN }} flask-inputfilter sh -c "coverage run --source=flask_inputfilter -m pytest tests/ && coveralls"
docker run --rm -e COVERALLS_REPO_TOKEN=${{ secrets.COVERALLS_REPO_TOKEN }} flask-inputfilter-pure sh -c "coverage run --source=flask_inputfilter -m pytest tests/ && coveralls"

- name: Run code style checks
run: |
set -x # Print commands and their arguments as they are executed
set -e # Exit immediately if a command exits with a non-zero status
set -u # Exit immediately if a variable is not defined

docker run --rm flask-inputfilter flake8
docker run --rm flask-inputfilter-pure flake8

build-and-test-cython:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-docker-flask-inputfilter-cython-${{ hashFiles('env_configs/cython.Dockerfile') }}
restore-keys: |
${{ runner.os }}-docker-flask-inputfilter-cython-

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: image=moby/buildkit:latest

- name: Build flask-inputfilter-cython image with cache
run: |
docker buildx build \
--cache-from=type=local,src=/tmp/.buildx-cache \
--cache-to=type=local,dest=/tmp/.buildx-cache,mode=max \
-t flask-inputfilter-cython -f env_configs/cython.Dockerfile . --load

- name: Run tests in Docker
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
run: |
set -x # Print commands and their arguments as they are executed.
set -e # Exit immediately if a command exits with a non-zero status.
set -u # Exit immediately if a variable is not defined.

docker run --rm flask-inputfilter-cython pytest
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:
flask-inputfilter:
build:
context: .
dockerfile: Dockerfile
dockerfile: env_configs/cython.Dockerfile
container_name: flask-inputfilter
volumes:
- .:/app
Expand Down
9 changes: 9 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ Changelog

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

[0.4.0a2] - 2025-04-17
----------------------

Changed
^^^^^^^
- Added fallback for ``cython`` to use ``python`` if no c++ compiler is installed.
- super().__init__() is now **ONLY** optional, if you are using the cython version.


[0.4.0a1] - 2025-04-17
----------------------

Expand Down
2 changes: 1 addition & 1 deletion docs/source/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.4.0a1"
release = "0.4.0a2"

extensions = ["sphinx_rtd_theme"]

Expand Down
1 change: 1 addition & 0 deletions docs/source/guides/frontend_validation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Example implementation

class UpdateZipcodeInputFilter(InputFilter):
def __init__(self):
super().__init__()

self.add(
'id',
Expand Down
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Definition

class UpdateZipcodeInputFilter(InputFilter):
def __init__(self):
super().__init__()

self.add(
'id',
Expand Down
18 changes: 18 additions & 0 deletions docs/source/options/condition.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Example

class TestInputFilter(InputFilter):
def __init__(self):
super().__init__()

self.add(
'username',
Expand Down Expand Up @@ -88,6 +89,7 @@ Validates that the length of the array from ``first_array_field`` is equal to th

class ArrayLengthFilter(InputFilter):
def __init__(self):
super().__init__()

self.add(
'list1',
Expand Down Expand Up @@ -127,6 +129,7 @@ Validates that the array in ``longer_field`` has more elements than the array in

class ArrayComparisonFilter(InputFilter):
def __init__(self):
super().__init__()

self.add(
'list1',
Expand Down Expand Up @@ -168,6 +171,7 @@ Executes the provided callable with the input data. The condition passes if the

class CustomFilter(InputFilter):
def __init__(self):
super().__init__()

self.add(
'age',
Expand Down Expand Up @@ -201,6 +205,7 @@ Validates that the values of ``first_field`` and ``second_field`` are equal. Fai

class EqualFieldsFilter(InputFilter):
def __init__(self):
super().__init__()

self.add(
'password'
Expand Down Expand Up @@ -237,6 +242,7 @@ Counts the number of specified fields present in the data and validates that the

class ExactFieldsFilter(InputFilter):
def __init__(self):
super().__init__()

self.add(
'field1'
Expand Down Expand Up @@ -278,6 +284,7 @@ Validates that exactly ``n`` fields among the specified ones have the given valu

class MatchFieldsFilter(InputFilter):
def __init__(self):
super().__init__()

self.add(
'field1'
Expand Down Expand Up @@ -313,6 +320,7 @@ Validates that only one field among the specified fields exists in the input dat

class OneFieldFilter(InputFilter):
def __init__(self):
super().__init__()

self.add(
'email'
Expand Down Expand Up @@ -349,6 +357,7 @@ Validates that exactly one of the specified fields has the given value.

class OneMatchFilter(InputFilter):
def __init__(self):
super().__init__()

self.add(
'option1'
Expand Down Expand Up @@ -386,6 +395,7 @@ Validates that the integer value from ``bigger_field`` is greater than the value

class NumberComparisonFilter(InputFilter):
def __init__(self):
super().__init__()

self.add(
'field_should_be_bigger',
Expand Down Expand Up @@ -424,6 +434,7 @@ Validates that the count of the specified fields present is greater than or equa

class MinimumFieldsFilter(InputFilter):
def __init__(self):
super().__init__()

self.add(
'field1'
Expand Down Expand Up @@ -465,6 +476,7 @@ Validates that the count of fields matching the given value is greater than or e

class MinimumMatchFilter(InputFilter):
def __init__(self):
super().__init__()

self.add(
'field1'
Expand Down Expand Up @@ -501,6 +513,7 @@ Validates that the values of ``first_field`` and ``second_field`` are not equal.

class DifferenceFilter(InputFilter):
def __init__(self):
super().__init__()

self.add(
'field1'
Expand Down Expand Up @@ -536,6 +549,7 @@ Validates that at least one field from the specified list is present. Fails if n

class OneFieldRequiredFilter(InputFilter):
def __init__(self):
super().__init__()

self.add(
'email'
Expand Down Expand Up @@ -572,6 +586,7 @@ Validates that at least one field from the specified list has the given value.

class OneMatchRequiredFilter(InputFilter):
def __init__(self):
super().__init__()

self.add(
'option1'
Expand Down Expand Up @@ -609,6 +624,7 @@ If the value of ``condition_field`` matches the specified value (or is in the sp

class ConditionalRequiredFilter(InputFilter):
def __init__(self):
super().__init__()

self.add(
'status'
Expand Down Expand Up @@ -651,6 +667,7 @@ Validates that the string in ``longer_field`` has a greater length than the stri

class StringLengthFilter(InputFilter):
def __init__(self):
super().__init__()

self.add(
'description'
Expand Down Expand Up @@ -687,6 +704,7 @@ Validates that the date in ``smaller_date_field`` is earlier than the date in ``

class DateOrderFilter(InputFilter):
def __init__(self):
super().__init__()

self.add(
'start_date'
Expand Down
2 changes: 2 additions & 0 deletions docs/source/options/copy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Basic Copy Integration

class MyInputFilter(InputFilter):
def __init__(self):
super().__init__()

self.add(
"username"
Expand Down Expand Up @@ -56,6 +57,7 @@ The coping can also be used as a chain.

class MyInputFilter(InputFilter):
def __init__(self):
super().__init__()

self.add(
"username"
Expand Down
Loading