Skip to content

Change from Rye to uv #30

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

Merged
merged 17 commits into from
Aug 27, 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
32 changes: 17 additions & 15 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,35 @@ FROM debian:bookworm-slim AS builder

WORKDIR /opt

ENV RYE_HOME="/opt/rye"
ENV PATH="$RYE_HOME/shims:$PATH"

# The installer requires curl (and certificates) to download the release archive
# hadolint ignore=DL3008
RUN apt-get update && \
apt-get install -y --no-install-recommends \
ca-certificates \
curl

SHELL [ "/bin/bash", "-o", "pipefail", "-c" ]
RUN curl -sSf https://rye.astral.sh/get | RYE_INSTALL_OPTION="--yes" bash && \
rye config --set-bool behavior.global-python=true && \
rye config --set-bool behavior.use-uv=true

COPY ./.python-version ./pyproject.toml ./requirements* ./
RUN rye pin "$(cat .python-version)" && \
rye sync
# Download the latest installer
ADD https://astral.sh/uv/install.sh /uv-installer.sh

# Run the installer then remove it
RUN sh /uv-installer.sh


FROM mcr.microsoft.com/vscode/devcontainers/base:bookworm
COPY --from=builder /opt/rye /opt/rye

ENV RYE_HOME="/opt/rye"
ENV PATH="$RYE_HOME/shims:$PATH"
ENV CARGO_HOME="/opt/.cargo/bin"
ENV PATH="$CARGO_HOME/:$PATH"

ENV PYTHONUNBUFFERED=True
ENV UV_LINK_MODE=copy

WORKDIR /opt

COPY --from=builder /root/.cargo/bin/uv $CARGO_HOME/uv
COPY ./.python-version ./

RUN rye config --set-bool behavior.global-python=true && \
rye config --set-bool behavior.use-uv=true
RUN uv python pin "$(cat .python-version)"

RUN chown -R vscode $RYE_HOME
RUN chown -R vscode $CARGO_HOME
8 changes: 4 additions & 4 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "Rye",
"name": "uv",
"build": {
"context": "..",
"dockerfile": "Dockerfile"
Expand All @@ -26,7 +26,7 @@
"yzhang.markdown-all-in-one"
],
"settings": {
"python.defaultInterpreterPath": "/opt/rye/shims/python",
"python.defaultInterpreterPath": "/root/.local/share/uv/python",
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.codeActionsOnSave": {
Expand All @@ -46,7 +46,7 @@
}
}
},
"postCreateCommand": "rye sync",
"postStartCommand": "rye run pre-commit install",
"postCreateCommand": "uv sync --dev",
"postStartCommand": "uv run pre-commit install",
"remoteUser": "vscode"
}
35 changes: 0 additions & 35 deletions .github/actions/setup-python-with-rye/action.yml

This file was deleted.

29 changes: 29 additions & 0 deletions .github/actions/setup-python-with-uv/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Install Python with uv

inputs:
python-version:
description: Python version
required: true

runs:
using: composite
steps:
- name: Install uv
run: curl -LsSf https://astral.sh/uv/install.sh | sh
shell: bash

- name: Pin Python Version
run: |
export PYTHONUNBUFFERED=True
uv python pin ${{ inputs.python-version }}
shell: bash

- uses: actions/cache@v4
id: cache-uv
with:
path: ~/.cache/uv
key: ${{ runner.os }}-python-${{ inputs.python-version }}-uv

- name: Install Dependencies
run: uv sync
shell: bash
12 changes: 6 additions & 6 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Python ${{ matrix.python-version }} with Rye
uses: ./.github/actions/setup-python-with-rye
- name: Setup Python ${{ matrix.python-version }} with uv
uses: ./.github/actions/setup-python-with-uv
with:
python-version: ${{ matrix.python-version }}

- name: Lint
run: rye run ruff check --output-format=github .
run: uv run ruff check --output-format=github .

format:
runs-on: ubuntu-latest
Expand All @@ -37,10 +37,10 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Python ${{ matrix.python-version }} with Rye
uses: ./.github/actions/setup-python-with-rye
- name: Setup Python ${{ matrix.python-version }} with uv
uses: ./.github/actions/setup-python-with-uv
with:
python-version: ${{ matrix.python-version }}

- name: Format
run: rye run ruff format . --check --diff
run: uv run ruff format . --check --diff
19 changes: 4 additions & 15 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,13 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Install Rye
uses: eifinger/setup-rye@v4
- name: Setup Python ${{ matrix.python-version }} with uv
uses: ./.github/actions/setup-python-with-uv
with:
enable-cache: true

- name: Set Rye Config
run: |
rye config --set-bool behavior.global-python=true
rye config --set-bool behavior.use-uv=true

- name: Set up Python ${{ matrix.python-version }}
run: |
export PYTHONUNBUFFERED=1
rye pin ${{ matrix.python-version }}
rye sync
python-version: ${{ matrix.python-version }}

- name: Run Pytest if directory exists
run: |
if [ -d "./tests/" ]; then
rye run pytest -s
uv run pytest -s
fi
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ ARG VARIANT=3.12
FROM python:${VARIANT} AS builder

ENV PYTHONDONTWRITEBYTECODE=True
ENV UV_LINK_MODE=copy

WORKDIR /opt
COPY pyproject.toml requirements.lock ./

COPY pyproject.toml uv.lock ./

