Skip to content

Poetryからuvへ移行しました。 #718

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 5 commits into from
May 9, 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: 17 additions & 21 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,10 @@ RUN set -x \
# for docker
&& curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - \
&& add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" \
# Python3.12をインストールするために、deadsnakes PPAを追加
&& add-apt-repository ppa:deadsnakes/ppa \
# Install packages
&& apt-get update \
&& apt-get install -y --no-install-recommends \
docker-ce-cli \
# python
python3.12-dev \
# common tools
bash-completion \
build-essential \
Expand Down Expand Up @@ -68,26 +64,26 @@ RUN set -x \
ENV PATH=/usr/local/devcontainer-tool/bin:${PATH}


# Python / pip
RUN ln -s $(which python3.12) /usr/bin/python
RUN curl -sSL https://bootstrap.pypa.io/get-pip.py | python -
ENV PYTHONDONTWRITEBYTECODE=1 \
PIP_DEFAULT_TIMEOUT=100 \
PIP_NO_CACHE_DIR=on \
PIP_DISABLE_PIP_VERSION_CHECK=on

# # poetry
RUN set -x \
&& python -m pip install "poetry<1.9"

# Add user / Grant sudo privileges
RUN useradd -m -s /bin/bash -u 5000 -U vscode \
&& echo "vscode ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/ALL \
&& groupadd --gid 999 docker \
&& usermod -aG docker vscode
ARG USERNAME=vscode
RUN useradd -m -s /bin/bash -u 5000 -U ${USERNAME} \
&& echo "${USERNAME} ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers.d/ALL

USER ${USERNAME}

USER vscode
ARG UV_VERSION=0.6.14
RUN set -x \
&& curl -LsSf https://astral.sh/uv/${UV_VERSION}/install.sh | sh \
&& echo 'eval "$(uv generate-shell-completion bash)"' >> /home/${USERNAME}/.bashrc \
&& echo 'eval "$(uvx --generate-shell-completion bash)"' >> /home/${USERNAME}/.bashrc

RUN poetry config virtualenvs.in-project true
ENV PATH=/home/${USERNAME}/.local/bin/:${PATH} \
UV_NO_CACHE=1 \
UV_LINK_MODE=copy

# install python
ARG PYTHON_VERSION=3.12.10
RUN uv python install ${PYTHON_VERSION} --default --preview

