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

build: use uv #303

Merged
merged 12 commits into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
38 changes: 3 additions & 35 deletions .github/renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,8 @@
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"local>Trim21/renovate-config",
"local>Trim21/renovate-config:monthly",
"local>Trim21/renovate-config:poetry"
],
"separateMajorMinor": true,
"separateMinorPatch": false,
"rangeStrategy": "pin",
"pre-commit": {
"enabled": true
},
"git-submodules": {
"enabled": true
},
"semanticCommitType": "build",
"packageRules": [
{
"matchManagers": [
"pre-commit"
],
"semanticCommitType": "chore",
"groupName": "pre-commit",
"semanticCommitScope": ""
},
{
"matchManagers": [
"dockerfile"
],
"pinDigests": true,
"rangeStrategy": "pin",
"minor": {
"enabled": false
},
"major": {
"enabled": false
}
}
"local>Trim21/renovate-config:app",
"local>Trim21/renovate-config:python",
"local>Trim21/renovate-config:monthly"
]
}
37 changes: 18 additions & 19 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
name: ci
name: test

on:
pull_request:
branches:
- "master"
push:
branches:
- "master"
- master
pull_request:
branches:
- master

jobs:
test:
runs-on: ubuntu-latest

steps:
- run: git clone https://github.com/bangumi/dev-env $HOME/dev-env
- run: cd ~/dev-env && docker compose up -d

- uses: actions/checkout@v4
with:
submodules: "true"

- uses: actions/setup-python@v5
with:
python-version: '3.10'
- uses: trim21/setup-poetry@dist/v2
- uses: trim21/install-poetry-project@dist/v2
python-version-file: ".python-version"

- uses: astral-sh/setup-uv@v5
- run: uv sync --frozen

- run: bash $HOME/dev-env/wait_mysql_ready.sh

- run: pytest --cov
- run: uv run pytest -rva
timeout-minutes: 10
env:
MYSQL_HOST: '127.0.0.1'
MYSQL_PORT: '3306'
MYSQL_USER: 'user'
MYSQL_PASS: 'password'
MYSQL_DB: 'bangumi'

- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v4
MYSQL_HOST: "127.0.0.1"
MYSQL_PORT: "3306"
MYSQL_USER: "user"
MYSQL_PASS: "password"
MYSQL_DB: "bangumi"
11 changes: 7 additions & 4 deletions .github/workflows/codegen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
submodules: 'true'
submodules: "true"

- uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version-file: ".python-version"

- uses: astral-sh/setup-uv@v5
- run: uv sync --frozen

- run: echo ".venv/bin/" >> $GITHUB_PATH

- uses: trim21/setup-poetry@dist/v2
- uses: trim21/install-poetry-project@dist/v2
- name: Install Task
uses: arduino/setup-task@v2
with:
Expand Down
30 changes: 14 additions & 16 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,46 @@ name: lint

