Open20

Rye & uv 追っかけ

zztkmzztkm

Rye の作者が↓のような投稿をしており、uv が気になったので個人のメモとして追っかけをする。

uv を開発しているのは最近話題の Ruff を開発している Astral

https://twitter.com/mitsuhiko/status/1758217551631282323

UPDATE 20240226: Rye が astral_sh 管理化に置かれた
https://twitter.com/mitsuhiko/status/1761832060870689219

Rye で uv を有効化するにはこれ

サポートされたのは https://github.com/mitsuhiko/rye/releases/tag/0.24.0 からなので、とりあえず rye self update して以下のコマンドで有効化すればOK

rye config --set-bool behavior.use-uv=true

この Scrap について

この Scrap に記載の内容はたまに記事にまとめなおして見やすくしています。
良ければこちらもどうぞ。

zztkmzztkm

Rye と uv の関係

uv は現状だとpip and pip-compile を置き換えるものと紹介されている。

Rye では以前から pip-tools から何かに移行したいねという issue が上がっていて、これとは別でしばらく前からRye と uv 制作者同士で話をしていて、Rye がバックエンドで uv をサポートするようになったっぽい(このへん雑に読んでるのでニュアンスが間違ってるかもだが)

Rye の今後について

Rye がすぐに引退してしまうようなことはなさそうだが、mitsuhiko さん的には Rye が uv などの Cargo for Python を目指すツールに吸収されていくことを望んでそう。

Cargo for Python なツールを目指す uv は要チェックだ。

zztkmzztkm

uv のREADMEを読みながら uv 単体で触ってみた。

venv を作成する

❯ uv venv
  × Querying Python at `/Users/zztkm/.rye/shims/rye` failed with status exit status: 2:
  │ --- stdout:

  │ --- stderr:
  │ error: unexpected argument found
  │ ---

あ、自分の python3 は rye の shimlink になってる?のでうまく処理できなかったのかな。。。

rye でインストールしたインタプリタを直接指定してみる。

❯ rye toolchain list
cpython@3.12.0 (/Users/zztkm/.rye/py/cpython@3.12.0/install/bin/python3)
cpython@3.11.7 (/Users/zztkm/.rye/py/cpython@3.11.7/install/bin/python3)
cpython@3.11.6 (/Users/zztkm/.rye/py/cpython@3.11.6/install/bin/python3)

# とりあえず 3.12 を指定しておく
❯ uv venv -p /Users/zztkm/.rye/py/cpython@3.12.0/install/bin/python3
Using Python 3.12.0 interpreter at /Users/zztkm/.rye/py/cpython@3.12.0/install/bin/python3.12
Creating virtualenv at: .venv

できた!。venv も一瞬で作られてビビる。どういう仕組になっているか気になるがあとで体力があれば深ぼる。

pip install をしてみる。例にある flask のインストールで、pipとどの程度差が出るのか確かめてみる。

uv

time uv pip install flask
Resolved 7 packages in 9ms
Installed 7 packages in 10ms
 + blinker==1.7.0
 + click==8.1.7
 + flask==3.0.2
 + itsdangerous==2.1.2
 + jinja2==3.1.3
 + markupsafe==2.1.5
 + werkzeug==3.0.1
uv pip install flask  0.01s user 0.04s system 103% cpu 0.053 total

pip

time pip install flask
Collecting flask
  Obtaining dependency information for flask from https://files.pythonhosted.org/packages/93/a6/aa98bfe0eb9b8b15d36cdfd03c8ca86a03968a87f27ce224fb4f766acb23/flask-3.0.2-py3-none-any.whl.metadata
  Downloading flask-3.0.2-py3-none-any.whl.metadata (3.6 kB)
Collecting Werkzeug>=3.0.0 (from flask)
  Obtaining dependency information for Werkzeug>=3.0.0 from https://files.pythonhosted.org/packages/c3/fc/254c3e9b5feb89ff5b9076a23218dafbc99c96ac5941e900b71206e6313b/werkzeug-3.0.1-py3-none-any.whl.metadata
  Using cached werkzeug-3.0.1-py3-none-any.whl.metadata (4.1 kB)
