Skip to content

Commit

Permalink
♻️ refactor: add pyright check
Browse files Browse the repository at this point in the history
  • Loading branch information
SigureMo committed Aug 30, 2022
1 parent dcd038e commit 995b23a
Show file tree
Hide file tree
Showing 68 changed files with 294 additions and 39 deletions.
15 changes: 0 additions & 15 deletions .github/workflows/black-fmt.yml

This file was deleted.

10 changes: 7 additions & 3 deletions .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- uses: Gr1N/setup-poetry@v7
- name: Install poetry
uses: snok/install-poetry@v1
with:
version: 1.2.0rc2

- uses: actions/cache@v3
id: poetry-cache
with:
path: |
**/.venv
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}
key: ${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.architecture }}-poetry-${{ hashFiles('poetry.lock') }}

- name: Install dependencies
if: steps.poetry-cache.outputs.cache-hit != 'true'
Expand All @@ -52,4 +56,4 @@ jobs:
- name: e2e test
run: |
poetry run pytest -m "e2e and not (ci_skip or ignore)" --workers auto
just ci-e2e-test
51 changes: 51 additions & 0 deletions .github/workflows/lint-and-fmt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Lint and Format

on: [push, pull_request, workflow_dispatch]

jobs:
lint-and-fmt:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9", "3.10"]
architecture: ["x64"]
name: Python ${{ matrix.python-version }} on ${{ matrix.architecture }} test
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
architecture: ${{ matrix.architecture }}

- name: Install poetry
uses: snok/install-poetry@v1
with:
version: 1.2.0rc2

- name: Install just
uses: extractions/setup-just@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- uses: actions/cache@v3
id: poetry-cache
with:
path: |
**/.venv
key: ${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.architecture }}-poetry-${{ hashFiles('poetry.lock') }}

- name: Install dependencies
if: steps.poetry-cache.outputs.cache-hit != 'true'
run: |
just install
- name: lint
run: |
just ci-lint
- name: format check
run: |
just ci-fmt-check
17 changes: 13 additions & 4 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,28 @@ jobs:
python-version: ${{ matrix.python-version }}
architecture: ${{ matrix.architecture }}

- uses: Gr1N/setup-poetry@v7
- name: Install poetry
uses: snok/install-poetry@v1
with:
version: 1.2.0rc2

- name: Install just
uses: extractions/setup-just@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- uses: actions/cache@v3
id: poetry-cache
with:
path: |
**/.venv
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}
key: ${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.architecture }}-poetry-${{ hashFiles('poetry.lock') }}

- name: Install dependencies
if: steps.poetry-cache.outputs.cache-hit != 'true'
run: |
poetry install
just install
- name: unit test
run: |
poetry run pytest -m "(api or processor) and not (ci_skip or ignore)" --workers auto
just ci-test
21 changes: 21 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ DOCKER_NAME := "siguremo/yutto"
run *ARGS:
poetry run python -m yutto {{ARGS}}

install:
poetry install

test:
poetry run pytest -m '(api or e2e or processor) and not (ci_only or ignore)' --workers auto
just clean
Expand All @@ -14,6 +17,9 @@ fmt:
poetry run isort .
poetry run black .

lint:
poetry run pyright yutto tests

build:
poetry build

Expand Down Expand Up @@ -50,6 +56,21 @@ clean-builds:
rm -rf dist/
rm -rf yutto.egg-info/

ci-fmt-check:
poetry run isort --check-only .
poetry run black --check --diff .

ci-lint:
just lint

ci-test:
poetry run pytest -m "(api or processor) and not (ci_skip or ignore)" --workers auto
just clean

ci-e2e-test:
poetry run pytest -m "e2e and not (ci_skip or ignore)" --workers auto
just clean

docker-run *ARGS:
docker run --rm -it -v `pwd`:/app {{DOCKER_NAME}} {{ARGS}}

Expand Down
53 changes: 52 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ classifiers = [
"Environment :: Console",
"Operating System :: OS Independent",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Typing :: Typed",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
Expand All @@ -28,11 +29,12 @@ uvloop = { version = "0.16.0", optional = true }
dicttoxml = "^1.7.4"
colorama = { version = "^0.4.5", markers = "sys_platform == 'win32'" }

[tool.poetry.dev-dependencies]
[tool.poetry.group.dev.dependencies]
pytest = "^7.0"
black = "^22.1"
pytest-parallel = "^0.1.1"
isort = "^5.10.1"
pyright = "^1.1.268"

[tool.poetry.extras]
uvloop = ["uvloop"]
Expand All @@ -51,7 +53,14 @@ line-length = 120

[tool.isort]
profile = "black"
add_imports = ["from __future__ import annotations"]
skip = ["setup.py", ".venv"]

[tool.pyright]
include = ["yutto", "tests"]
pythonVersion = "3.9"
typeCheckingMode = "strict"

[build-system]
requires = ["poetry_core>=1.0.0"]
requires = ["poetry_core>=1.1.0rc2"]
build-backend = "poetry.core.masonry.api"
2 changes: 2 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import shutil
from pathlib import Path

Expand Down
4 changes: 3 additions & 1 deletion tests/test_api/test_bangumi.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import aiohttp
import pytest

Expand All @@ -10,7 +12,7 @@
get_season_id_by_media_id,
)
from yutto.utils.fetcher import Fetcher
from yutto.utils.functools import as_sync
from yutto.utils.funcutils import as_sync


@pytest.mark.api
Expand Down
4 changes: 3 additions & 1 deletion tests/test_api/test_collection.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from __future__ import annotations

import aiohttp
import pytest

from yutto._typing import BvId, MId, SeriesId
from yutto.api.collection import get_collection_details
from yutto.utils.fetcher import Fetcher
from yutto.utils.functools import as_sync
from yutto.utils.funcutils import as_sync


@pytest.mark.api
Expand Down
4 changes: 3 additions & 1 deletion tests/test_api/test_danmaku.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from __future__ import annotations

import aiohttp
import pytest

from yutto._typing import CId
from yutto.api.danmaku import get_danmaku, get_protobuf_danmaku, get_xml_danmaku
from yutto.utils.fetcher import Fetcher
from yutto.utils.functools import as_sync
from yutto.utils.funcutils import as_sync


@pytest.mark.api
Expand Down
4 changes: 3 additions & 1 deletion tests/test_api/test_space.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import aiohttp
import pytest

Expand All @@ -12,7 +14,7 @@
get_user_space_all_videos_avids,
)
from yutto.utils.fetcher import Fetcher
from yutto.utils.functools import as_sync
from yutto.utils.funcutils import as_sync


@pytest.mark.api
Expand Down
4 changes: 3 additions & 1 deletion tests/test_api/test_ugc_video.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import aiohttp
import pytest

Expand All @@ -9,7 +11,7 @@
get_ugc_video_subtitles,
)
from yutto.utils.fetcher import Fetcher
from yutto.utils.functools import as_sync
from yutto.utils.funcutils import as_sync


@pytest.mark.api
Expand Down
Loading

0 comments on commit 995b23a

Please sign in to comment.