[[📜2025-01-03 uvを試してみた]] を参考に移行する。ついでに[[Python 3.8]]のサポートを切って[[Python 3.13]]をサポートに追加する。
## 仮想環境の削除
```console
rm -rf .venv .ruff_cache .pytest_cache
```
## pyproject.tomlの変更
```console
uvx pdm import pyproject.toml
```
- `[tool.poetry.*]` を削除
- `[tool.pdm.*]` を削除
- `requires-python` を 3.9以上に
`pytest` `pytest-cov` `aiohttp` は追加されなかったので手動で追加。
```toml
[dependency-groups]
dev = [
"mkdocs<2.0.0,>=1.5.3",
"mkdocs-material<10.0.0,>=9.4.6",
"ruff<1.0.0,>=0.3.7",
"pytest<8.0.0,>=7.2.0",
"pytest-cov<5.0.0,>=4.0.0",
# https://github.com/aio-libs/aiohttp/issues/7739
"aiohttp<4.0.0,>=3.10.2",
]
```
`[build-system]` は [[Hatch]] を使うよう変更。
```toml
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
```
## lockfileの作成
```console
rm poetry.lock
uv sync
```
エラーがいくつか発生した。
### ValueError: Field `console_scripts` must be defined as `project.scripts` instead of in the `project.entry-points` table
```error
Resolved 56 packages in 1.69s
Built docopt==0.6.2
Built markupsafe==2.0.1 × Failed to build `jumeaux @ file:///home/tadashi-aikawa/git/github.com/tadashi-aikawa/jumeaux`
├─▶ The build backend returned an error
╰─▶ Call to `hatchling.build.build_editable` failed (exit status: 1)
[stderr]
Traceback (most recent call last):
File "<string>", line 11, in <module>
wheel_filename = backend.build_editable("/home/tadashi-aikawa/.cache/uv/builds-v0/.tmpU034u3", {}, None)
File "/home/tadashi-aikawa/.cache/uv/builds-v0/.tmpySGidL/lib/python3.13/site-packages/hatchling/build.py", line 83, in build_editable
return os.path.basename(next(builder.build(directory=wheel_directory, versions=['editable'])))
~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/tadashi-aikawa/.cache/uv/builds-v0/.tmpySGidL/lib/python3.13/site-packages/hatchling/builders/plugin/interface.py", line 90, in build
self.metadata.validate_fields()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
File "/home/tadashi-aikawa/.cache/uv/builds-v0/.tmpySGidL/lib/python3.13/site-packages/hatchling/metadata/core.py", line 266, in validate_fields
self.core.validate_fields()
~~~~~~~~~~~~~~~~~~~~~~~~~^^
File "/home/tadashi-aikawa/.cache/uv/builds-v0/.tmpySGidL/lib/python3.13/site-packages/hatchling/metadata/core.py", line 1366, in validate_fields
getattr(self, attribute)
~~~~~~~^^^^^^^^^^^^^^^^^
File "/home/tadashi-aikawa/.cache/uv/builds-v0/.tmpySGidL/lib/python3.13/site-packages/hatchling/metadata/core.py", line 1139, in entry_points
raise ValueError(message)
ValueError: Field `console_scripts` must be defined as `project.scripts` instead of in the `project.entry-points` table hint: This usually indicates a problem with the package or the build environment
```
```diff
- [project.entry-points.console_scripts]
+ [project.scripts]
jumeaux = "jumeaux.main:main"
```
### Failed to build `lxml==4.9.4`
[[lxml]]に関する依存関係がエラーになっていそう。
```error
Resolved 56 packages in 0.91ms
Built jumeaux @ file:///home/tadashi-aikawa/git/github.com/tadashi-aikawa/jumeaux
× Failed to build `lxml==4.9.4`
├─▶ The build backend returned an error
╰─▶ Call to `setuptools.build_meta:__legacy__.build_wheel` failed (exit status: 1)
[stdout]
Building lxml version 4.9.4.
Building without Cython.
Error: Please make sure the libxml2 and libxslt development packages are installed.
[stderr]
<string>:67: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
hint: This usually indicates a problem with the package or the build environment.
help: `lxml` (v4.9.4) was included because `jumeaux` (v5.0.5) depends on `lxml`
```
[[lxml]]を最新 (5.3.0) にバージョンアップしたらなおった。
## Makefileの変更
`poetry` -> `uv` 他いくつか。
## 単体テストとエラー
```console
make test
```
### AttributeError: module 'uuid' has no attribute '_uuid_generate_time'
```error
.venv/lib/python3.13/site-packages/freezegun/api.py:59: in <module>
real_uuid_generate_time = uuid._uuid_generate_time
E AttributeError: module 'uuid' has no attribute '_uuid_generate_time'
During handling of the above exception, another exception occurred:
tests/test_executor.py:13: in <module>
import freezegun
.venv/lib/python3.13/site-packages/freezegun/__init__.py:9: in <module>
from .api import freeze_time
.venv/lib/python3.13/site-packages/freezegun/api.py:63: in <module>
uuid._load_system_functions()
E AttributeError: module 'uuid' has no attribute '_load_system_functions'
```
[[FreezeGun]]が0.3.12とバージョンが低いので、最新(1.5.1)にしてみたらテストを通過した。
## E2Eテスト
```console
make test-e2e
```
こちらは一発OK。
## ドキュメントビルド
```console
make package-docs
make serve docs
```
どちらも平気そう。
## README変更
`poetry` を `uv` に変更してほぼ完了。
## GitHub Actionsの変更
[[GitHub Actions]]の設定ファイルを変更。
> [!note]
> 内容はほぼ [[📜2025-01-03 uvを試してみた#GitHub Actionsの変更]] と同じなので割愛。