Closed1

aqua の Python Support

Shunsuke SuzukiShunsuke Suzuki

aqua で Python を管理できるようにしようとしています。

https://github.com/aquaproj/aqua-registry/issues/1138

https://github.com/aquaproj/aqua-registry/pull/26154

https://github.com/aquaproj/aqua/pull/3052

How to set up

  1. aqua, aqua-registry の update
  2. package indygreg/python-build-standalone のインストール
aqua g -i indygreg/python-build-standalone
  1. aqua.yaml を編集して vars parameter を設定
packages:
  - name: indygreg/python-build-standalone@20240726
    vars:
      python_version: 3.11.9

このように、 Python のバージョンは package のバージョンではなく、 varspython_version というパラメータで指定します。
これが他の aqua のパッケージとは大きく異なるところです。

使ってみる

aqua i -l
python -V
pip -V

pip install で CLI ツールをインストールする際の注意点

普通に pip install でインストールしても直接実行することはできません。
なぜかというとインストール先が $PATH に含まれていないからです。

pip install mkdocs
which mkdocs

この問題には幾つかの解決策があります。

  1. python -m 経由で実行する
  2. virtualenvvenv といった Python package のバージョン管理ツールを使う
python -m mkdocs

Python package のバージョン管理ツールは色々あります。

https://zenn.dev/shunsuke_suzuki/scraps/dff3add208ac20

これらを使うと適切に $PATH を更新してくれます。

python -m venv foo
. foo/bin/activate

build 済み Python indygreg/python-build-standalone の活用

従来 Python をインストールする際はコードからビルドする必要がありました。
しかし aqua はセキュリティなどの観点からツールをインストールする際に任意のコマンド実行をサポートしていないため 、 Python をサポートすることができませんでした。

しかし、ビルド済みの Python を配布する indygreg/python-build-standalone というプロジェクトがあることを知り、これを使って Python をサポートすることにしました。

vars parameter

indygreg/python-build-standalone の asset は GitHub Releases で配布されるもののバージョニングは特殊で、
GitHub Releases のバージョンは日付になり、 Python のバージョンは asset 名に含まれる形になります。
つまり aqua で Python をインストールするには indygreg/python-build-standalone のバージョンと Python のバージョンを指定する必要がありました。

そこで Python のバージョンを指定できるようにするため、 aqua.yaml で任意のパラメータを渡せるようにしました。

https://github.com/aquaproj/aqua/pull/3052

packages:
  - name: indygreg/python-build-standalone@20240726
    vars:
      python_version: 3.11.9

各 package でなんの変数が指定できるかは Registry で定義されています。

https://github.com/aquaproj/aqua-registry/pull/26154

https://github.com/aquaproj/aqua-registry/blob/d1e72c6929dfbcc27ba2c5f74a2c0293d4800622/pkgs/indygreg/python-build-standalone/registry.yaml#L6-L9

python_version は必須になっているので、 aqua.yaml で python_version を指定せずにインストールしようとすると失敗します。

Renovate による自動 update

indygreg/python-build-standalone のバージョンは従来通り aqua-renovate-config で update できます。
加えて Python version も update するには、 aqua-renovate-config を 2.4.0 以上にする必要があります。

https://github.com/aquaproj/aqua-renovate-config/pull/634

Python version の data source

https://docs.renovatebot.com/modules/datasource/python-version/

aqua update による Python version の update

現状対応していません。

aqua g -s や aqua update -s による Python のバージョン選択

現状対応していません。

このスクラップは2024/10/21にクローズされました