Collecting Jinja2>=3.1.2 (from flask)
  Obtaining dependency information for Jinja2>=3.1.2 from https://files.pythonhosted.org/packages/30/6d/6de6be2d02603ab56e72997708809e8a5b0fbfee080735109b40a3564843/Jinja2-3.1.3-py3-none-any.whl.metadata
  Downloading Jinja2-3.1.3-py3-none-any.whl.metadata (3.3 kB)
Collecting itsdangerous>=2.1.2 (from flask)
  Using cached itsdangerous-2.1.2-py3-none-any.whl (15 kB)
Collecting click>=8.1.3 (from flask)
  Obtaining dependency information for click>=8.1.3 from https://files.pythonhosted.org/packages/00/2e/d53fa4befbf2cfa713304affc7ca780ce4fc1fd8710527771b58311a3229/click-8.1.7-py3-none-any.whl.metadata
  Using cached click-8.1.7-py3-none-any.whl.metadata (3.0 kB)
Collecting blinker>=1.6.2 (from flask)
  Obtaining dependency information for blinker>=1.6.2 from https://files.pythonhosted.org/packages/fa/2a/7f3714cbc6356a0efec525ce7a0613d581072ed6eb53eb7b9754f33db807/blinker-1.7.0-py3-none-any.whl.metadata
  Downloading blinker-1.7.0-py3-none-any.whl.metadata (1.9 kB)
Collecting MarkupSafe>=2.0 (from Jinja2>=3.1.2->flask)
  Obtaining dependency information for MarkupSafe>=2.0 from https://files.pythonhosted.org/packages/53/bd/583bf3e4c8d6a321938c13f49d44024dbe5ed63e0a7ba127e454a66da974/MarkupSafe-2.1.5-cp312-cp312-macosx_10_9_universal2.whl.metadata
  Downloading MarkupSafe-2.1.5-cp312-cp312-macosx_10_9_universal2.whl.metadata (3.0 kB)
