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

Migrate to uv #82

Merged
merged 5 commits into from
Nov 12, 2024
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
16 changes: 5 additions & 11 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,14 @@ jobs:
strategy:
matrix:
python-version: ["3.11"]
poetry-version: ["1.8.3"]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: astral-sh/setup-uv@v3
with:
python-version: ${{ matrix.python-version }}
cache: pip
- uses: narumiruna/setup-poetry@v1
with:
poetry-version: ${{ matrix.poetry-version }}
cache: true
enable-cache: true
- name: Publish
env:
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }}
UV_PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN }}
run: |
poetry build -f wheel
poetry publish
uv build --wheel
uv publish
24 changes: 10 additions & 14 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,22 @@ jobs:
strategy:
matrix:
python-version: ["3.11"]
poetry-version: ["1.8.3"]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: astral-sh/setup-uv@v3
with:
python-version: ${{ matrix.python-version }}
cache: pip
- uses: narumiruna/setup-poetry@v1
with:
poetry-version: ${{ matrix.poetry-version }}
cache: true
enable-cache: true
- name: Install Python
run: uv python install ${{ matrix.python-version }}
- name: Install dependencies
run: poetry install
run: uv sync
- name: Lint
run: poetry run ruff check .
run: uv run ruff check .
- name: Type check
run: poetry run mypy --install-types --non-interactive .
run: uv run mypy --install-types --non-interactive .
- name: Test
run: poetry run pytest -v -s --cov=. --cov-report=xml tests
run: uv run pytest -v -s --cov=src --cov-report=xml tests
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
token: ${{ secrets.CODECOV_TOKEN }}
20 changes: 20 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.3
hooks:
- id: ruff
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.13.0
hooks:
- id: mypy
- repo: https://github.com/astral-sh/uv-pre-commit
rev: 0.5.1
hooks:
- id: uv-lock
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
install:
poetry install

lint:
poetry run ruff check .
uv run ruff check .

test:
poetry run pytest -v -s --cov=. tests
uv run pytest -v -s --cov=src tests

type:
uv run mypy --install-types --non-interactive .

publish:
poetry build -f wheel
poetry publish
uv build --wheel
uv publish

.PHONY: lint test publish
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
## Usage

```sh
# install poetry
pipx install poetry
# install uv
pip install uv

# install dependencies
poetry install
uv sync

# train model
poetry run template -c configs/mnist.yaml
uv run pytorch-template -c configs/mnist.yaml
```
1,612 changes: 0 additions & 1,612 deletions poetry.lock

This file was deleted.

57 changes: 32 additions & 25 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,33 +1,40 @@
[tool.poetry]
name = "template"
[project]
name = "pytorch-template"
version = "0.1.0"
description = ""
authors = ["narumi <[email protected]>"]

[tool.poetry.dependencies]
python = "^3.11"
torch = "^2.3.1"
torchvision = "^0.18.1"
torchmetrics = "^1.4.0"
numpy = "^1.26.3"
tqdm = "^4.66.4"
loguru = "^0.7.2"
mlconfig = "^0.2.2"
wandb = "^0.17.5"

[tool.poetry.group.dev.dependencies]
pytest = "^8.2.2"
pytest-cov = "^5.0.0"
ruff = "^0.5.3"
toml = "^0.10.2"
mypy = "^1.10.1"
readme = "README.md"
authors = [{ name = "narumi", email = "[email protected]" }]
requires-python = ">=3.11"
dependencies = [
"loguru>=0.7.2",
"mlconfig>=0.2.3",
"numpy>=2.1.3",
"torch>=2.5.1",
"torchmetrics>=1.5.2",
"torchvision>=0.20.1",
"tqdm>=4.67.0",
"wandb>=0.18.6",
]

[project.scripts]
pytorch-template = "pytorch_template.cli:main"

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

[tool.poetry.scripts]
template = "template.cli:main"
[dependency-groups]
dev = [
"mypy>=1.13.0",
"pytest>=8.3.3",
"pytest-cov>=6.0.0",
"ruff>=0.7.3",
"types-pyyaml>=6.0.12.20240917",
"types-redis>=4.6.0.20241004",
"types-requests>=2.32.0.20241016",
"types-six>=1.16.21.20241105",
"types-tabulate>=0.9.0.20240106",
]

[tool.ruff]
exclude = ["build"]
Expand Down
10 changes: 5 additions & 5 deletions template/__init__.py → src/pytorch_template/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from . import datasets
from . import jobs
from . import models
from . import optim
from . import trainers
from . import datasets
from . import jobs
from . import models
from . import optim
from . import trainers
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file added src/pytorch_template/py.typed
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import torch

from template.models import LeNet
from pytorch_template.models import LeNet


@torch.no_grad()
Expand Down
Loading