Skip to content

Commit

Permalink
Use uv (#153)
Browse files Browse the repository at this point in the history
* Use uv

* Name CI instead of Test

* Use master instead of main

* Remove 100% coverage condition
  • Loading branch information
Kludex committed Sep 21, 2024
1 parent 8b85d35 commit c664cef
Show file tree
Hide file tree
Showing 11 changed files with 1,065 additions and 144 deletions.
46 changes: 28 additions & 18 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,40 @@ on:
pull_request:
branches: ["master"]


jobs:
build:

test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5

- name: Install uv
uses: astral-sh/setup-uv@v2
with:
python-version: ${{ matrix.python-version }}
version: "0.4.12"
enable-cache: true

- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .[dev]
- name: Lint
if: matrix.python-version == '3.8'
run: |
ruff multipart tests
- name: Test with pytest
run: |
inv test
run: uv sync --python ${{ matrix.python-version }} --frozen

- name: Run tests
run: scripts/test

- name: Run linters
run: scripts/lint

# https://github.com/marketplace/actions/alls-green#why used for branch protection checks
check:
if: always()
needs: [test]
runs-on: ubuntu-latest
steps:
- name: Decide whether the needed jobs succeeded or failed
uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}
4 changes: 4 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,21 @@ jobs:

steps:
- uses: actions/checkout@v4

- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
pip install -e '.[docs]'
- name: Build package
run: python -m build

- name: Publish package
uses: pypa/gh-action-pypi-publish@v1.8.14
with:
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# [Python-Multipart](https://kludex.github.io/python-multipart/)

[![Build Status](https://github.com/Kludex/python-multipart/workflows/CI/badge.svg)](https://github.com/Kludex/python-multipart/actions)
[![Package version](https://badge.fury.io/py/python-multipart.svg)](https://pypi.python.org/pypi/python-multipart)
[![Supported Python Version](https://img.shields.io/pypi/pyversions/python-multipart.svg?color=%2334D058)](https://pypi.org/project/python-multipart)

Expand Down
22 changes: 9 additions & 13 deletions multipart/multipart.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,19 @@ class FileConfig(TypedDict, total=False):
MAX_MEMORY_FILE_SIZE: int

class _FormProtocol(Protocol):
def write(self, data: bytes) -> int:
...
def write(self, data: bytes) -> int: ...

def finalize(self) -> None:
...
def finalize(self) -> None: ...

def close(self) -> None:
...
def close(self) -> None: ...

class FieldProtocol(_FormProtocol, Protocol):
def __init__(self, name: bytes) -> None:
...
def __init__(self, name: bytes) -> None: ...

def set_none(self) -> None:
...
def set_none(self) -> None: ...

class FileProtocol(_FormProtocol, Protocol):
def __init__(self, file_name: bytes | None, field_name: bytes | None, config: FileConfig) -> None:
...
def __init__(self, file_name: bytes | None, field_name: bytes | None, config: FileConfig) -> None: ...

OnFieldCallback = Callable[[FieldProtocol], None]
OnFileCallback = Callable[[FileProtocol], None]
Expand Down Expand Up @@ -136,14 +130,16 @@ class MultipartState(IntEnum):
LOWER_Z = b"z"[0]
NULL = b"\x00"[0]

# fmt: off
# Mask for ASCII characters that can be http tokens.
# Per RFC7230 - 3.2.6, this is all alpha-numeric characters
# Per RFC7230 - 3.2.6, this is all alpha-numeric characters
# and these: !#$%&'*+-.^_`|~
TOKEN_CHARS_SET = frozenset(
b"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
b"abcdefghijklmnopqrstuvwxyz"
b"0123456789"
b"!#$%&'*+-.^_`|~")
# fmt: on


def ord_char(c: int) -> int:
Expand Down
13 changes: 7 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ classifiers = [
]
dependencies = []

[project.optional-dependencies]
dev = [
[tool.uv]
dev-dependencies = [
"atomicwrites==1.4.1",
"attrs==23.2.0",
"coverage==7.4.4",
Expand All @@ -45,10 +45,8 @@ dev = [
"invoke==2.2.0",
"pytest-timeout==2.3.1",
"ruff==0.3.4",
"hatch",
"atheris==2.3.0; python_version != '3.12'",
]
docs = [
# Documentation
"mkdocs==1.5.3",
"mkdocs-material==9.5.16",
"mkdocstrings==0.24.1",
Expand All @@ -69,7 +67,7 @@ path = "multipart/__init__.py"
packages = ["multipart"]

[tool.hatch.build.targets.sdist]
include = ["/multipart", "/tests"]
include = ["/multipart", "/tests", "CHANGELOG.md", "LICENSE.txt"]

[tool.ruff]
line-length = 120
Expand All @@ -90,6 +88,9 @@ branch = false
omit = ["tests/*"]

[tool.coverage.report]
# fail_under = 100
skip_covered = true
show_missing = true
exclude_lines = [
"pragma: no cover",
"raise NotImplementedError",
Expand Down
11 changes: 0 additions & 11 deletions requirements.txt

This file was deleted.

6 changes: 6 additions & 0 deletions scripts/lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh -e

set -x

uvx ruff check --fix
uvx ruff format
6 changes: 6 additions & 0 deletions scripts/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh -e

set -x # print executed commands to the terminal

uv run coverage run -m pytest "${@}"
uv run coverage report
84 changes: 0 additions & 84 deletions tasks.py

This file was deleted.

11 changes: 0 additions & 11 deletions tox.ini

This file was deleted.

Loading

0 comments on commit c664cef

Please sign in to comment.