ENTRYPOINT [ "bash", "/entrypoint.sh" ]
4 changes: 2 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"initializeCommand": "mkdir -p ${localWorkspaceFolder}/.devcontainer/venv",
"mounts": [
"source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind",
// ホスト側のvenvとコンテナ側のvenvを分類して、ホスト側でpoetryコマンドを利用できるようにする
// ホスト側のvenvとコンテナ側のvenvを分類して、ホスト側でuvコマンドを利用できるようにする
"source=${localWorkspaceFolder}/.devcontainer/venv,target=${containerWorkspaceFolder}/.venv,type=bind"
],
"runArgs": [
Expand All @@ -25,7 +25,7 @@
],
"workspaceMount": "source=${localWorkspaceFolder},target=/workspaces,type=bind,consistency=cached",
"workspaceFolder": "/workspaces",
"postStartCommand": "poetry install --all-extras",
"postStartCommand": "uv sync --all-extras",
"customizations": {
"vscode": {
"extensions": [
Expand Down
30 changes: 15 additions & 15 deletions .github/workflows/lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,35 @@ jobs:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]


steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
- name: Install uv and set the python version
uses: astral-sh/setup-uv@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip "poetry<1.9"
poetry install --only main,test --all-extras
python-version: ${{ matrix.python-version }}
version: "0.6.14"
- name: Install the project
run: uv sync --all-extras
- name: Test
env:
# 以下の環境変数がないとテストに失敗するため、ダミーの値を設定する
ANNOFAB_PAT: "foo"
run: |
poetry run pytest -n auto -m "not access_webapi"
uv run pytest -n auto -m "not access_webapi"


lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
- name: Install uv and set the python version
uses: astral-sh/setup-uv@v5
with:
python-version: 3.12
- name: Install dependencies
run: |
python -m pip install --upgrade pip "poetry<1.9"
poetry install --only main,linter --all-extras
python-version: 3.12
version: "0.6.14"
- name: Install the project
run: uv sync --all-extras
- name: Lint
run: |
make lint
Expand Down
16 changes: 7 additions & 9 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,17 @@ jobs:
name: Build and publish Python 🐍 distributions 📦 to PyPI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
- uses: actions/checkout@v3
- name: Install uv and set the python version
uses: astral-sh/setup-uv@v5
with:
python-version: "3.12"
- name: Install poetry
run: |
python -m pip install "poetry<1.9"
poetry self add "poetry-dynamic-versioning[plugin] < 1.5"
# Install a specific version of uv.
version: "0.6.14"

- name: Publish
env:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
run: |
poetry config pypi-token.pypi $PYPI_TOKEN
poetry publish --build
uv build
uv publish --token $PYPI_TOKEN
2 changes: 0 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"terminal.integrated.allowChords": false, // terminal上でEmacsキーバインドを使うための設定
"python.languageServer": "Pylance",
// "poetry run"コマンドで実行することを想定しているので、venv環境を自動的にactivateしないようにする
"python.terminal.activateEnvironment":false,
"python.analysis.completeFunctionParens": true,
"python.testing.autoTestDiscoverOnSaveEnabled": false,
"python.testing.pytestArgs": [
Expand Down
21 changes: 9 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,25 @@ ifndef TEST_FILES
export TEST_FILES:=tests
endif

.PHONY: docs lint test format test publish
.PHONY: docs lint test format test

format:
poetry run ruff format ${SOURCE_FILES} ${TEST_FILES}
poetry run ruff check ${SOURCE_FILES} ${TEST_FILES} --fix-only --exit-zero
uv run ruff format ${SOURCE_FILES} ${TEST_FILES}
uv run ruff check ${SOURCE_FILES} ${TEST_FILES} --fix-only --exit-zero

lint:
poetry run ruff format ${SOURCE_FILES} ${TEST_FILES} --check
poetry run ruff check ${SOURCE_FILES} ${TEST_FILES}
poetry run mypy ${SOURCE_FILES} ${TEST_FILES}
uv run ruff format ${SOURCE_FILES} ${TEST_FILES} --check
uv run ruff check ${SOURCE_FILES} ${TEST_FILES}
uv run mypy ${SOURCE_FILES} ${TEST_FILES}
# テストコードはチェックを緩和するためpylintは実行しない
poetry run pylint --jobs=0 ${SOURCE_FILES}
uv run pylint --jobs=0 ${SOURCE_FILES}


test:
# 並列で実行するとエラーになるので、シーケンシャルで実行する
poetry run pytest --cov=${SOURCE_FILES} --cov-report=html ${TEST_FILES}

publish:
poetry publish --build
uv run pytest --cov=${SOURCE_FILES} --cov-report=html ${TEST_FILES}

docs:
cd docs && poetry run make html
cd docs && uv run make html
@echo "\033[95m\n\nBuild successful! View the docs homepage at docs/_build/html/index.html.\n\033[0m"

10 changes: 5 additions & 5 deletions README_for_developer.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ $ make format && make lint
## テストの実行方法
1. Annofabの認証情報を、`.netrc`ファイルまたは環境変数に設定する。
2. 以下のコマンドを実行して、テスト用のプロジェクトとタスクを作成する。
* `poetry run python tests/create_test_project.py --organization ${MY_ORGANIZATION}`
* `uv run python tests/create_test_project.py --organization ${MY_ORGANIZATION}`
3. `pytest.ini`に、テスト対象の`project_id`と`task_id`を指定する。
* `task_id`はプロジェクト`project_id`配下であること
* **【注意】テストを実行すると、Annofabプロジェクトの内容が変更される**
Expand All @@ -35,17 +35,17 @@ $ make format && make lint
#### テストメソッドを指定してテストする方法

```
$ poetry run pytest tests/test_api.py::TestLogin::test_login
$ uv run pytest tests/test_api.py::TestLogin::test_login
```

annofabapiでは、pytestのカスタムオプションを定義しています。

```
# ジョブを投げるテスト(時間がかかるテスト)を実行する。
$ poetry run pytest --run_submitting_job tests
$ uv run pytest --run_submitting_job tests

# annofabapiモジュールのログを表示する。
$ poetry run pytest --print_log_annofabapi tests
$ uv run pytest --print_log_annofabapi tests
```

#### カバレッジの確認
Expand All @@ -67,7 +67,7 @@ GitHubのReleasesからリリースしてください。
バージョンはSemantic Versioningに従います。
リリースすると、以下の状態になります。

* ソース内のバージョン情報(`pyproject.toml`, `__version__.py`)は、https://github.com/mtkennerly/poetry-dynamic-versioning でGitHubのバージョンタグから生成されます
* ソース内のバージョン情報(`pyproject.toml`, `__init__.py`)は、uv-dynamic-versioning によりGitHubのバージョンタグから生成されます
* 自動でPyPIに公開されます。


Expand Down
11 changes: 8 additions & 3 deletions annofabapi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from importlib.metadata import PackageNotFoundError, version

from annofabapi.api import AnnofabApi
from annofabapi.api2 import AnnofabApi2
from annofabapi.wrapper import Wrapper
from annofabapi.resource import build, build_from_netrc, build_from_env, Resource

from .__version__ import __version__

__all__ = [
"AnnofabApi",
"AnnofabApi2",
Expand All @@ -13,5 +13,10 @@
"build_from_netrc",
"build_from_env",
"Resource",
"__version__",
]


try:
__version__ = version(__name__)
except PackageNotFoundError:
__version__ = "0.0.0"
1 change: 0 additions & 1 deletion annofabapi/__version__.py

This file was deleted.

2 changes: 1 addition & 1 deletion docs/create_pydantic_modes_rst.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pushd ${SCRIPT_DIR}/../

tempdir=$(mktemp -d)

poetry run sphinx-apidoc annofabapi -o docs/api_reference/foo --output-dir ${tempdir}
uv run sphinx-apidoc annofabapi -o docs/api_reference/foo --output-dir ${tempdir}
cp ${tempdir}/annofabapi.pydantic_models.rst docs/api_reference/pydantic_models.rst

rm -rf ${tempdir}
Expand Down
Loading