Skip to content

Commit

Permalink
Switch to uv
Browse files Browse the repository at this point in the history
  • Loading branch information
Parnassius committed Jan 11, 2025
1 parent 3ce1fe1 commit eb63fb7
Show file tree
Hide file tree
Showing 8 changed files with 783 additions and 1,450 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ insert_final_newline = true

[*.{json,yml}]
indent_size = 2

[Makefile]
indent_style = tab
22 changes: 11 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
__pycache__/
/.coverage
/.env
/.python-version
/.venv
/database.sqlite
/dist
/poetry.toml
/pokedex.sqlite
/pokemon-showdown
__pycache__
*.py[oc]
build
dist
wheels
*.egg-info
.venv
.coverage
.env
/*.sqlite
/userlist_icons.csv
/veekun.sqlite
/pokemon-showdown
41 changes: 22 additions & 19 deletions Containerfile
Original file line number Diff line number Diff line change
@@ -1,58 +1,61 @@
FROM python:3.13-alpine as base

ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1

ENV CERBOTTANA_CONFIG_PATH=/data
WORKDIR /app


FROM base as builder

ENV UV_COMPILE_BYTECODE=1
ENV UV_FROZEN=1
ENV UV_LINK_MODE=copy

RUN apk add --no-cache gcc musl-dev libffi-dev
RUN apk add --no-cache git

RUN python -m venv /opt/poetry-venv
RUN /opt/poetry-venv/bin/pip install --upgrade pip setuptools
RUN /opt/poetry-venv/bin/pip install poetry

RUN python -m venv .venv
COPY --from=ghcr.io/astral-sh/uv /uv /bin/uv

COPY poetry.lock pyproject.toml .
RUN /opt/poetry-venv/bin/poetry install --no-interaction --only main --no-root
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --no-install-project --no-dev --no-editable

COPY . .
RUN /opt/poetry-venv/bin/poetry build --no-interaction --format wheel
RUN .venv/bin/pip install --no-deps ./dist/*.whl
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --no-dev --no-editable


FROM builder as test-base

RUN apk add --no-cache gcc musl-dev linux-headers
RUN apk add --no-cache make

RUN mkdir -p /data

RUN /opt/poetry-venv/bin/poetry install --no-interaction --no-root
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --no-editable


FROM test-base as test

RUN /opt/poetry-venv/bin/poetry run poe ruff-format --check
RUN /opt/poetry-venv/bin/poetry run poe darglint
RUN /opt/poetry-venv/bin/poetry run poe mypy
RUN /opt/poetry-venv/bin/poetry run poe ruff
RUN /opt/poetry-venv/bin/poetry run poe pytest --cov
RUN make lint
RUN make pytest

RUN /opt/poetry-venv/bin/poetry run coverage json -o /coverage/coverage.json
RUN /opt/poetry-venv/bin/poetry run coverage report --format=markdown > /coverage/coverage.md
RUN uv run coverage json -o /coverage/coverage.json
RUN uv run coverage report --format=markdown > /coverage/coverage.md


FROM test-base as integration

ENV CERBOTTANA_SHOWDOWN_PATH=/pokemon-showdown

RUN apk add --no-cache nodejs npm

RUN mkdir -p /pokemon-showdown

RUN /opt/poetry-venv/bin/poetry run poe pytest-real-ps-instance
RUN make pytest-integration


FROM base as final
Expand Down
36 changes: 36 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
.PHONY: format
format:
@uv run ruff check src tests --fix-only
@uv run ruff format src tests

.PHONY: format-check
format-check:
@uv run ruff format src tests --check

.PHONY: darglint
darglint:
@uv run darglint src tests -v 2

.PHONY: mypy
mypy:
@uv run mypy src tests

.PHONY: ruff
ruff:
@uv run ruff check src tests

.PHONY: pytest
pytest:
@uv run pytest -m 'not integration' --cov

.PHONY: pytest-integration
pytest-integration:
@uv run pytest -m 'integration'

.PHONY: lint
lint: format-check darglint mypy ruff

.PHONY: all
all: format darglint mypy ruff pytest pytest-integration

.DEFAULT_GOAL := all
1,349 changes: 0 additions & 1,349 deletions poetry.lock

This file was deleted.

114 changes: 45 additions & 69 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,39 @@
[project]
name = "cerbottana"
version = "0.1.0"
requires-python = ">=3.13"
dependencies = [
"aiohttp==3.11.11",
"domify==0.4.5",
"imageprobe==0.3.0",
"pokedex[asyncio] @ https://github.com/Parnassius/pokedex.git",
"python-dateutil==2.9.0.post0",
"sqlalchemy==2.0.36",
"typenv==0.2.0",
]

[project.scripts]
cerbottana = "cerbottana.__main__:main"

[dependency-groups]
dev = [
"darglint==1.8.1",
"freezegun==1.5.1",
"mypy==1.14.1",
"poethepoet==0.32.0",
"pytest==8.3.4",
"pytest-asyncio==0.25.0",
"pytest-cov==6.0.0",
"pytest-mock==3.14.0",
"pytest-xprocess==1.0.2",
"python-dotenv[cli]==1.0.1",
"ruff==0.8.4",
"types-python-dateutil==2.9.0.20241206",
]

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
requires = ["hatchling"]
build-backend = "hatchling.build"


[tool.coverage.report]
Expand All @@ -11,7 +44,12 @@ relative_files = true
source = ["src/cerbottana"]


[tool.hatch.metadata]
allow-direct-references = true


[tool.mypy]
python_version = "3.13"
strict = true
implicit_reexport = true

Expand All @@ -31,67 +69,12 @@ disallow_untyped_defs = false
disallow_incomplete_defs = false


[tool.poe.tasks]
ruff-fix = "ruff check src tests --fix-only"
ruff-format = "ruff format src tests"
format = ["ruff-fix", "ruff-format"]

darglint = "darglint src tests -v 2"
mypy = "mypy src tests"
ruff = "ruff check src tests"
pytest-full = [
{ref="pytest"},
{shell="""
dotenv get TESTS_MOD_USERNAME > /dev/null
if [ $? -ne 0 ]
then
echo 'Skipping tests using a real Showdown instance'
else
poe pytest-real-ps-instance
fi
"""},
]
pytest = "pytest -m 'not real_ps_instance'"
pytest-real-ps-instance = "pytest -m 'real_ps_instance'"
all = ["format", "darglint", "mypy", "ruff", "pytest-full"]


[tool.poetry]
name = "cerbottana"
version = "0.1.0"
description = ""
authors = ["Parnassius <[email protected]>"]

[tool.poetry.dependencies]
python = "^3.13"
aiohttp = "3.11.11"
domify = "0.4.5"
imageprobe = "0.3.0"
pokedex = {git="https://github.com/Parnassius/pokedex.git", extras=["asyncio"]}
python-dateutil = "2.9.0.post0"
sqlalchemy = "2.0.36"
typenv = "0.2.0"

[tool.poetry.group.dev.dependencies]
darglint = "1.8.1"
freezegun = "1.5.1"
mypy = "1.14.1"
poethepoet = "0.32.0"
pytest = "8.3.4"
pytest-asyncio = "0.25.0"
pytest-cov = "6.0.0"
pytest-mock = "3.14.0"
pytest-xprocess = "1.0.2"
python-dotenv = {version="1.0.1", extras=["cli"]}
ruff = "0.8.4"
types-python-dateutil = "2.9.0.20241206"

[tool.poetry.scripts]
cerbottana = "cerbottana.__main__:main"

[tool.pytest.ini_options]
addopts = "--strict-config --strict-markers"
markers = ["integration"]
asyncio_mode = "auto"
xfail_strict = true

[tool.ruff]
target-version = "py313"

[tool.ruff.lint]
select = [
Expand Down Expand Up @@ -143,10 +126,3 @@ ban-relative-imports = "all"
[tool.ruff.lint.isort]
required-imports = ["from __future__ import annotations"]
split-on-trailing-comma = false


[tool.pytest.ini_options]
addopts = "--strict-config --strict-markers"
markers = ["real_ps_instance"]
asyncio_mode = "auto"
xfail_strict = true
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@

def pytest_collection_modifyitems(items):
for item in items:
# Mark tests using a real showdown instance with `pytest.mark.real_ps_instance`
# Mark tests using a real showdown instance with `pytest.mark.integration`
if "showdown_connection" in item.fixturenames:
item.add_marker(pytest.mark.real_ps_instance)
item.add_marker(pytest.mark.integration)


database_metadata: dict[str, Any] = {
Expand Down
Loading

0 comments on commit eb63fb7

Please sign in to comment.