on:
push:
branches-ignore:
- renovate/**
paths-ignore:
- "**.md"
branches:
- master
pull_request:
branches:
- master
paths-ignore:
- "**.md"

jobs:
mypy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: "true"

- uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version-file: ".python-version"

- uses: Trim21/setup-poetry@dist/v2

- uses: Trim21/install-poetry-project@dist/v2
- uses: astral-sh/setup-uv@v5
- run: uv sync --frozen

- uses: liskin/gh-problem-matcher-wrap@v3
with:
action: add
linters: mypy
run: ''

- name: mypy
run: mypy --show-column-numbers chii rpc
run: uv run mypy --show-column-numbers .

lint:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: "true"

- uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version-file: ".python-version"

- run: pip install pre-commit

- uses: trim21/setup-poetry@dist/v2
- uses: trim21/install-poetry-project@dist/v2
- uses: trim21/actions/pre-commit@master
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@ name: Release(Docker)

on:
push:
tags:
- v*
branches:
- master
- 'fix/**'
- 'feat/**'
- 'refactor/**'

jobs:
docker:
runs-on: ubuntu-latest
env:
IMAGE: 'ghcr.io/${{ github.repository_owner }}/ms-timeline'
IMAGE: 'ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}'

concurrency:
group: ${{ github.workflow }}-${{ github.sha }}
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false

steps:
- uses: actions/checkout@v4
with:
submodules: 'true'

- uses: docker/login-action@v3
with:
Expand Down
18 changes: 8 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
exclude: "api/.*"
repos:
- repo: https://github.com/astral-sh/uv-pre-commit
rev: "0.5.29"
hooks:
- id: uv-lock

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
Expand All @@ -10,6 +15,7 @@ repos:
- id: check-toml
- id: check-yaml
- id: check-json
- id: check-docstring-first
- id: check-merge-conflict
- id: check-added-large-files # check for file bigger than 500kb
- id: debug-statements
Expand All @@ -19,22 +25,14 @@ repos:
args: [--fix=lf]
- id: end-of-file-fixer

- repo: https://github.com/python-poetry/poetry
rev: "1.8.4"
hooks:
- id: poetry-check
- id: poetry-lock
name: poetry-lock-check
args: [--check]

- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.7.1
rev: v0.9.5
hooks:
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]

- repo: https://github.com/psf/black
rev: 24.10.0
rev: 25.1.0
hooks:
- id: black
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.10
32 changes: 9 additions & 23 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,34 +1,20 @@
# syntax=docker/dockerfile:1@sha256:865e5dd094beca432e8c0a1d5e1c465db5f998dca4e439981029b3b81fb39ed5

### convert poetry.lock to requirements.txt ###
FROM python:3.10-slim@sha256:af6f1b19eae3400ea3a569ba92d4819a527be4662971d51bb798c923bba30a81 AS poetry
FROM ghcr.io/astral-sh/uv:debian-slim@sha256:3ac4e2ef46fd5a0fb0cf5af9a421435513fec1b2a66e1379a7981dc03470fd33 AS build

WORKDIR /app

ENV PIP_ROOT_USER_ACTION=ignore

COPY requirements-poetry.txt ./
RUN pip install -r requirements-poetry.txt
COPY uv.lock pyproject.toml ./

COPY pyproject.toml poetry.lock ./
RUN poetry export -f requirements.txt --output requirements.txt

### final image ###
FROM python:3.10-slim@sha256:af6f1b19eae3400ea3a569ba92d4819a527be4662971d51bb798c923bba30a81

WORKDIR /app
RUN uv export --no-group dev --frozen --no-emit-project > /app/requirements.txt

ENV PYTHONPATH=/app
FROM python:3.10-slim@sha256:66aad90b231f011cb80e1966e03526a7175f0586724981969b23903abac19081

COPY --from=poetry /app/requirements.txt ./requirements.txt
ENTRYPOINT [ "python", "-m", "start_grpc_server" ]

ENV PIP_ROOT_USER_ACTION=ignore

RUN pip install -U pip && \
pip install -r requirements.txt

WORKDIR /app

ENTRYPOINT [ "python", "-m", "start_grpc_server" ]
COPY --from=build /app/requirements.txt .

RUN pip install --only-binary=:all: --no-cache --no-deps -r requirements.txt

COPY . ./
COPY . .
22 changes: 1 addition & 21 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,6 @@ tasks:
- black .
- mypy .

gen-gql:
desc: generate grpc python files
generates:
- ./api/**/*.py
sources:
- ./proto/**/*.proto
- poetry.lock
cmds:
- >-
datamodel-codegen
--input gql/schema.graphql
--input-file-type graphql
--output gql/model.py
--output-model-type dataclasses.dataclass
# --use-standard-collections

gen-grpc:
desc: generate grpc python files
generates:
Expand All @@ -34,7 +18,7 @@ tasks:
- poetry.lock
cmds:
- >-
poetry run python -m grpc_tools.protoc
python -m grpc_tools.protoc
-I ./proto/
--python_out=.
--pyi_out=.
Expand Down Expand Up @@ -78,7 +62,3 @@ tasks:
- uvicorn gql.app:app

mypy: mypy --show-column-numbers chii rpc

lint:
- poetry run ruff check .
- poetry run mypy chii rpc
2 changes: 1 addition & 1 deletion chii/curd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
from .exceptions import NotFoundError

__all__ = [
"count",
"NotFoundError",
"count",
]
28 changes: 14 additions & 14 deletions chii/db/sa.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,26 @@

__all__ = [
"CHAR",
"selectinload",
"joinedload",
"Text",
"Column",
"subqueryload",
"String",
"DateTime",
"func",
"join",
"text",
"select",
"update",
"insert",
"String",
"Text",
"and_",
"func",
"count",
"or_",
"get",
"delete",
"func",
"func",
"get",
"insert",
"join",
"joinedload",
"or_",
"select",
"selectinload",
"subqueryload",
"sync_session_maker",
"text",
"update",
]


Expand Down
Loading