public_notes/content/20240722101442 Rye.md

120 lines
No EOL
3.7 KiB
Markdown

# 20240722101442 Rye
#tech #python
## Rye?
Ryeはpythonのプロジェクトとかパッケージをいい感じに管理してくれるやつ。 [[20231129211719 poetry|poetry]] と近い(けどこっちの方がよさそうな感触)
[Rye](https://rye.astral.sh/)
関連ツール的なものに、
- [[20240722104422 uv]]
- [[20240722104428 Ruff]]
がある。どれもastralという社が開発しているようだ。
[Astral: Next-gen Python tooling](https://astral.sh/)
## インストール
### windows
公式サイト [Rye](https://rye.astral.sh/) から.exeをダウンロードして実行。
```
Welcome to Rye!
Rye has detected that it's not installed on this computer yet and
automatically started the installer for you. For more information
read https://rye.astral.sh/guide/installation/
This installer will install rye to C:\Users\saita\.rye
This path can be changed by exporting the RYE_HOME environment variable.
Details:
Rye Version: 0.37.0
Platform: windows (x86_64)
```
途中で聞かれる質問には
```
✔ What should running `python` or `python3` do when you are not inside a Rye managed project? · Run the old default Python (provided by your OS, pyenv, etc.)
```
以外は全てデフォルトにしておいた(まだ信用していない)。
インストールが終了すると、自動でパスが通って使えるようになっていた。
### linux
wslのubuntuで試した。
```
curl -sSf https://rye.astral.sh/get | bash
This script will automatically download and install rye (latest) for you.
######################################################################## 100.0%
Welcome to Rye!
This installer will install rye to /home/kazbo/.rye
This path can be changed by exporting the RYE_HOME environment variable.
Details:
Rye Version: 0.37.0
Platform: linux (x86_64)
✔ Continue? · yes
✔ Select the preferred package installer · uv (fast, recommended)
✔ What should running `python` or `python3` do when you are not inside a Rye managed project? · Run the old default Python (provided by your OS, pyenv, etc.)
Installed binary to /home/kazbo/.rye/shims/rye
Bootstrapping rye internals
Downloading cpython@3.12.4
Checking checksum
Unpacking
Downloaded cpython@3.12.4
Updated self-python installation at /home/kazbo/.rye/self
The rye directory /home/kazbo/.rye/shims was not detected on PATH.
It is highly recommended that you add it.
✔ Should the installer add Rye to PATH via .profile? · yes
Added to PATH.
note: for this to take effect you will need to restart your shell or run this manually:
source "$HOME/.rye/env"
For more information read https://rye.astral.sh/guide/installation/
All done!
```
## プロジェクト作成(executable)
自分の場合、実行できるスクリプトを作る方が多い。とりあえずその方法(`--script`を除けばライブラリ用のテンプレートが自動作成される)
[Basics - Rye](https://rye.astral.sh/guide/basics/) に書かれている。
```
rye init --script [project名]
```
ってやるとフォルタが作られる。ちなみに、
```
rye init
```
だけだと,カレントディレクトリに必要なファイルが作られる。
```
rye sync
```
を実行すると、フォルダ内に自動的にローカルなpythonの実行環境(.venv)が作成される。cf. [[20240121125457 venv|venv]]
実行するには、プロジェクトのディレクトリ内で、
```
rye run [project名]
```
とやればよい。
## poetryとの比較
poetry 1.8.2くらいとの比較。
pros:
- デフォルトでローカルフォルダに .venvを作ってくれる
- 実行可能スクリプトのプロジェクトがオマケじゃない感がある
cons:
- 今のところ無い