Skip to content

Commit

Permalink
Use ruff and update dependencies (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
abersheeran authored Nov 3, 2023
1 parent cd2227c commit 51ae578
Show file tree
Hide file tree
Showing 9 changed files with 481 additions and 564 deletions.
16 changes: 7 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
runs-on: "${{ matrix.os }}"
strategy:
matrix:
python-version: [3.7, 3.8, 3.9, "3.10", 3.11]
python-version: [3.7, 3.8, 3.9, "3.10", 3.11, 3.12]
os: [windows-latest, ubuntu-latest, macos-latest]

steps:
Expand All @@ -36,15 +36,13 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
architecture: x64
version: 2.7.0
prerelease: true
enable-pep582: true # Enable PEP 582 package loading globally
version: 2.10.0
- name: Install dependencies
run: |
pdm sync -v -dG dev -dG test --no-self
- name: Static type and format checking
run: pdm run check
run: pdm run lint && pdm run format --check --diff

- name: Tests
run: pdm run test --cov=./baize --cov-report=xml -o log_cli=true -o log_cli_level=DEBUG
Expand All @@ -57,15 +55,17 @@ jobs:
verbose: true

- name: Tests with mypyc
if: matrix.python-version < 3.12
run: |
pdm sync -v -dG build --no-isolation
pdm run test --cov=./baize -o log_cli=true -o log_cli_level=DEBUG
- name: Build binary wheel
if: matrix.python-version < 3.12
run: pdm build --no-isolation -v

- name: Try repair linux binary wheel
if: matrix.os == 'ubuntu-latest'
if: matrix.os == 'ubuntu-latest' && matrix.python-version < 3.12
run: |
pip install auditwheel
auditwheel show dist/*-linux*.whl
Expand All @@ -90,9 +90,7 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
architecture: x64
version: 2.7.0
prerelease: true
enable-pep582: true # Enable PEP 582 package loading globally
version: 2.10.0

- name: Install dependencies
run: |
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ jobs:
# - uses: pdm-project/setup-pdm@v3
# name: Setup Python and PDM
# with:
# python-version: 3.7
# python-version: 3.10
# architecture: x64
# version: 2.7.0
# prerelease: true
# enable-pep582: true # Enable PEP 582 package loading globally
# version: 2.10.0

# - name: Install dependencies
# run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,4 @@ site/
# pdm
__pypackages__
.pdm-python
.pdm.toml
1 change: 0 additions & 1 deletion baize/asgi/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
await send({"type": "websocket.close"})
return
else: # pragma: no cover

# call the specified response, mapping send/receive events
# between http/websocket ASGI protocols

Expand Down
969 changes: 455 additions & 514 deletions pdm.lock

Large diffs are not rendered by default.

42 changes: 14 additions & 28 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ classifiers = [
]
dependencies = [
"typing-extensions>=4.1.1; python_version < \"3.8\"",
"contextvars; python_version < \"3.7\"",
]
description = "Powerful and exquisite WSGI/ASGI framework/toolkit."
license = { text = "Apache-2.0" }
Expand All @@ -24,9 +23,6 @@ Homepage = "https://github.com/abersheeran/baize"
Repository = "https://github.com/abersheeran/baize"
Documentation = "https://baize.aber.sh/"

[tool.isort]
profile = "black"

[tool.coverage.run]
omit = ["*/.venv/*", "*/tests/*"]
plugins = ["coverage_conditional_plugin"]
Expand Down Expand Up @@ -59,43 +55,30 @@ includes = ["baize"]
build = "speedup.py"

[tool.pdm.scripts]
lint-isort = "isort {args}"
lint-black = "black {args}"
lint-ruff = "ruff {args}"
lint-mypy = "mypy {args}"
lint = { composite = [
"lint-isort baize tests",
"lint-black baize tests",
"check-flake8 baize tests",
"check-mypy baize tests",
] }
check-isort = "isort --check --diff {args}"
check-black = "black --check --diff {args}"
check-flake8 = "flake8 --ignore W503,E203,E501,E731 {args}"
check-mypy = "mypy {args}"
check = { composite = [
"check-isort baize tests",
"check-black baize tests",
"check-flake8 baize tests",
"check-mypy baize tests",
"lint-ruff baize tests",
"lint-mypy baize tests",
] }
lint-fix = "ruff --fix baize tests"
format = "ruff format baize tests --target-version py37"
test = "pytest tests {args}"
build-docs = "sphinx-build -M html docs/source docs/build"

[tool.pdm.dev-dependencies]
build = [
"mypy<2.0,>=1.0",
"mypy-extensions>=1.0",
"types-contextvars>=2.4.7; python_version < \"3.7\"",
]
dev = [
"black<22,>=21.9b0",
"isort<6.0.0,>=5.7.0",
"flake8~=3.9",
"mypy<2.0,>=1.0",
"types-contextvars>=2.4.7; python_version < \"3.7\"",
"ruff>=0.1.3",
]
doc = [
"Sphinx<4.0.0,>=3.5.3",
"recommonmark<1.0.0,>=0.7.1",
"sphinx-autodoc-typehints<2.0.0,>=1.11.1",
"Sphinx>=4.2.0",
"recommonmark>=0.7.1",
"sphinx-autodoc-typehints>=1.19.1",
]
test = [
"httpx<1.0.0,>=0.19.0",
Expand All @@ -109,6 +92,9 @@ test = [
"coverage-conditional-plugin>=0.8.0",
]

[tool.ruff.lint]
ignore = ["F821"]

[build-system]
build-backend = "pdm.pep517.api"
requires = ["pdm-pep517"]
3 changes: 1 addition & 2 deletions tests/test_asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,7 @@ async def redirect(request: Request) -> Response:
assert (await client.get("/")).text == "homepage"
assert (await client.get("/baize")).json() == {"path": "baize"}
assert (await client.get("/baize/")).status_code == 404
assert (await (client.get("/redirect"))).headers["location"] == "/cat"
assert (await client.get("/redirect")).headers["location"] == "/cat"


@pytest.mark.asyncio
Expand Down Expand Up @@ -1190,7 +1190,6 @@ async def test_files(app):
).status_code == 304

if app.handle_404 is None:

with pytest.raises(HTTPException):
await client.get("/")

Expand Down
6 changes: 1 addition & 5 deletions tests/test_multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ def test_decoder_simple() -> None:
asdasd
-----------------------------9704338192090380615194531385$--
""".replace(
"\n", "\r\n"
).encode(
"utf-8"
)
""".replace("\n", "\r\n").encode("utf-8")
decoder.receive_data(data)
decoder.receive_data(None)
events = [decoder.next_event()]
Expand Down
1 change: 0 additions & 1 deletion tests/test_wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,6 @@ def test_files(app):
).status_code == 304

if app.handle_404 is None:

with pytest.raises(HTTPException):
client.get("/")

Expand Down

0 comments on commit 51ae578

Please sign in to comment.