Downloading flask-3.0.2-py3-none-any.whl (101 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 101.3/101.3 kB 4.5 MB/s eta 0:00:00
Downloading blinker-1.7.0-py3-none-any.whl (13 kB)
Using cached click-8.1.7-py3-none-any.whl (97 kB)
Downloading Jinja2-3.1.3-py3-none-any.whl (133 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 133.2/133.2 kB 13.8 MB/s eta 0:00:00
Using cached werkzeug-3.0.1-py3-none-any.whl (226 kB)
Downloading MarkupSafe-2.1.5-cp312-cp312-macosx_10_9_universal2.whl (18 kB)
Installing collected packages: MarkupSafe, itsdangerous, click, blinker, Werkzeug, Jinja2, flask
Successfully installed Jinja2-3.1.3 MarkupSafe-2.1.5 Werkzeug-3.0.1 blinker-1.7.0 click-8.1.7 flask-3.0.2 itsdangerous-2.1.2
WARNING: There was an error checking the latest version of pip.
pip install flask  0.60s user 0.18s system 49% cpu 1.559 total

体感でわかるくらい uv が速い。

zztkmzztkm

ソフトウェアの比較は得意ではないので、あとは自由に使ってみての感想を書いていく。
あと、rye の uv バックエンドも使ってみる。

zztkmzztkm

とりあえず普段自分は rye を使っているので rye で uv を使うことで速度的なところがどの程度変化するのか確かめてみる。

  • flask を add 済

まずデフォルト

time rye sync
Initializing new virtualenv in /Users/zztkm/dev/sandbox/pydev/rye-not-uv-test/.venv
Python version: cpython@3.12.0
Generating production lockfile: /Users/zztkm/dev/sandbox/pydev/rye-not-uv-test/requirements.lock
Generating dev lockfile: /Users/zztkm/dev/sandbox/pydev/rye-not-uv-test/requirements-dev.lock
Installing dependencies
Looking in indexes: https://pypi.org/simple/
Obtaining file:///. (from -r /var/folders/jf/ppd8_ywn5j94k064g559vgq00000gp/T/tmpbahbtfpn (line 3))
  Installing build dependencies ... done
  Checking if build backend supports build_editable ... done
  Getting requirements to build editable ... done
  Preparing editable metadata (pyproject.toml) ... done
Collecting blinker==1.7.0 (from -r /var/folders/jf/ppd8_ywn5j94k064g559vgq00000gp/T/tmpbahbtfpn (line 1))
  Using cached blinker-1.7.0-py3-none-any.whl.metadata (1.9 kB)
Collecting click==8.1.7 (from -r /var/folders/jf/ppd8_ywn5j94k064g559vgq00000gp/T/tmpbahbtfpn (line 2))
  Using cached click-8.1.7-py3-none-any.whl.metadata (3.0 kB)
Collecting flask==3.0.2 (from -r /var/folders/jf/ppd8_ywn5j94k064g559vgq00000gp/T/tmpbahbtfpn (line 4))
  Using cached flask-3.0.2-py3-none-any.whl.metadata (3.6 kB)
Collecting itsdangerous==2.1.2 (from -r /var/folders/jf/ppd8_ywn5j94k064g559vgq00000gp/T/tmpbahbtfpn (line 5))
  Using cached itsdangerous-2.1.2-py3-none-any.whl (15 kB)
Collecting jinja2==3.1.3 (from -r /var/folders/jf/ppd8_ywn5j94k064g559vgq00000gp/T/tmpbahbtfpn (line 6))
  Using cached Jinja2-3.1.3-py3-none-any.whl.metadata (3.3 kB)
Collecting markupsafe==2.1.5 (from -r /var/folders/jf/ppd8_ywn5j94k064g559vgq00000gp/T/tmpbahbtfpn (line 7))
  Using cached MarkupSafe-2.1.5-cp312-cp312-macosx_10_9_universal2.whl.metadata (3.0 kB)
Collecting werkzeug==3.0.1 (from -r /var/folders/jf/ppd8_ywn5j94k064g559vgq00000gp/T/tmpbahbtfpn (line 8))
  Using cached werkzeug-3.0.1-py3-none-any.whl.metadata (4.1 kB)
Using cached blinker-1.7.0-py3-none-any.whl (13 kB)
Using cached click-8.1.7-py3-none-any.whl (97 kB)
Using cached flask-3.0.2-py3-none-any.whl (101 kB)
Using cached Jinja2-3.1.3-py3-none-any.whl (133 kB)
Using cached MarkupSafe-2.1.5-cp312-cp312-macosx_10_9_universal2.whl (18 kB)
Using cached werkzeug-3.0.1-py3-none-any.whl (226 kB)
Building wheels for collected packages: rye-not-uv-test
  Building editable for rye-not-uv-test (pyproject.toml) ... done
  Created wheel for rye-not-uv-test: filename=rye_not_uv_test-0.1.0-py3-none-any.whl size=1409 sha256=87613278ee3f5431d8443e051b8fd2253cb6f0501fbdbd7a7237218fc6554874
  Stored in directory: /private/var/folders/jf/ppd8_ywn5j94k064g559vgq00000gp/T/pip-ephem-wheel-cache-nnl7k1a8/wheels/8b/19/c8/73a63a20645e0f1ed9aae9dd5d459f0f7ad2332bb27cba6c0f
Successfully built rye-not-uv-test
Installing collected packages: werkzeug, rye-not-uv-test, markupsafe, jinja2, itsdangerous, flask, click, blinker
Successfully installed blinker-1.7.0 click-8.1.7 flask-3.0.2 itsdangerous-2.1.2 jinja2-3.1.3 markupsafe-2.1.5 rye-not-uv-test-0.1.0 werkzeug-3.0.1
Done!
rye sync  3.12s user 0.93s system 73% cpu 5.506 total

次に uv

❯ rye config --set-bool behavior.use-uv=true
❯ time rye sync
Initializing new virtualenv in /Users/zztkm/dev/sandbox/pydev/rye-uv-test/.venv
Python version: cpython@3.12.0
Generating production lockfile: /Users/zztkm/dev/sandbox/pydev/rye-uv-test/requirements.lock
   Built file:///Users/zztkm/dev/sandbox/pydev/rye-uv-test                                                                          Built 1 editable in 853ms
Resolved 8 packages in 1.66s
Generating dev lockfile: /Users/zztkm/dev/sandbox/pydev/rye-uv-test/requirements-dev.lock
   Built file:///Users/zztkm/dev/sandbox/pydev/rye-uv-test                                                                          Built 1 editable in 264ms
Resolved 8 packages in 273ms
Installing dependencies
   Built file:///Users/zztkm/dev/sandbox/pydev/rye-uv-test                                                                          Built 1 editable in 237ms
Resolved 7 packages in 1ms
Downloaded 7 packages in 86ms
Installed 8 packages in 4ms
 + blinker==1.7.0
 + click==8.1.7
 + flask==3.0.2
 + itsdangerous==2.1.2
 + jinja2==3.1.3
 + markupsafe==2.1.5
 + rye-uv-test==0.1.0 (from file:///Users/zztkm/dev/sandbox/pydev/rye-uv-test)
 + werkzeug==3.0.1
Done!
rye sync  0.53s user 0.39s system 30% cpu 2.994 total

たしかに速い。
これ大規模プロジェクトになったときにかなりわかりやすい差が出そう。
特に問題ない間は rye で uv を使い続けてみる。

zztkmzztkm

uv の help と version

❯ uv -h
Usage: uv [OPTIONS] <COMMAND>

Commands:
  pip    Resolve and install Python packages
  venv   Create a virtual environment
  clean  Clear the cache
  help   Print this message or the help of the given subcommand(s)

Options:
  -q, --quiet                  Do not print any output
  -v, --verbose                Use verbose output
      --color <COLOR>          Control colors in output [default: auto] [possible values: auto, always, never]
  -n, --no-cache               Avoid reading from or writing to the cache
      --cache-dir <CACHE_DIR>  Path to the cache directory [env: UV_CACHE_DIR=]
  -h, --help                   Print help (see more with '--help')
  -V, --version                Print version
❯ uv --version
uv 0.1.1

clean コマンドでキャッシュクリアできるっぽい。

❯ uv clean -h
Clear the cache

Usage: uv clean [OPTIONS] [PACKAGE]...

Arguments:
  [PACKAGE]...  The packages to remove from the cache

Options:
  -q, --quiet                  Do not print any output
  -v, --verbose                Use verbose output
      --color <COLOR>          Control colors in output [default: auto] [possible values: auto, always, never]
  -n, --no-cache               Avoid reading from or writing to the cache
      --cache-dir <CACHE_DIR>  Path to the cache directory [env: UV_CACHE_DIR=]
  -h, --help                   Print help (see more with '--help')
  -V, --version                Print version

試しに flask を消し飛ばす

❯ uv clean flask
Removed 7 files for flask (61.7KiB)

この間 numpy を python3.12 環境にインストールするときにキャッシュでハマったのでクリアを簡単にできるの嬉しいかも。

zztkmzztkm

Windows で Rye の uv を有効化してみた。

❯ rye sync
Reusing already existing virtualenv
Generating production lockfile: requirements.lock
warning: uv enabled in config but not supported on windows
Generating dev lockfile: requirements-dev.lock
warning: uv enabled in config but not supported on windows
Installing dependencies

ということで Windows ではサポートされていないらしく、この開発者体験が今すぐ欲しい人は linux or mac でやりましょう。

zztkmzztkm

依存先がURL依存を持っているとこける

結論

  • uv の仕様
    • URL依存はプロジェクトで直接依存管理されている必要がある
  • URLは依存は直接の依存として表現しましょう
  • 面倒だけど...

再現手順

❯ rye --version
rye 0.25.0
commit: 0.25.0 (d8e00cea1 2024-02-19)
platform: macos (aarch64)
self-python: cpython@3.12
symlink support: true
uv enabled: true

❯ rye init tox-rye-uv
❯ cd rye tox-uv
❯ rye add --dev tox-rye --git https://github.com/bluss/tox-rye❯ rye sync
Reusing already existing virtualenv
Generating production lockfile: /Users/zztkm/dev/sandbox/pydev/tox-rye-uv/requirements.lock
warning: Requirements file /var/folders/jf/ppd8_ywn5j94k064g559vgq00000gp/T/.tmpK0TR5T/requirements.txt does not contain any dependencies
   Built file:///Users/zztkm/dev/sandbox/pydev/tox-rye-uv                                                                                                                                                                                                                    Built 1 editable in 302ms
Resolved 1 package in 463ms
Generating dev lockfile: /Users/zztkm/dev/sandbox/pydev/tox-rye-uv/requirements-dev.lock
warning: Requirements file /var/folders/jf/ppd8_ywn5j94k064g559vgq00000gp/T/.tmpqOjgnq/requirements.txt does not contain any dependencies
   Built file:///Users/zztkm/dev/sandbox/pydev/tox-rye-uv                                                                                                                                                                                                                    Built 1 editable in 248ms
error: Package `virtualenv-rye-discovery` attempted to resolve via URL: git+https://github.com/bluss/virtualenv-rye-discovery@0.3.0. URL dependencies must be expressed as direct requirements or constraints. Consider adding `virtualenv-rye-discovery @ git+https://github.com/bluss/virtualenv-rye-discovery@0.3.0` to your dependencies or constraints file.
error: could not write dev lockfile for project

Caused by:
    failed to generate lockfile

回避方法(これはやりたくない
virtualenv-rye-discovery を直接依存に含めると回避できたので uv のバグかも?ある程度調べたら issue 立てるかなにかしてみる。

❯ rye add --dev virtualenv-rye-discovery --git https://github.com/bluss/virtualenv-rye-discovery
Added virtualenv-rye-discovery @ git+https://github.com/bluss/virtualenv-rye-discovery@4958f87a8fef73a1dddbb02fa3a98c93bab48377 as dev dependency
❯ rye sync
Reusing already existing virtualenv
Generating production lockfile: /Users/zztkm/dev/sandbox/pydev/tox-rye-uv/requirements.lock
   Built file:///Users/zztkm/dev/sandbox/pydev/tox-rye-uv                                                                                                                                                                                                                    Built 1 editable in 326ms
Resolved 1 package in 489ms
Generating dev lockfile: /Users/zztkm/dev/sandbox/pydev/tox-rye-uv/requirements-dev.lock
warning: Requirements file /var/folders/jf/ppd8_ywn5j94k064g559vgq00000gp/T/.tmpMEtKPA/requirements.txt does not contain any dependencies
   Built file:///Users/zztkm/dev/sandbox/pydev/tox-rye-uv                                                                                                                                                                                                                    Built 1 editable in 241ms
Updating https://github.com/bluss/virtualenv-rye-discovery (0.3.0)                                                                                                                                                                                                              Resolved 7 packages in 983ms
 Updated https://github.com/bluss/virtualenv-rye-discovery (4958f87)                                                                                                                                                                                                            Installing dependencies
   Built file:///Users/zztkm/dev/sandbox/pydev/tox-rye-uv                                                                                                                                                                                                                    Built 1 editable in 242ms
Resolved 6 packages in 0ms
   Built tox-rye @ git+https://github.com/bluss/tox-rye@d1348e996d642e947cd0fb158ecdbcfe0f386af3
   Built virtualenv-rye-discovery @ git+https://github.com/bluss/virtualenv-rye-discovery@4958f87a8fef73a1dddbb02fa3a98c93bab48377                                                                                                                                              Downloaded 6 packages in 585ms
Installed 7 packages in 6ms
 + distlib==0.3.8
 + filelock==3.13.1
 + platformdirs==4.2.0
 + tox-rye==0.3.0 (from git+https://github.com/bluss/tox-rye@d1348e996d642e947cd0fb158ecdbcfe0f386af3)
 + tox-rye-uv==0.1.0 (from file:///Users/zztkm/dev/sandbox/pydev/tox-rye-uv)
 + virtualenv==20.25.0
 + virtualenv-rye-discovery==0.3.0 (from git+https://github.com/bluss/virtualenv-rye-discovery@4958f87a8fef73a1dddbb02fa3a98c93bab48377)
Done!

関連ページ

https://zenn.dev/tkm/scraps/6c4f501ed15650

uv 単体で pip install してみてもエラーがでた。

❯ uv pip install "tox-rye @ git+https://github.com/bluss/tox-rye.git@0.3.0"
 Updated https://github.com/bluss/tox-rye.git (d1348e9)                                                                                                                                                                                                                         error: Package `virtualenv-rye-discovery` attempted to resolve via URL: git+https://github.com/bluss/virtualenv-rye-discovery@0.3.0. URL dependencies must be expressed as direct requirements or constraints. Consider adding `virtualenv-rye-discovery @ git+https://github.com/bluss/virtualenv-rye-discovery@0.3.0` to your dependencies or constraints file.

DeepL 翻訳

エラーが発生しました: パッケージ virtualenv-rye-discovery は URL: git+https://github.com/bluss/virtualenv-rye-discovery@0.3.0 から解決しようとしました。URL 依存は直接的な要件または制約として表現する必要があります。virtualenv-rye-discovery @ git+https://github.com/bluss/virtualenv-rye-discovery@0.3.0` を依存ファイルまたは制約ファイルに追加することを検討してください。

なるほど。uv の制限なのか。(というか rye 使ってても同じエラーが出てたのでちゃんと見てなかった...

ではこれはバグではなく仕様なので、大人しくそれぞれ rye add しておくのが良さそう。

zztkmzztkm

Rye uv で private GitHub Repository の依存を解決したい場合

git credential.helper の設定がないと以下のようなエラーになる。

> rye lock
error: Failed to download and build: hello @ git+https://github.com/zztkm/hello-private@v0.1.0
  Caused by: Git operation failed
  Caused by: failed to clone into: /Users/zztkm/Library/Caches/uv/git-v0 ...
  Caused by: failed to authenticate when downloading repository

* attempted to find username/password via git's `credential.helper` support, but failed
  Caused by: failed to acquire username/password from local configuration
error: could not write production lockfile for project

Caused by:
    failed to generate lockfile

対応方法

  • git credential.helper を設定する

.gitconfig に以下のような設定を追加することになる

[credential]
    helper = store --file ~/.git-credentials
    helper = cache --timeout 30000

自分は GitHub CLI を使って認証の管理をしているので、この設定をいれたあとに gh auth refresh したら設定通りにキャッシュされた。
キャッシュされたら rye lock が通った。

参考
https://git-scm.com/book/ja/v2/Git-のさまざまなツール-認証情報の保存
認証情報のキャッシュ方法が記載されていて参考になったのでまずはこちらのドキュメントを読んだうえで設定をしてみるのが良いかと思う

zztkmzztkm

【解決】Rye uv で GitHub リポジトリからの依存が pip install するときにバージョンコンフリクトを起こす

Rye 0.29.0 (uv 0.1.17) で Git 依存のコンフリクト問題は解消されました。

uv 0.1.17 以降では lock ファイルは変わらず commit hash になりますが、dependencies に @develop、lock ファイルに commit hash が指定されていた場合、
uv は commit hash を @develop のより正確な値であると仮定して処理することで、コンフリクトエラーを出さないようなりました。

詳細は

前提

  • Rye で uv を使ってる

問題

❯ rye run tox -e py311
py311: venv> .venv/bin/uv venv -p 3.11 /Users/zztkm/dev/github.com/zztkm/hello-git-uv/.tox/py311/.venv
py311: install_deps> .venv/bin/uv pip install -r requirements-dev.lock
   Built file:///Users/ttsuruta/dev/github.com/zztkm/hello-git-uv                                                                                                                                                                                                Built 1 editable in 341ms
error: Requirements contain conflicting URLs for package `hello-git-uv`:
- git+https://github.com/zztkm/hello-git-uv@03d18dc51cf22e2f6ccf1637a2080de75d19ea7d
- git+https://github.com/zztkm/hello-git-uv@v0.1.0
py311: exit 2 (0.53 seconds) /Users/ttsuruta/dev/github.com/zztkm/hello-git-uv> .venv/bin/uv pip install -r requirements-dev.lock pid=77767
  py311: FAIL code 2 (0.59 seconds)
  evaluation failed :( (0.62 seconds)

推測
rye add するときは tag で指定していたが、lock ファイルでは commit に切り替わっていて、pyproject.toml に記載の依存関係とコンフリクトを起こしていそう。

困るパターン

  • git 依存パッケージがさらに git 依存パッケージを持っている場合

どうするか?

  • uv で commit ではなく指定したタグでロックできるようにしてもらえるか聞いてみる
  • それまでは rye で uv を利用しないほうが良いかも
zztkmzztkm

Rye とか uv とか使わずに pip でやってるプロジェクトで tox を利用してるなら、tox-uv 単体でも採用してみるのはありかも。
多分速度に感動して uv に切り替えたくなるかもだけど。

https://github.com/tox-dev/tox-uv

tox 公式が出しているという安心感もある。uv のバグを踏む可能性はあるのでそこは貢献のチャンスと思ってもらって。

既存の tox.ini を特にいじらずに、tox をアンインストールして tox-uv をインストールすれば導入完了した。

zztkmzztkm

sounddevice を Rye uv で install したときの問題

※ 深掘りしていないので、推測が含まれます。

uv 有効化状態で、sounddevice をインストールしてスクリプトを実行しようとしたときに以下のエラーが発生した。
その後、uv を無効化し、pip でインストールしたところ問題が解消した。

$ rye run media_recvonly
Traceback (most recent call last):
  File "C:\Users\takum\dev\github.com\shiguredo\sora-python-sdk-samples\.venv\lib\site-packages\sounddevice.py", line 71, in <module>
    raise OSError('PortAudio library not found')
OSError: PortAudio library not found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\takum\.rye\py\cpython@3.8.18\install\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\takum\.rye\py\cpython@3.8.18\install\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\takum\dev\github.com\shiguredo\sora-python-sdk-samples\.venv\Scripts\media_recvonly.exe\__main__.py", line 5, in <module>
  File "C:\Users\takum\dev\github.com\shiguredo\sora-python-sdk-samples\src\media\recvonly.py", line 9, in <module>
    import sounddevice
  File "C:\Users\takum\dev\github.com\shiguredo\sora-python-sdk-samples\.venv\lib\site-packages\sounddevice.py", line 80, in <module>
    import _sounddevice_data
ModuleNotFoundError: No module named '_sounddevice_data'

uv 無効化

$ rye config --set-bool behavior.use-uv=false
$ rye sync -f

# このあとは問題なかった。

調査

.venv の site-packages 配下を見ると、uv のときは _sounddevice_data がなくて、pip のときにはあることがわかった。どうやらこのディレクトリに portaudio ライブラリがインストールされるっぽい。

なんで uv だと _sounddevice_data が作られないかまではわかっていないので、Rye を利用せずに uv だけで試してみて、uv と pip のインストールされる状態の違いを issue で報告するだけしてみるか。

zztkmzztkm

Scrap だと見出しがなくて気になるトピックに飛びづらいので更新前提ではあるが、Rye uv の記事書こうかな。

zztkmzztkm

Rye 内臓の lint, fmt コマンドについて。

Rye 内臓の Ruff のバージョンは、固定されているので、Rye のバージョンアップごとにしかバージョンアップされない。

また、Ruff はまだ安定版ではないので、Ruff のバージョンアップによっては ruff format の結果が変わることもある(フォーマットが変わったこと自体は検知できるし特に問題ないとは思うけど)。

複数人で開発している場合など以下のケースで困ることがあると思った。

  • Rye のバージョンは開発者に依存し、プロジェクト設定で強制することができないので、別々のフォーマットが並行して適用されると混乱の種になる
  • Rye のバージョンアップ時に Ruff のバージョンも上がることがあるので、良きせぬフォーマット変更が入る(許容できるかもしれないが
  • Ruff の最新が出たときに、Rye のバージョンアップを待つことになる

というのもあり、個人的には Ruff のバージョンは rye.dev-dependencies と lock ファイルで管理して、rye fmt は使わずに、rye run ruff format するとか、makefile に fmt を追加して make fmt するとか、tool.rye.scripts に fmt = "ruff format" を定義すると良いと思ってる。

rye test も同様。

まあ、基本 pytest とか Ruff とかのバージョンを自分であげていくモチベーションがある人もそんなにいないので、rye self update したら勝手にバージョンが上がってくれるのはメリットでもあるかも?

zztkmzztkm

TODO: Rye (uv) で相対パスでローカルのパッケージをインストールする方法をまとめる

これは記事にしてここにリンク残す感じにするか。

zztkmzztkm

self update

self update できるようになってる

uv self update
zztkmzztkm

releases を眺めてたけど、今は pip にある option のサポートをメインで進めてる感じなのかな。

Rye を置き換えられるのはまだ先になりそうだけど、開発自体はめちゃくちゃ進んでるのでそう遠い話ではないかもしれない。楽しみ