Skip to content

How to select the installerインストーラーの選択方法


Enabling UVUVを有効にする

The virtual environment type by default uses virtualenv for virtual environment creation and pip to install dependencies. You can speed up environment creation and dependency resolution by using UV instead of both of those tools.デフォルトでは、virtual 環境タイプは、仮想環境の作成に virtualenv を使用し、依存関係のインストールには pip を使用します。これらのツールの代わりに UV を使用することで、環境の作成と依存関係の解決を高速化できます。

caveat注意

UV is under active development and may not work for all dependencies.UVは現在も活発に開発中であり、すべての依存関係に対して動作しない可能性があります。

To do so, set the installer option to uv. For example, if you wanted to enable this functionality for the default environment, you could set the following:そのためには、installer オプションuv に設定します。たとえば、デフォルト 環境に対してこの機能を有効にしたい場合、次のように設定できます:

[tool.hatch.envs.default]
installer = "uv"
[envs.default]
installer = "uv"

Tipヒント

All environments that enable UV will have the path to UV available as the HATCH_UV environment variable.UVを有効にしたすべての環境は、HATCH_UV 環境変数としてUVへのパスを利用可能にします。

Configuring the versionバージョンの設定

The UV that is shared by all environments uses a specific version range that is known to work with Hatch. If you want to use a different version, you can override the dependencies for the internal hatch-uv environment:すべての環境で共有されるUVは、Hatchで動作することが知られている特定のバージョン範囲を使用します。異なるバージョンを使用したい場合は、内部の hatch-uv 環境の依存関係をオーバーライドできます:

[tool.hatch.envs.hatch-uv]
dependencies = [
  "uv>9000",
]
[envs.hatch-uv]
dependencies = [
  "uv>9000",
]

Externally managed外部管理

If you want to manage UV yourself, you can expose it to Hatch by setting the HATCH_ENV_TYPE_VIRTUAL_UV_PATH environment variable which should be the absolute path to a UV binary for Hatch to use instead. This implicitly enables UV.UVを自分で管理したい場合は、HATCH_ENV_TYPE_VIRTUAL_UV_PATH 環境変数を設定してHatchに公開できます。この変数は、Hatchが使用するUVバイナリへの絶対パスである必要があります。これにより、暗黙的にUVを有効にします

Installer script aliasインストーラスクリプトエイリアス

If you have scripts or commands that call pip, it may be useful to alias the uv pip command to pip so that you can use the same commands for both methods of configuration and retain your muscle memory. The following is an example of a matrix that conditionally enables UV and sets the alias:もしあなたが スクリプト または コマンド を持っていて、それが pip を呼び出す場合、uv pip コマンドを pip にエイリアスすることが有用かもしれません。これにより、両方の設定方法に対して同じコマンドを使用し、筋肉の記憶を保持することができます。以下は、条件付きで UV を有効にし、エイリアスを設定するマトリックスの例です:

[[tool.hatch.envs.example.matrix]]
tool = ["uv", "pip"]

[tool.hatch.envs.example.overrides]
matrix.tool.installer = { value = "{matrix:tool}" }
matrix.tool.scripts = [
  { key = "pip", value = "{env:HATCH_UV} pip {args}", if = ["uv"] },
]
[[envs.example.matrix]]
tool = ["uv", "pip"]

[envs.example.overrides]
matrix.tool.installer = { value = "{matrix:tool}" }
matrix.tool.scripts = [
  { key = "pip", value = "{env:HATCH_UV} pip {args}", if = ["uv"] },
]

Another common use case is to expose UV to all test environments. In this case, you often wouldn't want to modify the scripts mapping directly but rather add an extra script:もう一つの一般的な使用例は、UV をすべての テスト環境 に公開することです。この場合、通常は scripts マッピングを直接変更したくはなく、むしろ 追加スクリプト を追加することになります:

[tool.hatch.envs.hatch-test.extra-scripts]
pip = "{env:HATCH_UV} pip {args}"
[envs.hatch-test.extra-scripts]
pip = "{env:HATCH_UV} pip {args}"