# hadolint ignore=DL3013,DL3042
RUN pip install --upgrade pip && \
pip install --no-cache-dir -r requirements.lock
pip install uv && \
uv sync --frozen


FROM python:${VARIANT}-slim
Expand Down
35 changes: 16 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
# VSCode Dev Container: Python Development with Rye, uv, and Ruff
# VSCode Dev Container: Python Development with uv and Ruff

<div align="center">

[![Rye](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/rye/main/artwork/badge.json)](https://github.com/astral-sh/rye)
[![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)](https://github.com/astral-sh/uv)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)

[![Versions](https://img.shields.io/badge/python-3.9%20|%203.10%20|%203.11%20|%203.12%20-green.svg)](https://github.com/a5chin/python-rye)
[![Versions](https://img.shields.io/badge/python-3.9%20|%203.10%20|%203.11%20|%203.12%20-green.svg)](https://github.com/a5chin/python-uv)

[![Ruff](https://github.com/a5chin/python-rye/actions/workflows/ruff.yml/badge.svg)](https://github.com/a5chin/python-rye/actions/workflows/ruff.yml)
[![test](https://github.com/a5chin/python-rye/actions/workflows/test.yml/badge.svg)](https://github.com/a5chin/python-rye/actions/workflows/test.yml)
[![Docker](https://github.com/a5chin/python-rye/actions/workflows/docker.yml/badge.svg)](https://github.com/a5chin/python-rye/actions/workflows/docker.yml)
[![Ruff](https://github.com/a5chin/python-uv/actions/workflows/ruff.yml/badge.svg)](https://github.com/a5chin/python-uv/actions/workflows/ruff.yml)
[![Test](https://github.com/a5chin/python-uv/actions/workflows/test.yml/badge.svg)](https://github.com/a5chin/python-uv/actions/workflows/test.yml)
[![Docker](https://github.com/a5chin/python-uv/actions/workflows/docker.yml/badge.svg)](https://github.com/a5chin/python-uv/actions/workflows/docker.yml)

</div>

## Overview
This repository contains configurations to set up a Python development environment using VSCode's Dev Container feature.
The environment includes Rye, uv, and Ruff.
The environment includes uv, and Ruff.

![demo](assets/gif/ruff.gif)

Expand All @@ -27,7 +26,7 @@ Specifically, you can solve this problem by following the steps below.
2. Type `Developer: Reload Window` in the command palette to reload the window

### Contents
- [VSCode Dev Container: Python Development with Rye, uv, and Ruff](#vscode-dev-container-python-development-with-rye-uv-and-ruff)
- [VSCode Dev Container: Python Development with uv and Ruff](#vscode-dev-container-python-development-with-uv-and-ruff)
- [Overview](#overview)
- [Contents](#contents)
- [Branches](#branches)
Expand All @@ -40,8 +39,9 @@ Specifically, you can solve this problem by following the steps below.
- [The structure of this repository](#the-structure-of-this-repository)

## Branches
- [main](https://github.com/a5chin/python-rye/tree/main)
- [jupyter](https://github.com/a5chin/python-rye/tree/jupyter)
- [main](https://github.com/a5chin/python-uv/tree/main)
- [jupyter](https://github.com/a5chin/python-uv/tree/jupyter)
- [rye](https://github.com/a5chin/python-uv/tree/rye)(Archived)

## Dev Container
- `devcontainer.json`
Expand All @@ -64,9 +64,6 @@ Specifically, you can solve this problem by following the steps below.
- [usernamehw.errorlens](https://marketplace.visualstudio.com/items?itemName=usernamehw.errorlens)
- [yzhang.markdown-all-in-one](https://marketplace.visualstudio.com/items?itemName=yzhang.markdown-all-in-one)
- `Dockerfile`
- Rye
- `rye config --set-bool behavior.global-python=true`
- `rye config --set-bool behavior.use-uv=true`
- Only Dev dependencies
- `pre-commit`
- `pytest`
Expand Down Expand Up @@ -100,10 +97,10 @@ The `.pre-commit-config.yaml` file can contain scripts to be executed before com

```sh
# Python Formatter
rye run ruff format .
uv run ruff format .

# Python Linter
rye run ruff check . --fix
uv run ruff check . --fix

# Docker Linter
hodolint Dockerfile
Expand All @@ -116,13 +113,13 @@ Only sync based on the production lockfile (`requirements.lock`) instead of the

```sh
# Install also include develop dependencies
rye sync
uv sync

# If you do not want dev dependencies to be installed
rye sync --no-dev
uv sync --no-dev

# Use the add command to add dependencies to your project
rye add {libraries}
uv add {libraries}
```

### The structure of this repository
Expand All @@ -134,7 +131,7 @@ rye add {libraries}
├── Dockerfile
├── .github
│ ├── actions
│ │ └── setup-python-with-rye
│ │ └── setup-python-with-uv
│ │ └── action.yml
│ ├── dependabot.yml
│ └── workflows
Expand Down
9 changes: 4 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ description = "Add your description here"
authors = [
{ name = "a5chin" }
]
dependencies = []
requires-python = ">=3.9"
readme = "README.md"
requires-python = ">= 3.12"
dependencies = []

[tool.rye]
managed = true
[tool.uv]
dev-dependencies = [
"pytest>=8.3.2",
"pre-commit>=3.8.0",
"ruff>=0.5.5",
"ruff>=0.6.2",
]
Loading