Improve pydantic/_internal/_decorators_v1.py
docstring
#8221
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
on: | |
push: | |
branches: | |
- main | |
tags: | |
- '**' | |
pull_request: {} | |
env: | |
COLUMNS: 150 | |
PDM_DEPS: 'urllib3<2' | |
jobs: | |
lint: | |
runs-on: ubuntu-latest | |
name: lint ${{ matrix.python-version }} | |
strategy: | |
fail-fast: false | |
matrix: | |
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11'] | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: pdm-project/setup-pdm@v3 | |
with: | |
python-version: ${{ matrix.python-version }} | |
cache: true | |
version: 2.7.0 | |
- name: install | |
run: pdm install -G linting -G email | |
- uses: pre-commit/action@v3.0.0 | |
with: | |
extra_args: --all-files --verbose | |
- name: make history | |
run: pdm run python3 ./changes/make_history.py | |
docs-build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: pdm-project/setup-pdm@v3 | |
with: | |
# cloudflare pages build containers run 3.8, hence using it here | |
python-version: '3.8' | |
cache: true | |
version: 2.7.0 | |
- name: install dependencies | |
run: pdm install -G docs | |
- run: pdm run python -c 'import docs.plugins.main' | |
- run: pdm run mkdocs build --verbose | |
test-memray: | |
name: test memray | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: pdm-project/setup-pdm@v3 | |
with: | |
python-version: '3.10' | |
cache: true | |
version: 2.7.0 | |
- name: install deps | |
run: | | |
pdm install -G testing -G testing-extra -G email -G memray | |
pdm add pytest-memray | |
- name: test | |
run: pdm run pytest --ignore=tests/mypy/ --ignore=tests/test_docs.py --memray | |
test: | |
name: test ${{ matrix.os }} / ${{ matrix.python-version }} | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [ubuntu, macos, windows] | |
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11'] | |
include: | |
# no pydantic-core binaries for pypy on windows, so tests take absolute ages | |
# macos tests with pypy take ages (>10mins) since pypy is very slow | |
# so we only test pypy on ubuntu | |
- os: ubuntu | |
python-version: 'pypy3.7' | |
- os: ubuntu | |
python-version: 'pypy3.8' | |
- os: ubuntu | |
python-version: 'pypy3.9' | |
env: | |
PYTHON: ${{ matrix.python-version }} | |
OS: ${{ matrix.os }} | |
DEPS: yes | |
runs-on: ${{ matrix.os }}-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: pdm-project/setup-pdm@v3 | |
with: | |
python-version: ${{ matrix.python-version }} | |
cache: true | |
version: 2.7.0 | |
- name: install deps | |
run: pdm install -G testing | |
- run: pdm info && pdm list | |
- run: 'pdm run python -c "import pydantic.version; print(pydantic.version.version_info())"' | |
- run: mkdir coverage | |
- name: test without deps | |
# speed up by skipping this step on pypy | |
if: "!startsWith(matrix.python-version, 'pypy')" | |
run: make test | |
env: | |
COVERAGE_FILE: coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }}-without-deps | |
CONTEXT: ${{ runner.os }}-py${{ matrix.python-version }}-without-deps | |
- name: install extra deps | |
run: pdm install -G testing-extra -G email | |
- name: test with deps | |
run: make test | |
env: | |
COVERAGE_FILE: coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }}-with-deps | |
CONTEXT: ${{ runner.os }}-py${{ matrix.python-version }}-with-deps | |
- name: store coverage files | |
uses: actions/upload-artifact@v3 | |
with: | |
name: coverage | |
path: coverage | |
test-mypy: | |
name: mypy ${{ matrix.mypy-version }} / ${{ matrix.python-version }} | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
# test recent mypy versions on 3.10 and mypy 1.0.1 on all supported python versions | |
# if you change the value in the lockfile add the old value to this list | |
mypy-version: ['0.971', '0.982', '0.991', '1.0.1', 'lockfile'] | |
python-version: ['3.10'] | |
include: | |
- mypy-version: '1.0.1' | |
python-version: '3.7' | |
- mypy-version: '1.0.1' | |
python-version: '3.8' | |
- mypy-version: '1.0.1' | |
python-version: '3.9' | |
- mypy-version: '1.0.1' | |
python-version: '3.11' | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: pdm-project/setup-pdm@v3 | |
with: | |
python-version: ${{ matrix.python-version }} | |
cache: true | |
version: 2.7.0 | |
- name: install deps | |
run: | | |
pdm install -G testing -G mypy | |
- name: install mypy | |
if: steps.cache.outputs.cache-hit != 'true' | |
run: | | |
if [ ${{ matrix.mypy-version }} != 'lockfile' ]; then | |
pdm remove mypy && pdm add mypy==${{ matrix.mypy-version }} | |
fi | |
pdm list | |
- run: mkdir coverage | |
- name: run mypy tests | |
run: pdm run coverage run -m pytest tests/mypy --test-mypy | |
env: | |
COVERAGE_FILE: coverage/.coverage.linux-py${{ matrix.python-version }}-mypy${{ matrix.mypy-version }} | |
CONTEXT: linux-py${{ matrix.python-version }}-mypy${{ matrix.mypy-version }} | |
- name: install node for pyright | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '18' | |
- name: install pyright | |
run: npm install -g pyright@1.1.302 # try to keep this in sync with .pre-commit-config.yaml | |
- name: run pyright tests | |
run: make test-pyright | |
env: | |
COVERAGE_FILE: coverage/.coverage.linux-py${{ matrix.python-version }}-pyright | |
CONTEXT: linux-py${{ matrix.python-version }}-pyright | |
- name: store coverage files | |
uses: actions/upload-artifact@v3 | |
with: | |
name: coverage | |
path: coverage | |
coverage-combine: | |
needs: [test, test-mypy] | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-python@v4 | |
with: | |
python-version: '3.8' | |
- name: get coverage files | |
uses: actions/download-artifact@v3 | |
with: | |
name: coverage | |
path: coverage | |
- run: pip install coverage[toml] | |
- run: ls -la coverage | |
- run: coverage combine coverage | |
- run: coverage report | |
- run: coverage html --show-contexts --title "pydantic coverage for ${{ github.sha }}" | |
- name: Store coverage html | |
uses: actions/upload-artifact@v3 | |
with: | |
name: coverage-html | |
path: htmlcov | |
test-fastapi: | |
# FastAPI has a version constraint of pydantic<2.0.0, | |
# so we can't run tests, we expect them to break for now anyway | |
# FIXME: drop this comment and the if-clause once that's fixed | |
if: false | |
name: test fastAPI | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: set up python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.10' | |
- name: install | |
run: | | |
pdm install -G :all | |
- name: test | |
run: make test-fastapi | |
test-typing-extensions: | |
name: test typing-extensions | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
# test the oldest supported version and main | |
typing-extensions-version: ['4.6.1', 'main'] | |
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11'] | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: pdm-project/setup-pdm@v3 | |
with: | |
python-version: ${{ matrix.python-version }} | |
cache: true | |
version: 2.7.0 | |
- name: install deps | |
run: | | |
pdm install -G testing -G email | |
- name: install typing-extensions | |
run: | | |
if [ ${{ matrix.typing-extensions-version }} == 'main' ]; then | |
pdm remove typing-extensions && pdm add 'git+https://github.com/python/typing_extensions.git' | |
else | |
pdm remove typing-extensions && pdm add 'typing-extensions==${{ matrix.typing-extensions-version }}' | |
fi | |
pdm list | |
- name: test | |
run: make test | |
test-pydantic-settings: | |
name: test pydantic settings | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: test | |
run: make test-pydantic-settings | |
# https://github.com/marketplace/actions/alls-green | |
check: # This job does nothing and is only used for the branch protection | |
if: always() | |
outputs: | |
result: ${{ steps.all-green.outputs.result }} | |
needs: | |
- lint | |
- docs-build | |
- test | |
- test-memray | |
- test-mypy | |
- test-fastapi | |
- test-pydantic-settings | |
runs-on: ubuntu-latest | |
steps: | |
- name: Decide whether the needed jobs succeeded or failed | |
uses: re-actors/alls-green@release/v1 | |
id: all-green | |
with: | |
allowed-skips: test-fastapi # TODO: drop once re-enabled | |
jobs: ${{ toJSON(needs) }} | |
publish_docs: | |
needs: [check] | |
# `always()` is required to trigger this task even though test-fastapi is skipped | |
if: "always() && needs.check.outputs.result == 'success' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))" | |
runs-on: ubuntu-latest | |
steps: | |
- name: checkout docs-site | |
uses: actions/checkout@v3 | |
with: | |
ref: docs-site | |
- name: checkout current branch | |
uses: actions/checkout@v3 | |
- uses: pdm-project/setup-pdm@v3 | |
with: | |
python-version: '3.10' | |
cache: true | |
version: 2.7.0 | |
- name: install | |
run: | | |
pdm install -G docs | |
pdm run pip install https://files.scolvin.com/${MKDOCS_TOKEN}/mkdocs-material/mkdocs_material-9.1.5+insiders.4.32.4-py3-none-any.whl | |
env: | |
MKDOCS_TOKEN: ${{ secrets.MKDOCS_TOKEN }} | |
- run: pdm run python -c 'import docs.plugins.main' | |
- name: Set git credentials | |
run: | | |
git config --global user.name "${{ github.actor }}" | |
git config --global user.email "${{ github.actor }}@users.noreply.github.com" | |
- run: pdm run mike deploy -b docs-site dev-v2 --push | |
if: github.ref == 'refs/heads/main' | |
- name: check version | |
if: "startsWith(github.ref, 'refs/tags/')" | |
id: check-version | |
uses: samuelcolvin/check-python-version@v3.2 | |
with: | |
version_file_path: 'pydantic/version.py' | |
- run: mike deploy -b docs-site ${{ steps.check-version.outputs.VERSION_MAJOR_MINOR }} latest --update-aliases --push | |
if: "startsWith(github.ref, 'refs/tags/') && !fromJSON(steps.check-version.outputs.IS_PRERELEASE)" | |
release: | |
needs: [check, publish_docs] | |
# `always()` is required to trigger this task even though test-fastapi is skipped | |
if: "always() && needs.check.outputs.result == 'success' && startsWith(github.ref, 'refs/tags/')" | |
runs-on: ubuntu-latest | |
environment: release | |
permissions: | |
id-token: write | |
outputs: | |
pydantic-version: ${{ steps.check-tag.outputs.VERSION }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: set up python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.10' | |
- name: install | |
run: pip install -U build | |
- name: check version | |
id: check-tag | |
uses: samuelcolvin/check-python-version@v3.2 | |
with: | |
version_file_path: pydantic/version.py | |
- name: build | |
run: python -m build | |
- name: Upload package to PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
send-tweet: | |
name: Send tweet | |
runs-on: ubuntu-latest | |
needs: [release] | |
if: ${{ needs.release.status == 'success' }} | |
steps: | |
- uses: actions/setup-python@v4 | |
with: | |
python-version: '3.10' | |
- name: Install dependencies | |
run: pip install tweepy==4.14.0 | |
- name: Send tweet | |
shell: python | |
run: | | |
import os | |
import tweepy | |
client = tweepy.Client( | |
access_token=os.getenv("TWITTER_ACCESS_TOKEN"), | |
access_token_secret=os.getenv("TWITTER_ACCESS_TOKEN_SECRET"), | |
consumer_key=os.getenv("TWITTER_CONSUMER_KEY"), | |
consumer_secret=os.getenv("TWITTER_CONSUMER_SECRET"), | |
) | |
tweet = os.getenv("TWEET") | |
client.create_tweet(text=tweet) | |
env: | |
TWEET: | | |
Pydantic version ${{needs.release.outputs.pydantic-version}} is out! 🎉 | |
https://github.com/pydantic/pydantic/releases/tag/v${{needs.release.outputs.pydantic-version}} | |
TWITTER_CONSUMER_KEY: ${{ secrets.TWITTER_CONSUMER_KEY }} | |
TWITTER_CONSUMER_SECRET: ${{ secrets.TWITTER_CONSUMER_SECRET }} | |
TWITTER_ACCESS_TOKEN: ${{ secrets.TWITTER_ACCESS_TOKEN }} | |
TWITTER_ACCESS_TOKEN_SECRET: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }} |