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
32 changes: 25 additions & 7 deletions .github/workflows/minimal-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,40 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.7, 3.8, 3.9]
os: [ubuntu-18.04]
python-version: ['3.8', '3.9', '3.10']
flask-version: [latest]
os: [ubuntu-20.04]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v3
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitHub was encouraging us to update to the most recent action versions, seems harmless


- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install poetry
run: pip install poetry
- name: Force the chosen flask version
run: poetry add flask==${{ matrix.flask-version }}
run: pip3 install poetry

- name: Force Python version (linux/macOS)
if: matrix.os != 'windows-latest'
# sed command for macOS: https://stackoverflow.com/a/44864004
run: sed -i.bak 's/python = "^3.6"/python = "~${{ matrix.python-version }}"/' pyproject.toml
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find a better way than sed-replacing the python version in pyproject.toml to the fixed, desired 3.X version.


- name: Force Python version (windows)
if: matrix.os == 'windows-latest'
run: (Get-Content pyproject.toml).replace('python = "^3.6"', 'python = "~${{ matrix.python-version }}"') | Set-Content pyproject.toml

- name: Force Flask version
run: poetry add Flask==${{ matrix.flask-version }}

- name: Install requirements
run: poetry install

- name: List installed package versions for manual inspection
run: poetry --version && poetry show
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to control what packages we exactly installed in the end


- name: Test package
run: poetry run test

- name: Test package
run: poetry run doctest
11 changes: 9 additions & 2 deletions .github/workflows/publish-prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,29 @@ jobs:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, 'nodeploy')"
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: 3.7

- name: Install poetry
run: pip install poetry

- name: Install requirements
run: poetry install

- name: Build package
run: poetry build

- name: Test package
run: poetry run pytest

- name: Check if already uploaded
id: check_pypi
run: poetry run check_pypi_prerelease
continue-on-error: true

- name: publish to pypi
run: poetry publish -u __token__ -p ${{ secrets.PYPI_TOKEN }}
if: steps.check_pypi.outcome == 'success'
13 changes: 10 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Deploy release version to pypi
on:
push:
branches:
branches:
- main

jobs:
Expand All @@ -11,19 +11,26 @@ jobs:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, 'nodeploy')"
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: 3.7

- name: Install poetry
run: pip install poetry

- name: Install requirements
run: poetry install

- name: Build package
run: poetry build

- name: Test package
run: poetry run pytest

- name: Check if already uploaded
run: poetry run check_pypi

- name: publish to pypi
run: poetry publish -u __token__ -p ${{ secrets.PYPI_TOKEN }}
174 changes: 161 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,174 @@ on:
- pull_request

jobs:

testing:
strategy:
fail-fast: false
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]
os: [ubuntu-18.04, macos-latest, windows-latest]
flask-version: ["1.0", 1.1, "2.0", latest]
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10', '3.x']
flask-version: ['1.0', '1.1', '2.0', '2.1', 'latest']
os: [ubuntu-20.04, macos-latest, windows-latest]
exclude:
# starting from Flask 2.1.0, python 3.6 is no longer supported:
- flask-version: '2.1'
python-version: '3.6'

- flask-version: 'latest'
python-version: '3.6'

# old versions of Flask no longer working with python >= 3.10:
- flask-version: '1.0'
python-version: '3.10'

- flask-version: '1.0'
python-version: '3.x'

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install poetry
run: pip install poetry
- name: Force the chosen flask version
run: poetry add flask==${{ matrix.flask-version }}
- name: Install requirements
run: poetry install

- name: Install dev dependencies (python 3.6)
if: matrix.python-version == '3.6'
run: |
pip3 install poetry
poetry export --dev --without-hashes --format requirements.txt --output requirements-dev.txt
pip3 install -r requirements-dev.txt

- name: Install Flask ${{ matrix.flask-version }}
if: matrix.flask-version != 'latest'
run: pip3 install Flask==${{ matrix.flask-version }}

- name: Install latest Flask
if: matrix.flask-version == 'latest'
run: pip3 install Flask

- name: Install dev dependencies (python >= 3.7)
if: matrix.python-version != '3.6'
run: |
pip3 install poetry
poetry export --only dev --format requirements.txt --output requirements-dev.txt
pip3 install -r requirements-dev.txt

- name: Overwrite Flask dependencies for legacy install
if: matrix.flask-version < '2.0' && matrix.flask-version != 'latest'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a typo? you are checking flask-version twice

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Sorry, just seeing this now)

I wasn't sure how matrix.flask-version < 2.0 would behave in the case where matrix.flask-version == 'latest'.
Now I think matrix.flask-version < '2.0' would be sufficient.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some packages that are now too recent when installed via the Flask 1.X dependencies

run: |
pip3 install "Jinja2<3.0"
pip3 install "MarkupSafe<=2.0.1"
pip3 install "itsdangerous<=2.0.1"

- name: Overwrite Flask dependencies for legacy install (2)
if: matrix.flask-version < '2.1' && matrix.flask-version != 'latest'
run: pip3 install "werkzeug<=2.0.3"

- name: List installed package versions for manual inspection
run: python3 --version && pip3 list

- name: Run unit tests
run: poetry run test
run: python3 -c "from run_tests import test; test()"

- name: Run doctests
run: poetry run doctest
run: python3 -c "from run_tests import run_doctest; run_doctest()"

check_pip_install:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's put this in a different workflow file?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a different test strategy:

  • given a specific Python runtime version
  • given a specific Flask version installed
  • try installing flask-selfdoc via pip and check that we can use it without ImportError
    => this basically tests the dependency configuration in pyproject.toml

