Skip to content

Commit

Permalink
セットアップを全面的にuvへ切り替え (#121)
Browse files Browse the repository at this point in the history
* セットアップを全面的にuvへ切り替え

* Apply suggestions from code review

Co-authored-by: Go.YAMADA <[email protected]>

---------

Co-authored-by: Go.YAMADA <[email protected]>
  • Loading branch information
shimizukawa and usaturn authored Nov 4, 2024
1 parent d40f8a4 commit 22fe311
Show file tree
Hide file tree
Showing 11 changed files with 560 additions and 47 deletions.
17 changes: 8 additions & 9 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/python
{
"name": "Python 3",
"image": "mcr.microsoft.com/devcontainers/python:1-3.12-bookworm",
"features": {
"ghcr.io/devcontainers/features/git:1": {},
},
"name": "Default Linux Universal",
"image": "mcr.microsoft.com/devcontainers/universal:2-linux",
"features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "pip3 install --user -r requirements.txt",

"onCreateCommand": "bash .devcontainer/on_create_command.sh"
"containerEnv": {
"UV_PROJECT_ENVIRONMENT": "/home/codespace/.local"
},
"onCreateCommand": "bash .devcontainer/on_create_command.sh",
"postStartCommand": "bash .devcontainer/post_start_command.sh"

// Configure tool-specific properties.
// "customizations": {},
Expand Down
4 changes: 1 addition & 3 deletions .devcontainer/on_create_command.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@ rm -rf ~/.cache/matplotlib

curl -LsSf https://astral.sh/uv/install.sh | sh
. $HOME/.cargo/env

uv venv --allow-existing ~/.local
uv pip install --prefix ~/.local/ -r requirements.txt
uv venv --allow-existing ${UV_PROJECT_ENVIRONMENT}
3 changes: 3 additions & 0 deletions .devcontainer/post_start_command.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
. $HOME/.cargo/env
uv self update
uv sync
10 changes: 10 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.*.pyc
.*.swp
.*.orig
_build/
build/
.*~
**/__pycache__/
.devcontainer
.git
.python-version
28 changes: 12 additions & 16 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,28 @@ jobs:
run: |
chmod +x ./.github/git-set-file-times.py
./.github/git-set-file-times.py
- name: CACHE pip
id: cache-pip
uses: actions/cache@v4
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v3
with:
path: |
~/.cache/pip
~/.local/
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}-${{ steps.get-date.outputs.yyyymm }}
version: "latest"
enable-cache: true
- name: CACHE sphinx build
id: cache-sphinx-build
uses: actions/cache@v4
with:
path: build
key: ${{ runner.os }}-sphinx-build-${{ github.ref }}-${{ steps.get-date.outputs.date }}
- name: pip install
- name: install packages
run: |
echo "python version $(python3 --version) running"
echo "pip version $(pip3 --version) running"
python3 -m pip install -U pip setuptools
echo "pip version $(pip3 --version) running"
python3 -m site
pip3 install -r requirements.txt -U
pip3 freeze
echo "python version $(uv run python --version) running"
echo "uv version $(uv --version) running"
uv sync
uv run python -m site
uv pip freeze
- name: build html
run: |
/home/runner/.local/bin/sphinx-build -M html source build -N -T
echo "sphinx-build version $(uv run sphinx-build --version) running"
uv run sphinx-build -M html source build -N -T
- name: s3sync
run: |
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
_build/
build/
.*~
source/_ext/__pycache__/
**/__pycache__/
31 changes: 23 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
FROM python:3.8-slim
FROM python:3.12-slim

RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
DEBIAN_FRONTEND=noninteractive apt-get update\
&& apt-get install -y --no-install-recommends gettext git graphviz make \
&& apt autoremove -y

COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/

# - Silence uv complaining about not being able to use hard links,
# - tell uv to byte-compile packages for faster application startups,
# - prevent uv from accidentally downloading isolated Python builds,
# - pick a Python,
# - and finally declare `UV_PROJECT_ENVIRONMENT` as the target for `uv sync`.
ENV UV_LINK_MODE=copy \
UV_COMPILE_BYTECODE=1 \
UV_PYTHON_DOWNLOADS=never \
UV_PYTHON=python3.12 \
UV_PROJECT_ENVIRONMENT=/usr/local
# Docker上では、uv sync で /usr/local へインストールし /usr/local/bin のコマンドが使えます

RUN apt-get update \
&& apt-get install -y gettext git graphviz make \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN pip install -U setuptools pip
RUN mkdir -p /doc
WORKDIR /doc
COPY ./requirements.txt /doc/requirements.txt
RUN pip install -r /doc/requirements.txt
COPY ./ /doc
RUN --mount=type=cache,target=/root/.cache/uv uv sync --locked

CMD bash
12 changes: 11 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ http://sphinx-users.jp/

1. Sphinx と関連パッケージをインストール

i. ``pip install -r requirements.txt`` を実行
i. ``uv sync`` を実行

2. HTMLを生成する

Expand All @@ -30,3 +30,13 @@ http://sphinx-users.jp/
* Dockerfile の自動ビルド: https://hub.docker.com/r/sphinxjp/sphinx-users.jp/
* サイトの自動ビルド: https://app.wercker.com/sphinxjp/sphinx-users.jp/


パッケージ管理
========================

::

$ uv add requests
$ uv remove requests
$ uv pip list
$ uv export --no-hashes > requirements.txt
13 changes: 13 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[project]
name = "sphinx-users-jp"
version = "0"
readme = "README.rst"
requires-python = ">=3.10"
dependencies = [
"setuptools>=75.3.0",
"sphinx>=8.1.3",
"pillow>=11.0.0",
"sphinxext-opengraph>=0.9.1",
"sphinxcontrib-gist>=0.1.0",
"sphinxcontrib-trimblank>=1.0.3",
]
9 changes: 0 additions & 9 deletions requirements.txt

This file was deleted.

Loading

0 comments on commit 22fe311

Please sign in to comment.