use ruff instead of black (#598)

This commit is contained in:
Inada Naoki 2024-05-03 15:17:54 +09:00 committed by GitHub
parent e77672200b
commit 2eca765533
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 40 additions and 73 deletions

View file

@ -10,22 +10,25 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
architecture: 'x64'
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
architecture: 'x64'
cache: "pip"
cache-dependency-path: |
requirements.txt
docs/requirements.txt
- name: Build - name: Build
shell: bash
run: | run: |
pip install -r requirements.txt pip install -r requirements.txt
make cython make cython
- name: Sphinx Documentation Generator - name: Sphinx Documentation Generator
run: | run: |
pip install tox pip install -r docs/requirements.txt
tox -e sphinx make docs

View file

@ -1,25 +1,22 @@
name: Black name: lint
on: ["push", "pull_request"] on: ["push", "pull_request"]
jobs: jobs:
black: lint:
# We want to run on external PRs, but not on our own internal PRs as they'll be run # We want to run on external PRs, but not on our own internal PRs as they'll be run
# by the push to the branch. # by the push to the branch.
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
architecture: 'x64'
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Black Code Formatter - name: ruff check
run: | run: |
pip install black==22.3.0 pipx run ruff check --diff msgpack/ test/ setup.py
black -S --diff --check msgpack/ test/ setup.py
- name: ruff format
run: |
pipx run ruff format --diff msgpack/ test/ setup.py

View file

@ -4,9 +4,17 @@ PYTHON_SOURCES = msgpack test setup.py
all: cython all: cython
python setup.py build_ext -i -f python setup.py build_ext -i -f
.PHONY: black .PHONY: format
black: format:
black $(PYTHON_SOURCES) pipx run ruff format $(PYTHON_SOURCES)
.PHONY: lint
lint:
pipx run ruff check $(PYTHON_SOURCES)
.PHONY: doc
doc:
cd docs && sphinx-build -n -v -W --keep-going -b html -d doctrees . html
.PHONY: pyupgrade .PHONY: pyupgrade
pyupgrade: pyupgrade:

View file

@ -1,2 +1,2 @@
sphinx~=7.2 sphinx~=7.3.7
sphinx-rtd-theme~=1.3.0 sphinx-rtd-theme~=2.0.0

View file

@ -1,4 +1,5 @@
"""Fallback pure Python implementation of msgpack""" """Fallback pure Python implementation of msgpack"""
from datetime import datetime as _DateTime from datetime import datetime as _DateTime
import sys import sys
import struct import struct

View file

@ -54,9 +54,9 @@ skip_string_normalization = true
[tool.ruff] [tool.ruff]
line-length = 100 line-length = 100
target-version = "py38" target-version = "py38"
ignore = [] lint.ignore = []
[tool.ruff.per-file-ignores] [tool.ruff.lint.per-file-ignores]
"msgpack/__init__.py" = ["F401", "F403"] "msgpack/__init__.py" = ["F401", "F403"]
"msgpack/fallback.py" = ["E731"] "msgpack/fallback.py" = ["E731"]
"test/test_seq.py" = ["E501"] "test/test_seq.py" = ["E501"]

View file

@ -1,7 +1,2 @@
# Also declared in pyproject.toml, if updating here please also update there. # Also declared in pyproject.toml, if updating here please also update there.
Cython~=3.0.8 Cython~=3.0.10
# Tools required only for development. No need to add it to pyproject.toml file.
black==23.3.0
pytest==7.3.1
pyupgrade==3.3.2

View file

@ -95,4 +95,4 @@ def test_multidim_memoryview():
view = memoryview(b"\00" * 6) view = memoryview(b"\00" * 6)
data = view.cast(view.format, (3, 2)) data = view.cast(view.format, (3, 2))
packed = packb(data) packed = packb(data)
assert packed == b'\xc4\x06\x00\x00\x00\x00\x00\x00' assert packed == b"\xc4\x06\x00\x00\x00\x00\x00\x00"

View file

@ -89,7 +89,7 @@ def testStrictUnicodeUnpack():
def testIgnoreErrorsPack(): def testIgnoreErrorsPack():
re = unpackb( re = unpackb(
packb("abc\uDC80\uDCFFdef", use_bin_type=True, unicode_errors="ignore"), packb("abc\udc80\udcffdef", use_bin_type=True, unicode_errors="ignore"),
raw=False, raw=False,
use_list=1, use_list=1,
) )

View file

@ -1,4 +1,5 @@
"""Test Unpacker's read_array_header and read_map_header methods""" """Test Unpacker's read_array_header and read_map_header methods"""
from msgpack import packb, Unpacker, OutOfData from msgpack import packb, Unpacker, OutOfData
UnexpectedTypeException = ValueError UnexpectedTypeException = ValueError

38
tox.ini
View file

@ -1,38 +0,0 @@
[tox]
envlist =
{py35,py36,py37,py38}-{c,pure},
{pypy,pypy3}-pure,
py34-x86,
sphinx,
isolated_build = true
[testenv]
deps=
pytest
changedir=test
commands=
c,x86: python -c 'from msgpack import _cmsgpack'
c,x86: py.test
pure: py.test
setenv=
pure: MSGPACK_PUREPYTHON=x
[testenv:py34-x86]
basepython=python3.4-x86
deps=
pytest
changedir=test
commands=
python -c 'import sys; print(hex(sys.maxsize))'
python -c 'from msgpack import _cmsgpack'
py.test
[testenv:sphinx]
changedir = docs
deps =
-r docs/requirements.txt
commands =
sphinx-build -n -v -W --keep-going -b html -d {envtmpdir}/doctrees . {envtmpdir}/html