strategy:
fail-fast: false
matrix:
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10', '3.x']
flask-version: ['1.0', '1.1', '2.0', '2.1', 'latest']
os: [ubuntu-20.04, macos-latest, windows-latest]
exclude:
# starting from Flask 2.1.0, python 3.6 is no longer supported:
- flask-version: '2.1'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps we should just allow all runs with python 3.6 to fail (or skip them), since it's EOL?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess now that python 3.6 is EOL we can indeed simplify the logic and stop testing on it

python-version: '3.6'

- flask-version: 'latest'
python-version: '3.6'

# old versions of Flask no longer working with python >= 3.10:
- flask-version: '1.0'
python-version: '3.10'

- flask-version: '1.0'
python-version: '3.x'

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dev dependencies (python 3.6)
# actually installs all dependencies (no --only flag in this version)
# so we run this without installing the target Flask version
if: matrix.python-version == '3.6'
run: |
pip3 install poetry
poetry export --dev --without-hashes --format requirements.txt --output requirements-dev.txt
pip3 install -r requirements-dev.txt

- name: Install Flask ${{ matrix.flask-version }}
if: matrix.flask-version != 'latest'
run: pip3 install Flask==${{ matrix.flask-version }}

- name: Install latest Flask
if: matrix.flask-version == 'latest'
run: pip3 install Flask

- name: Install current flask-selfdoc from GitHub (linux/macOS)
if: matrix.os != 'windows-latest'
run: |
git_url="${{ github.event.pull_request.head.repo.git_url }}@${{ github.event.pull_request.head.ref }}"
git_url="git+https${git_url:3}"
pip3 install ${git_url}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is currently failing


- name: Install current flask-selfdoc from GitHub (windows)
if: matrix.os == 'windows-latest'
run: |
$git_url = "${{ github.event.pull_request.head.repo.git_url }}@${{ github.event.pull_request.head.ref }}"
$git_url = $git_url.subString(3)
$git_url = "git+https$git_url"
pip3 install $git_url

- name: Install dev dependencies (python >= 3.7)
if: matrix.python-version != '3.6'
run: |
pip3 install poetry
poetry export --only dev --format requirements.txt --output requirements-dev.txt
pip3 install -r requirements-dev.txt

- name: Overwrite Flask dependencies for legacy install
if: matrix.flask-version < '2.0' && matrix.flask-version != 'latest'
run: |
pip3 install "Jinja2<3.0"
pip3 install "MarkupSafe<=2.0.1"
pip3 install "itsdangerous<=2.0.1"

- name: Overwrite Flask dependencies for legacy install (2)
if: matrix.flask-version < '2.1' && matrix.flask-version != 'latest'
run: pip3 install "werkzeug<=2.0.3"

- name: List installed package versions for manual inspection
run: python3 --version && pip3 list
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

control what package versions we exactly installed


- name: Check that Flask version did not change
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

control that pip's dependency solver didn't need to update the already installed version of Flask

# not implemented for windows yet
if: matrix.flask-version != 'latest' && matrix.os != 'windows-latest'
run: |
flask_version=$(pip3 show Flask | grep Version:)
echo "found Flask ${flask_version}"
if [[ $(pip3 show Flask | grep Version) == *"Version: ${{ matrix.flask-version }}"* ]]
then
echo "No reinstall of Flask was done 👍"
else
exit 1
fi

- name: Try importing flask_selfdoc
run: python3 -c "import flask_selfdoc"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arguably we could run some tests or an example after importing this way?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remember correctly the issue I fixed happened only at import time, but yes running an example is a good idea.

10 changes: 5 additions & 5 deletions examples/custom/blog.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from os import path
from json import dumps

from flask import Flask, redirect, request, jsonify
from flask import Flask, redirect, request
from flask_selfdoc.autodoc import custom_jsonify
from flask_selfdoc import Autodoc


Expand Down Expand Up @@ -58,7 +58,7 @@ def get_post(id):

@app.route('/post', methods=["POST"])
@auto.doc(groups=['posts', 'private'],
form_data=['title', 'content', 'authorid'])
form_data=['title', 'content', 'authorid'])
def post_post():
"""Create a new post."""
authorid = request.form.get('authorid', None)
Expand All @@ -84,7 +84,7 @@ def get_user(id):

@app.route('/users', methods=['POST'])
@auto.doc(groups=['users', 'private'],
form_data=['username'])
form_data=['username'])
def post_user(id):
"""Creates a new user."""
User(request.form['username'])
Expand All @@ -111,7 +111,7 @@ def private_doc():

@app.route('/doc/json')
def public_doc_json():
return jsonify(auto.generate())
return custom_jsonify(auto.generate(), indent=4, separators=(',', ': '))


if __name__ == '__main__':
Expand Down
7 changes: 4 additions & 3 deletions examples/simple/blog.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from json import dumps

from flask import Flask, redirect, request, jsonify
from flask import Flask, redirect, request
from flask_selfdoc.autodoc import custom_jsonify
from flask_selfdoc import Autodoc


Expand Down Expand Up @@ -128,12 +129,12 @@ def private_doc():

@app.route('/doc/json')
def public_doc_json():
return jsonify(auto.generate())
return custom_jsonify(auto.generate(), indent=4, separators=(',', ': '))


@app.route('/doc/builtin_json')
def public_doc_builtin_json():
return auto.json()
return auto.json(indent=2, separators=(',', ': '))


if __name__ == '__main__':
Expand Down
Loading