Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
ci: setup pre-commit.ci for running type checking, linting and format…
Browse files Browse the repository at this point in the history
…ting (#52)

ci: setup codecov

ci: remove redundant parameter from dependabot config

ci: remove redundant parameters from release-please config

ci: fix installing poetry on windows

ci: use immutable references to repositories in github workflows

build: use third-party pre-commit hooks instead of local where possible
  • Loading branch information
LeeeeT authored Nov 9, 2022
1 parent a12f86f commit 8d48195
Show file tree
Hide file tree
Showing 16 changed files with 112 additions and 172 deletions.
2 changes: 0 additions & 2 deletions .github/dependabot.yml → .github/dependabot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ updates:
directory: /
schedule:
interval: daily
allow:
- dependency-type: all

- package-ecosystem: github-actions
directory: /
Expand Down
2 changes: 0 additions & 2 deletions .github/release-please.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
handleGHRelease: true
releaseType: python
packageName: valtypes
47 changes: 0 additions & 47 deletions .github/workflows/ci.yaml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
name: CD
name: Publish release

on:
release:
types: [created]

jobs:
deploy-release:
publish-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main
- uses: actions/setup-python@main
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- uses: snok/install-poetry@main
python-version: '3.11'
- uses: snok/install-poetry@v1.3.3
with:
version: latest
virtualenvs-create: false
- run: poetry build
- uses: pypa/gh-action-pypi-publish@master
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Test

on:
push:
branches: [main]
pull_request:
types: [opened, synchronize]

jobs:
test:
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash
strategy:
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]
python-version: [ '3.11' ]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- uses: snok/[email protected]
with:
virtualenvs-create: false
- run: poetry install
- run: pre-commit run --all-files pytest || true
- uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
58 changes: 28 additions & 30 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,63 +1,61 @@
repos:
- repo: local
ci:
autofix_commit_msg: 'refactor: auto fixes from pre-commit hooks'
autoupdate_commit_msg: 'build(deps): update pre-commit hooks'
skip: [pytest] # tests are run in a GitHub workflow

repos:
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
name: isort
entry: isort
language: python
pass_filenames: false
args: [ . ]
stages: [ commit ]

- repo: https://github.com/aio-libs/sort-all
rev: v1.2.0
hooks:
- id: sort-all
name: sort-all
entry: sort-all
language: python
types: [ python ]
stages: [ commit ]

- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
name: black
entry: black
language: python
pass_filenames: false
args: [ . ]
stages: [ commit ]

- id: flake8
- repo: https://github.com/csachs/pyproject-flake8
rev: 0b61f25
hooks:
- id: pyproject-flake8
name: flake8
entry: pflake8
language: python
pass_filenames: false
args: [ valtypes, tests ]
stages: [ commit ]

- repo: local
hooks:
- id: mypy
name: mypy
entry: mypy
language: python
entry: python scripts/mypy.py
language: system
pass_filenames: false
stages: [ commit ]

- id: pyright
name: pyright
entry: pyright
language: node
entry: python scripts/pyright.py
language: system
pass_filenames: false
stages: [ commit ]

- id: pyright-verify
name: pyright verify
entry: pyright
language: node
name: pyright-verify
entry: python scripts/pyright-verify.py
language: system
pass_filenames: false
args: [ --verifytypes, valtypes ]
stages: [ commit ]

- id: pytest
name: pytest
entry: pytest
language: python
entry: python scripts/pytest.py
language: system
pass_filenames: false
stages: [ commit ]
10 changes: 10 additions & 0 deletions codecov.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
coverage:
status:
project:
default:
target: 100%

comment:
layout: "header, diff, footer"
require_changes: true
after_n_builds: 3 # keep in sync with .github/workflows/test.yaml
76 changes: 6 additions & 70 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@ python = "^3.10"

[tool.poetry.dev-dependencies]
pre-commit = "^2.20.0"
isort = "^5.10.1"
sort-all = "^1.2.0"
black = "^22.10.0"
pyproject-flake8 = "^5.0.4.post1"
mypy = "^0.982"
pyright = "^1.1.274"
pytest = "^7.1.3"
pytest-cov = "^4.0.0"
mkdocs-material = "^8.5.6"

[tool.isort]
Expand All @@ -52,75 +44,19 @@ strict = true
strict_equality = false
warn_return_any = false
warn_no_return = false
warn_redundant_casts = false
no_warn_unused_ignores = true

