generated from daniil-berg/boilerplate-py
Compare commits
4 Commits
394921626f
...
master
Author | SHA1 | Date | |
---|---|---|---|
3f0e3db427
|
|||
862a517018
|
|||
3c16b4ebd6
|
|||
0e443f08b9
|
88
.github/workflows/ci.yaml
vendored
88
.github/workflows/ci.yaml
vendored
@ -1,70 +1,34 @@
|
||||
name: CI - Tests & Checks
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
branches: master
|
||||
tags: 'v*.*.*'
|
||||
|
||||
jobs:
|
||||
unit-tests:
|
||||
name: Execute unit tests (Python ${{ matrix.python-version }})
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
python-version:
|
||||
- '3.9'
|
||||
- '3.10'
|
||||
- '3.11'
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: actions/setup-python@v4
|
||||
test:
|
||||
name: Test
|
||||
uses: daniil-berg/reusable-workflows/.github/workflows/python-test.yaml@v0.2.1
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
cache: 'pip'
|
||||
cache-dependency-path: 'requirements/dev.txt'
|
||||
versions: '["3.9", "3.10", "3.11"]'
|
||||
unittest-command: 'scripts/test.sh'
|
||||
coverage-command: 'scripts/cov.sh'
|
||||
unittest-requirements: "-e '.[dev]'"
|
||||
typecheck-command: 'scripts/typecheck.sh'
|
||||
typecheck-requirements: '-Ur requirements/dev.txt'
|
||||
typecheck-all-versions: true
|
||||
lint-command: 'scripts/lint.sh'
|
||||
lint-requirements: '-Ur requirements/dev.txt'
|
||||
|
||||
- name: Upgrade pip
|
||||
run: pip install -U pip
|
||||
|
||||
- name: Install marshmallow-generic
|
||||
run: pip install -e '.[dev]'
|
||||
|
||||
- name: Run unit tests for Python ${{ matrix.python-version }}
|
||||
if: ${{ matrix.python-version != '3.11' }}
|
||||
run: python -m tests
|
||||
|
||||
- name: Run unit test coverage script for Python 3.11 and save total percentage
|
||||
if: ${{ matrix.python-version == '3.11' }}
|
||||
run: |
|
||||
total=$(./scripts/test.sh)
|
||||
[[ $? -eq 0 ]] && echo "coverage=${total}" >> $GITHUB_ENV
|
||||
outputs:
|
||||
coverage: ${{ env.coverage }}
|
||||
|
||||
lint:
|
||||
name: Run type checker and linters (Python ${{ matrix.python-version }})
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
python-version:
|
||||
- '3.9'
|
||||
- '3.10'
|
||||
- '3.11'
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- uses: actions/setup-python@v4
|
||||
release:
|
||||
name: Release
|
||||
if: ${{ github.ref_type == 'tag' }}
|
||||
needs: test
|
||||
uses: daniil-berg/reusable-workflows/.github/workflows/python-release.yaml@v0.2.1
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
cache: 'pip'
|
||||
cache-dependency-path: 'requirements/dev.txt'
|
||||
|
||||
- name: Upgrade pip
|
||||
run: pip install -U pip
|
||||
|
||||
- name: Install dependencies
|
||||
run: pip install -Ur requirements/dev.txt
|
||||
|
||||
- name: Run checks
|
||||
run: bash scripts/lint.sh
|
||||
git-ref: ${{ github.ref_name }}
|
||||
secrets:
|
||||
release-token: ${{ secrets.TOKEN_GITHUB_CREATE_RELEASE }}
|
||||
publish-token: ${{ secrets.TOKEN_PYPI_PROJECT }}
|
||||
permissions:
|
||||
contents: write
|
||||
|
@ -37,18 +37,15 @@ dynamic = [
|
||||
]
|
||||
|
||||
[project.optional-dependencies]
|
||||
full = [
|
||||
|
||||
]
|
||||
dev = [
|
||||
"black",
|
||||
"build",
|
||||
"coverage[toml]",
|
||||
"isort",
|
||||
"mkdocs-material",
|
||||
"mkdocstrings[python]",
|
||||
"mypy",
|
||||
"ruff",
|
||||
"black==23.3.0",
|
||||
"build==0.10.0",
|
||||
"coverage[toml]==7.2.3",
|
||||
"isort==5.12.0",
|
||||
"mkdocs-material==9.1.6",
|
||||
"mkdocstrings[python]==0.21.2",
|
||||
"mypy==1.2.0",
|
||||
"ruff==0.0.262",
|
||||
]
|
||||
|
||||
[project.urls]
|
||||
|
@ -1 +1 @@
|
||||
marshmallow
|
||||
marshmallow>=3.12.0
|
@ -1,9 +1,9 @@
|
||||
-r common.txt
|
||||
black
|
||||
build
|
||||
coverage[toml]
|
||||
isort
|
||||
mkdocs-material
|
||||
mkdocstrings[python]
|
||||
mypy
|
||||
ruff
|
||||
black==23.3.0
|
||||
build==0.10.0
|
||||
coverage[toml]==7.2.3
|
||||
isort==5.12.0
|
||||
mkdocs-material==9.1.6
|
||||
mkdocstrings[python]==0.21.2
|
||||
mypy==1.2.0
|
||||
ruff==0.0.262
|
||||
|
@ -16,6 +16,11 @@ from .decorators import post_load
|
||||
|
||||
Model = TypeVar("Model")
|
||||
|
||||
MANY_SCHEMA_UNSAFE = (
|
||||
"Changing `many` schema-wide breaks type safety. "
|
||||
"Use the the `many` parameter of specific methods (like `load`) instead."
|
||||
)
|
||||
|
||||
|
||||
class GenericSchema(GenericInsightMixin1[Model], Schema):
|
||||
"""
|
||||
@ -100,6 +105,7 @@ class GenericSchema(GenericInsightMixin1[Model], Schema):
|
||||
[`load`][marshmallow_generic.GenericSchema.load]/
|
||||
[`loads`][marshmallow_generic.GenericSchema.loads].
|
||||
"""
|
||||
self._pre_init = True
|
||||
super().__init__(
|
||||
only=only,
|
||||
exclude=exclude,
|
||||
@ -110,6 +116,7 @@ class GenericSchema(GenericInsightMixin1[Model], Schema):
|
||||
partial=partial,
|
||||
unknown=unknown,
|
||||
)
|
||||
self._pre_init = False
|
||||
|
||||
def __setattr__(self, name: str, value: Any) -> None:
|
||||
"""
|
||||
@ -119,10 +126,7 @@ class GenericSchema(GenericInsightMixin1[Model], Schema):
|
||||
[`object.__setattr__`](https://docs.python.org/3/reference/datamodel.html#object.__setattr__).
|
||||
"""
|
||||
if name == "many" and value is not False:
|
||||
warn(
|
||||
"Changing `many` schema-wide breaks type safety. Use the the "
|
||||
"`many` parameter of specific methods (like `load`) instead."
|
||||
)
|
||||
warn(MANY_SCHEMA_UNSAFE, stacklevel=4 if self._pre_init else 2)
|
||||
super().__setattr__(name, value)
|
||||
|
||||
@post_load
|
||||
|
Reference in New Issue
Block a user