Skip to content

Commit fdd30ff

Browse files
authored
Refactor CI/CD (#286)
1 parent 29a95f4 commit fdd30ff

File tree

106 files changed

+382
-328
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+382
-328
lines changed

.github/dependabot.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "daily"
7+
- package-ecosystem: "pip"
8+
directory: "tests"
9+
schedule:
10+
interval: "daily"
11+
- package-ecosystem: "pip"
12+
directory: "docs"
13+
schedule:
14+
interval: "daily"

.github/workflows/cd.yml

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: CD
2+
3+
on:
4+
workflow_dispatch:
5+
release:
6+
types:
7+
- published
8+
9+
jobs:
10+
build_sdist:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- run: scripts/cythonize.sh
15+
- run: pipx run build --sdist
16+
- uses: actions/upload-artifact@v2
17+
with:
18+
name: dist
19+
path: dist/*.tar.gz
20+
build_wheels:
21+
name: Wheel on ${{ matrix.os }}
22+
runs-on: ${{ matrix.os }}
23+
strategy:
24+
fail-fast: false
25+
matrix:
26+
os: [windows-2022, windows-2019, ubuntu-20.04, ubuntu-18.04, macos-11, macos-10.15]
27+
steps:
28+
- uses: actions/checkout@v2
29+
- run: scripts/cythonize.sh
30+
- uses: pypa/cibuildwheel@v2.0.0
31+
with:
32+
CIBW_TEST_COMMAND: pytest {project}/tests --ignore=tests/__generated__/test_recursive_postponned.py
33+
CIBW_BEFORE_TEST: pip install -r tests/requirements.txt
34+
CIBW_TEST_SKIP: "*universal2:arm64"
35+
- uses: actions/upload-artifact@v2
36+
with:
37+
name: dist
38+
path: wheelhouse/*.whl
39+
publish:
40+
needs: [build_sdist, build_wheels]
41+
runs-on: ubuntu-latest
42+
if: github.event_name == 'release' && github.event.action == 'published'
43+
steps:
44+
- uses: actions/download-artifact@v2
45+
with:
46+
name: dist
47+
path: dist
48+
- uses: pypa/gh-action-pypi-publish@v1.4.2
49+
with:
50+
password: ${{ secrets.PYPI_TOKEN }}

.github/workflows/ci.yml

+38-36
Original file line numberDiff line numberDiff line change
@@ -12,54 +12,56 @@ on:
1212
- "**.py"
1313

1414
jobs:
15-
check:
16-
name: Run pre-commit checks
17-
runs-on: ubuntu-latest
18-
steps:
19-
- uses: actions/cache@v2
20-
with:
21-
path: ~/.cache/pip
22-
key: pip
23-
- uses: actions/checkout@v2
24-
- uses: actions/setup-python@v2
25-
- name: Install pre-commit
26-
run: |
27-
python -m pip install --upgrade pip
28-
pip install pre-commit
29-
- name: Run pre-commit
30-
run: pre-commit run --all-files
3115
test:
32-
name: Test ${{ matrix.python-version }}${{ matrix.compile && ' compiled' || '' }}
16+
name: Test ${{ matrix.python-version }}
3317
runs-on: ubuntu-latest
34-
needs: [check]
3518
strategy:
3619
fail-fast: false
3720
matrix:
38-
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10', 'pypy3']
39-
compile: [true, false]
40-
exclude:
41-
- python-version: pypy3
42-
compile: true
21+
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10', 'pypy-3.7']
22+
include:
23+
- python-version: "3.6"
24+
pytest-args: --ignore=tests/__generated__/test_recursive_postponned.py
25+
- python-version: "3.10"
26+
pytest-args: --cov=apischema --cov-branch --cov-report=xml --cov-report=html
4327
steps:
4428
- uses: actions/cache@v2
4529
with:
4630
path: ~/.cache/pip
47-
key: pip
31+
key: ${{ runner.os }}-pip-${{ hashFiles('tests/requirements.txt') }}
32+
restore-keys: |
33+
${{ runner.os }}-pip-
4834
- uses: actions/checkout@v2
4935
- name: Set up Python ${{ matrix.python-version }}
5036
uses: actions/setup-python@v2
5137
with:
5238
python-version: ${{ matrix.python-version }}
53-
- name: cythonize
54-
if: matrix.compile
55-
run: |
56-
python -m pip install cython ${{ (matrix.python-version == '3.6' || matrix.python-version == 'pypy3') && 'dataclasses' || '' }}
57-
python scripts/cythonize.py
58-
python setup.py build_ext --inplace
59-
- name: Install tox
60-
run: |
61-
python -m pip install --upgrade pip
62-
pip install tox tox-gh-actions
63-
- name: Run tox
64-
run: tox
39+
- name: Install requirements
40+
run: pip install -r tests/requirements.txt
41+
- name: Generate tests from documentation example
42+
run: scripts/generate_tests_from_examples.py
43+
- name: Run tests
44+
run: pytest tests ${{ matrix.pytest-args }}
45+
- uses: codecov/codecov-action@v2
46+
# https://github.saobby.my.eu.orgmunity/t/run-step-if-file-exists/16445/3
47+
if: hashFiles('coverage.xml') != ''
48+
- uses: actions/upload-artifact@v2
49+
if: hashFiles('coverage.xml') != ''
50+
with:
51+
name: coverage
52+
path: |
53+
coverage.xml
54+
htmlcov
55+
- name: Cythonize
56+
run: scripts/cythonize.sh
57+
if: matrix.python-version != 'pypy3'
58+
- name: Compile
59+
run: python setup.py build_ext --inplace
60+
if: matrix.python-version != 'pypy3'
61+
- name: Run tests (compiled)
62+
run: pytest tests ${{ matrix.pytest-args }}
63+
if: matrix.python-version != 'pypy3'
6564

65+
concurrency:
66+
group: ci-${{ github.head_ref }}
67+
cancel-in-progress: true

.pre-commit-config.yaml

+10-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,16 @@ repos:
66
entry: python3 scripts/sort_all.py
77
language: python
88
types: [ python ]
9+
- repo: https://github.com/hadialqattan/pycln
10+
rev: v1.1.0
11+
hooks:
12+
- id: pycln
13+
- repo: https://github.com/pycqa/isort
14+
rev: 5.10.1
15+
hooks:
16+
- id: isort
917
- repo: https://github.com/ambv/black
10-
rev: 21.11b1
18+
rev: 21.12b0
1119
hooks:
1220
- id: black
1321
args: [-C]
@@ -17,7 +25,7 @@ repos:
1725
- id: flake8
1826
exclude: ^examples/.*\.py$
1927
- repo: https://github.com/pre-commit/mirrors-mypy
20-
rev: v0.910-1
28+
rev: v0.930
2129
hooks:
2230
- id: mypy
2331
exclude: ^examples/.*\.py$

apischema/conversions/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,5 @@ def __getattr__(name):
4141
return identity
4242
raise AttributeError(f"module {__name__} has no attribute {name}")
4343

44-
4544
else:
4645
from apischema.utils import identity # noqa: F401

apischema/conversions/conversions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from dataclasses import dataclass
22
from functools import lru_cache
33
from typing import (
4+
TYPE_CHECKING,
45
Any,
56
Callable,
67
Collection,
@@ -9,7 +10,6 @@
910
List,
1011
NewType,
1112
Optional,
12-
TYPE_CHECKING,
1313
Tuple,
1414
TypeVar,
1515
Union,

apischema/conversions/converters.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
from functools import partial, wraps
55
from types import new_class
66
from typing import (
7+
TYPE_CHECKING,
78
Any,
89
Callable,
910
List,
1011
MutableMapping,
1112
Optional,
12-
TYPE_CHECKING,
1313
Type,
1414
TypeVar,
1515
Union,
@@ -21,8 +21,8 @@
2121
from apischema.conversions import LazyConversion
2222
from apischema.conversions.conversions import (
2323
AnyConversion,
24-
ConvOrFunc,
2524
Conversion,
25+
ConvOrFunc,
2626
resolve_conversion,
2727
)
2828
from apischema.conversions.utils import Converter, is_convertible
@@ -53,7 +53,6 @@
5353
def default_deserialization(tp):
5454
return _deserializers.get(tp)
5555

56-
5756
else:
5857
default_deserialization = _deserializers.get # type: ignore
5958

apischema/conversions/dataclass_models.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import warnings
22
from dataclasses import dataclass
33
from types import new_class
4-
from typing import Callable, Optional, TYPE_CHECKING, Tuple, Type, Union
4+
from typing import TYPE_CHECKING, Callable, Optional, Tuple, Type, Union
55

66
from apischema.conversions import Conversion
77
from apischema.conversions.conversions import ResolvedConversion

apischema/conversions/wrappers.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import warnings
2-
from dataclasses import MISSING, field as field_, make_dataclass
2+
from dataclasses import MISSING
3+
from dataclasses import field as field_
4+
from dataclasses import make_dataclass
35
from inspect import Parameter, iscoroutinefunction, signature
46
from typing import Any, Callable, Mapping, Tuple, Type
57

apischema/dataclasses.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33

44

55
def _replace(__obj, **changes):
6+
from dataclasses import _FIELD_INITVAR, _FIELDS
7+
from dataclasses import replace as replace_ # type: ignore
8+
69
from apischema.fields import FIELDS_SET_ATTR, fields_set, set_fields
7-
from dataclasses import replace as replace_, _FIELDS, _FIELD_INITVAR # type: ignore
810

911
# Fix https://bugs.python.org/issue36470
1012
assert is_dataclass(__obj)

apischema/deserialization/__init__.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from enum import Enum
66
from functools import lru_cache, partial
77
from typing import (
8+
TYPE_CHECKING,
89
Any,
910
Callable,
1011
Collection,
@@ -14,7 +15,6 @@
1415
Pattern,
1516
Sequence,
1617
Set,
17-
TYPE_CHECKING,
1818
Tuple,
1919
Type,
2020
TypeVar,
@@ -39,8 +39,6 @@
3939
AnyMethod,
4040
BoolMethod,
4141
CoercerMethod,
42-
ListMethod,
43-
ListCheckOnlyMethod,
4442
ConstrainedFloatMethod,
4543
ConstrainedIntMethod,
4644
ConstrainedStrMethod,
@@ -54,9 +52,11 @@
5452
FlattenedField,
5553
FloatMethod,
5654
IntMethod,
55+
ListCheckOnlyMethod,
56+
ListMethod,
5757
LiteralMethod,
58-
MappingMethod,
5958
MappingCheckOnly,
59+
MappingMethod,
6060
NoneMethod,
6161
ObjectMethod,
6262
OptionalMethod,
@@ -82,7 +82,7 @@
8282
from apischema.recursion import RecursiveConversionsVisitor
8383
from apischema.schemas import Schema, get_schema
8484
from apischema.schemas.constraints import Constraints, merge_constraints
85-
from apischema.types import AnyType, NoneType, PRIMITIVE_TYPES
85+
from apischema.types import PRIMITIVE_TYPES, AnyType, NoneType
8686
from apischema.typing import get_args, get_origin, is_type, is_typed_dict
8787
from apischema.utils import (
8888
CollectionOrPredicate,

apischema/deserialization/methods.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from dataclasses import dataclass, field
22
from typing import (
3+
TYPE_CHECKING,
34
AbstractSet,
45
Any,
56
Callable,
@@ -9,7 +10,6 @@
910
Optional,
1011
Pattern,
1112
Sequence,
12-
TYPE_CHECKING,
1313
Tuple,
1414
Union,
1515
)

apischema/fields.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
__all__ = ["fields_set", "is_set", "set_fields", "unset_fields", "with_fields_set"]
22
from dataclasses import ( # type: ignore
3-
Field,
43
_FIELD,
5-
_FIELDS,
64
_FIELD_INITVAR,
5+
_FIELDS,
6+
Field,
77
is_dataclass,
88
)
99
from functools import wraps

apischema/graphql/__init__.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,9 @@
1111

1212

1313
try:
14-
from .schema import ID, Query, Mutation, Subscription, graphql_schema
14+
from . import relay
1515
from .interfaces import interface
1616
from .resolvers import resolver
17-
from . import relay
17+
from .schema import ID, Mutation, Query, Subscription, graphql_schema
1818
except ImportError:
1919
raise
20-
raise ImportError(
21-
"GraphQL feature requires graphql-core library\n"
22-
"Run `pip install apischema[graphql]` to install it"
23-
)

apischema/graphql/relay/global_identification.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
import graphql
1717

1818
from apischema import deserialize, deserializer, serialize, serializer, type_name
19-
from apischema.graphql import ID, interface, resolver
19+
from apischema.graphql.interfaces import interface
20+
from apischema.graphql.resolvers import resolver
21+
from apischema.graphql.schema import ID
2022
from apischema.metadata import skip
2123
from apischema.ordering import order
2224
from apischema.type_names import get_type_name

apischema/graphql/relay/mutations.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from dataclasses import Field, MISSING, field, make_dataclass
1+
from dataclasses import MISSING, Field, field, make_dataclass
22
from functools import wraps
33
from inspect import Parameter, signature
44
from typing import (

apischema/graphql/resolvers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
ErrorHandler,
4444
SerializedMethod,
4545
_get_methods,
46-
serialized as register_serialized,
4746
)
47+
from apischema.serialization.serialized_methods import serialized as register_serialized
4848
from apischema.types import AnyType, NoneType, Undefined
4949
from apischema.typing import is_type
5050
from apischema.utils import (

apischema/graphql/schema.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from dataclasses import dataclass, field as field_, replace
1+
from dataclasses import dataclass
2+
from dataclasses import field as field_
3+
from dataclasses import replace
24
from enum import Enum
35
from functools import wraps
46
from inspect import Parameter, iscoroutinefunction

0 commit comments

Comments
 (0)