[tool.pyright]
include = ["valtypes", "tests"]
strictListInference = true
strictDictionaryInference = true
strictSetInference = true
strictParameterNoneValue = true
enableTypeIgnoreComments = true
reportMissingModuleSource = true
reportMissingImports = true
reportUndefinedVariable = true
reportAssertAlwaysTrue = true
reportInvalidStringEscapeSequence = true
reportInvalidTypeVarUse = true
reportMissingTypeStubs = true
reportSelfClsParameterName = true
reportUnsupportedDunderAll = true
reportUnusedExpression = false
reportWildcardImportFromLibrary = true
reportGeneralTypeIssues = true
reportOptionalSubscript = true
reportOptionalMemberAccess = true
reportOptionalCall = true
reportOptionalIterable = true
reportOptionalContextManager = true
reportOptionalOperand = true
reportTypedDictNotRequiredAccess = true
reportPrivateImportUsage = true
reportUnboundVariable = true
reportUnusedCoroutine = true
reportConstantRedefinition = true
reportDuplicateImport = true
reportFunctionMemberAccess = true
typeCheckingMode = "strict"
reportUnnecessaryTypeIgnoreComment = false
reportImportCycles = false
reportIncompatibleMethodOverride = true
reportIncompatibleVariableOverride = true
reportIncompleteStub = true
reportInconsistentConstructor = true
reportInvalidStubStatement = true
reportMatchNotExhaustive = true
reportMissingParameterType = true
reportMissingTypeArgument = true
reportOverlappingOverload = true
reportPrivateUsage = true
reportUnknownArgumentType = true
reportUnknownLambdaType = true
reportUnknownArgumentType = false
reportUnknownLambdaType = false
reportUnknownMemberType = false
reportUnknownParameterType = true
reportUnknownVariableType = true
reportUnnecessaryCast = true
reportUnnecessaryComparison = true
reportUnknownParameterType = false
reportUnknownVariableType = false
reportUnnecessaryIsInstance = false
reportUnusedClass = true
reportUnusedImport = true
reportUnusedFunction = false
reportUnusedVariable = true
reportUntypedBaseClass = true
reportUntypedClassDecorator = true
reportUntypedFunctionDecorator = true
reportUntypedNamedTuple = true
reportCallInDefaultInitializer = false
reportImplicitStringConcatenation = true
reportMissingSuperCall = false
reportPropertyTypeMismatch = true
reportUninitializedInstanceVariable = false
reportUnnecessaryTypeIgnoreComment = false
reportUnusedCallResult = false

[tool.pytest.ini_options]
testpaths = ["tests"]
Expand Down
4 changes: 4 additions & 0 deletions scripts/mypy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import os

os.system("pip install mypy pytest")
os.system("mypy")
4 changes: 4 additions & 0 deletions scripts/pyright-verify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import os

os.system("pip install pyright")
os.system("pyright --verifytypes valtypes")
4 changes: 4 additions & 0 deletions scripts/pyright.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import os

os.system("pip install pyright pytest")
os.system("pyright")
4 changes: 4 additions & 0 deletions scripts/pytest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import os

os.system("pip install pytest pytest-cov")
os.system("pytest")
11 changes: 6 additions & 5 deletions valtypes/parsing/factory/composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@
__all__ = ["Composite"]


T_co = TypeVar("T_co", covariant=True)
T_contra = TypeVar("T_contra", contravariant=True)
T = TypeVar("T")

F = TypeVar("F")

class Composite(ABC[object, T_contra, T_co], Collection["rule.ABC[T_contra, T_co]"], Generic[T_contra, T_co]):

class Composite(ABC[object, T, F], Collection["rule.ABC[T, F]"], Generic[T, F]):
@cached_method
def get_parser_for(self, type: object, /) -> parser.ABC[T_contra, T_co]: # type: ignore
def get_parser_for(self, type: object, /) -> parser.ABC[T, F]: # type: ignore
for rule in self:
if rule.is_suitable_for(type):
return rule.get_parser_for(type)
raise error.NoParser(type)

def add_to_top(self, *rules: rule.ABC[T_contra, T_co]) -> None:
def add_to_top(self, *rules: rule.ABC[T, F]) -> None:
self.get_parser_for.cache_clear()
super().add_to_top(*rules)
8 changes: 4 additions & 4 deletions valtypes/parsing/factory/mapping_to_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@


T = TypeVar("T")
T_co = TypeVar("T_co", covariant=True)
T_contra = TypeVar("T_contra", contravariant=True)

F = TypeVar("F")

S = TypeVar("S")


class MappingToDict(ABC[type[dict[Any, Any]], Mapping[S, T_co], dict[Any, Any]], Generic[S, T_co]):
def __init__(self, factory: ABC[Any, S | T_co, Any]):
class MappingToDict(ABC[type[dict[Any, Any]], Mapping[S, T_contra], dict[Any, Any]], Generic[S, T_contra]):
def __init__(self, factory: ABC[Any, S | T_contra, Any]):
self._factory = factory

def get_parser_for(self, type: type[dict[T, F]], /) -> parser.MappingToDict[S, T_co, T, F]:
def get_parser_for(self, type: type[dict[T, F]], /) -> parser.MappingToDict[S, T_contra, T, F]:
keys_type, values_type = resolve_type_args(type, dict)
return parser.MappingToDict(self._factory.get_parser_for(keys_type), self._factory.get_parser_for(values_type))
Loading

0 comments on commit 8d48195

Please sign in to comment.