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

👷 ci: use ruff and update ci workflow #39

Merged
merged 3 commits into from
Mar 17, 2024
Merged
Changes from 1 commit
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
Next Next commit
👷 ci: use ruff and update ci workflow
SigureMo committed Mar 17, 2024

Verified

This commit was signed with the committer’s verified signature.
SigureMo Nyakku Shigure
commit 9afaa80456e628a6cb8121a3565d83eb8b49be57
15 changes: 0 additions & 15 deletions .github/workflows/black-fmt.yml

This file was deleted.

52 changes: 52 additions & 0 deletions .github/workflows/lint-and-fmt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Lint and Format

on:
push:
branches: [main]
pull_request:
merge_group:
workflow_dispatch:

jobs:
lint-and-fmt:
runs-on: ubuntu-latest
strategy:
matrix:
# Only run linter and formatter on minimum supported Python version
python-version: ["3.8"]
architecture: ["x64"]
name: lint and fmt - Python ${{ matrix.python-version }} on ${{ matrix.architecture }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install prettier
run: |
npm install -g prettier
- name: Install poetry
run: pipx install poetry

- name: Install python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
architecture: ${{ matrix.architecture }}
cache: "poetry"

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

- name: Install dependencies
run: |
just ci-install
- name: lint
run: |
just ci-lint
- name: format check
run: |
just ci-fmt-check
21 changes: 15 additions & 6 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
name: Unit Test

on: [push, pull_request, workflow_dispatch]
on:
push:
branches: [main]
pull_request:
merge_group:
workflow_dispatch:

jobs:
unit-test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12-dev"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
architecture: ["x64"]
name: Python ${{ matrix.python-version }} on ${{ matrix.architecture }} test
name: unittest - Python ${{ matrix.python-version }} on ${{ matrix.architecture }}
steps:
- name: Checkout
uses: actions/checkout@v4
@@ -24,11 +29,15 @@ jobs:
architecture: ${{ matrix.architecture }}
cache: "poetry"

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

- name: Install dependencies
if: steps.poetry-cache.outputs.cache-hit != 'true'
run: |
poetry install -E rst-parser
just ci-install
- name: unit test
run: |
poetry run pytest
just ci-test
27 changes: 22 additions & 5 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
VERSION := `poetry run python -c "import sys; from dochooks import __version__ as version; sys.stdout.write(version)"`

install:
poetry install -E rst-parser

test:
poetry run pytest
just clean

fmt:
poetry run isort .
poetry run black .

fmt-docs:
prettier --write '**/*.md'
poetry run ruff format .

lint:
poetry run pyright dochooks tests
poetry run ruff check .

fmt-docs:
prettier --write '**/*.md'

build:
poetry build
@@ -37,3 +40,17 @@ clean-builds:

hooks-update:
poetry run pre-commit autoupdate

ci-install:
poetry install --no-interaction --no-root -E rst-parser

ci-fmt-check:
poetry run ruff format --check --diff .
prettier --check '**/*.md'

ci-lint:
just lint

ci-test:
poetry run pytest --reruns 3 --reruns-delay 1
just clean
256 changes: 94 additions & 162 deletions poetry.lock

Large diffs are not rendered by default.

42 changes: 34 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -12,13 +12,12 @@ httpx = "^0.27.0"

[tool.poetry.group.dev.dependencies]
pytest = "^8.0.0"
black = "^24.0.0"
isort = "^5.12.0"
tomli = { version = "^2.0.1", python = "<3.11" }
pre-commit = "^3.0.0"
types-docutils = "^0.19.0"
httpx = { extras = ["socks"], version = "^0.27.0" }
pyright = "^1.1.262"
pyright = "^1.1.354"
ruff = "^0.3.3"

[tool.poetry.extras]
rst-parser = ["docutils"]
@@ -28,13 +27,40 @@ check-whitespace-between-cn-and-en-char = "dochooks.insert_whitespace_between_cn
insert-whitespace-between-cn-and-en-char = "dochooks.insert_whitespace_between_cn_and_en_char.format:main"
api-doc-checker = "dochooks.api_doc_checker.check:main"

[tool.black]
[tool.ruff]
line-length = 120
target-version = "py38"

[tool.isort]
profile = "black"
add_imports = ["from __future__ import annotations"]
skip = ["setup.py", ".venv"]
[tool.ruff.lint]
select = [
# Pyflakes
"F",
# Pycodestyle
"E",
"W",
# Isort
"I",
# Pyupgrade
"UP",
# Flake8-pyi
"PYI",
# Flake8-use-pathlib
"PTH",
# Yesqa
"RUF100",
]
ignore = [
"E501", # line too long, duplicate with ruff fmt
"F401", # imported but unused, duplicate with pyright
"F841", # local variable is assigned to but never used, duplicate with pyright
]

[tool.ruff.lint.isort]
required-imports = ["from __future__ import annotations"]
known-first-party = ["moelib"]

[tool.ruff.lint.per-file-ignores]
"setup.py" = ["I"]

[build-system]
requires = ["poetry-core>=1.1.0"]