Environment configuration¶環境設定¶
All environments are defined as sections within the tool.hatch.envs table.すべての環境は、tool.hatch.envs テーブル内のセクションとして定義されています。
[tool.hatch.envs.<ENV_NAME>]
[envs.<ENV_NAME>]
The storage location for environments is completely configurable.環境のストレージ場所は完全に設定可能です。
Unless an environment is explicitly selected on the command line, the default environment will be used. The type of this environment defaults to virtual.コマンドラインで環境が明示的に選択されない限り、default 環境が使用されます。この環境のタイプはデフォルトでvirtualです。
Info情報
Environments prefixed by hatch- are used for special purposes e.g. testing.hatch-で始まる環境は、特別な目的のために使用されます。例えば、テストなどです。
Inheritance¶継承¶
All environments inherit from the environment defined by its template option, which defaults to default.すべての環境は、そのtemplateオプションで定義された環境から継承され、デフォルトはdefaultです。
So for the following configuration:したがって、次の設定の場合:
[tool.hatch.envs.foo]
type = "baz"
skip-install = true
[tool.hatch.envs.bar]
template = "foo"
skip-install = false
[envs.foo]
type = "baz"
skip-install = true
[envs.bar]
template = "foo"
skip-install = false
the environment bar will be of type baz with skip-install set to false.環境barは、bazタイプで、skip-installがfalseに設定されます。
Self-referential environments¶自己参照環境¶
You can disable inheritance by setting template to the environment's own name:templateを環境自身の名前に設定することで、継承を無効にできます:
[tool.hatch.envs.foo]
template = "foo"
[envs.foo]
template = "foo"
Detached environments¶切り離された環境¶
A common use case is standalone environments that do not require inheritance nor the installation of the project, such as for linting or sometimes building documentation. Enabling the detached option will make the environment self-referential and will skip project installation:一般的な使用ケースは、継承やプロジェクトのインストールを必要としないスタンドアロン環境で、例えばリンティングや時にはドキュメントのビルドなどです。detachedオプションを有効にすると、環境は自己参照となり、プロジェクトのインストールをスキップします:
[tool.hatch.envs.lint]
detached = true
[envs.lint]
detached = true
Dependencies¶依存関係¶
You can install dependencies in addition to the ones defined by your project's metadata. Entries support context formatting.あなたは依存関係を、あなたのプロジェクトのメタデータで定義されたものに加えてインストールできます。エントリはコンテキストフォーマットをサポートします。
[tool.hatch.envs.test]
dependencies = [
"coverage[toml]",
"pytest",
"pytest-cov",
"pytest-mock",
]
[envs.test]
dependencies = [
"coverage[toml]",
"pytest",
"pytest-cov",
"pytest-mock",
]
If you define environments with dependencies that only slightly differ from their inherited environments, you can use the extra-dependencies option to avoid redeclaring the dependencies option:依存関係が継承された環境とわずかに異なる環境を定義する場合、extra-dependenciesオプションを使用してdependenciesオプションを再宣言するのを避けることができます:
[tool.hatch.envs.default]
dependencies = [
"foo",
"bar",
]
[tool.hatch.envs.experimental]
extra-dependencies = [
"baz",
]
[envs.default]
dependencies = [
"foo",
"bar",
]
[envs.experimental]
extra-dependencies = [
"baz",
]
Tipヒント
Hatch uses pip to install dependencies so any configuration it supports Hatch does as well. For example, if you wanted to only use a private repository you could set the PIP_INDEX_URL environment variable.Hatchはpipを使用して依存関係をインストールするため、Hatchがサポートする設定も同様にサポートされます。例えば、プライベートリポジトリのみを使用したい場合は、PIP_INDEX_URL 環境変数を設定できます。
Installation¶インストール¶
Features (extras)¶機能(追加機能)¶
If your project defines optional dependencies, you can select which groups to install using the features option:プロジェクトがオプションの依存関係を定義している場合、featuresオプションを使用してインストールするグループを選択できます:
[tool.hatch.envs.nightly]
features = [
"server",
"grpc",
]
[envs.nightly]
features = [
"server",
"grpc",
]
Note注意
Features/optional dependencies are also known as extras in other tools.機能/オプションの依存関係は、他のツールではextrasとして知られています。
Dependency Groups¶依存関係グループ¶
Dependency groups provide a uniform way to organize related development dependencies. See advanced usage for more details on dependency group features like including other groups.依存関係グループは、関連する開発依存関係を整理するための一貫した方法を提供します。依存関係グループの機能や他のグループを含める方法についての詳細は、高度な使用法を参照してください。
You can include dependency-groups in your hatch environments using the [dependency-groups] array:依存関係グループを[dependency-groups]配列を使用してハッチ環境に含めることができます:
[dependency-groups]
test = [
"pytest>=7.0.0",
"pytest-cov>=4.1.0",
]
[tool.hatch.envs.test]
dependency-groups = [
"test",
]
[dependency-groups]
test = [
"pytest>=7.0.0",
"pytest-cov>=4.1.0",
]
[envs.test]
dependency-groups = [
"test",
]
Dev mode¶開発モード¶
By default, environments will always reflect the current state of your project on disk, for example, by installing it in editable mode in a Python environment. Set dev-mode to false to disable this behavior and have your project installed only upon creation of a new environment. From then on, you need to manage your project installation manually.デフォルトでは、環境は常にディスク上のプロジェクトの現在の状態を反映します。たとえば、Python環境で編集可能モードでインストールされます。dev-modeをfalseに設定すると、この動作を無効にし、新しい環境の作成時にのみプロジェクトがインストールされるようになります。それ以降は、プロジェクトのインストールを手動で管理する必要があります。
[tool.hatch.envs.static]
dev-mode = false
[envs.static]
dev-mode = false
Skip install¶インストールをスキップ¶
By default, environments will install your project during creation. To ignore this step, set skip-install to true:デフォルトでは、環境は作成時にプロジェクトをインストールします。このステップを無視するには、skip-installをtrueに設定します:
[tool.hatch.envs.lint]
skip-install = true
[envs.lint]
skip-install = true
Environment variables¶環境変数¶
Defined¶定義済み¶
You can define environment variables with the env-vars option:環境変数は env-vars オプションで定義できます:
[tool.hatch.envs.docs]
dependencies = [
"mkdocs"
]
[tool.hatch.envs.docs.env-vars]
SOURCE_DATE_EPOCH = "1580601600"
[envs.docs]
dependencies = [
"mkdocs"
]
[envs.docs.env-vars]
SOURCE_DATE_EPOCH = "1580601600"
Values support context formatting.値は コンテキストフォーマッティング をサポートしています。
Filters¶フィルター¶
By default, environments will have access to all environment variables. You can filter with wildcard patterns using the env-include/env-exclude options:デフォルトでは、環境はすべての環境変数にアクセスできます。 env-include/env-exclude オプションを使用してワイルドカードパターンでフィルタリングできます:
[tool.hatch.envs.<ENV_NAME>]
env-include = [
"FOO*",
]
env-exclude = [
"BAR",
]
[envs.<ENV_NAME>]
env-include = [
"FOO*",
]
env-exclude = [
"BAR",
]
Exclusion patterns take precedence but will never affect defined environment variables.除外パターンは優先されますが、定義された 環境変数には影響しません。
Scripts¶スクリプト¶
You can define named scripts that may be executed or referenced at the beginning of other scripts. Context formatting is supported.名前付きスクリプトを定義でき、他のスクリプトの最初で 実行 または参照することができます。 コンテキストフォーマッティング がサポートされています。
For example, in the following configuration:例えば、次の構成では:
[tool.hatch.envs.test]
dependencies = [
"coverage[toml]",
"pytest",
"pytest-cov",
"pytest-mock",
]
[tool.hatch.envs.test.scripts]
run-coverage = "pytest --cov-config=pyproject.toml --cov=pkg --cov=tests"
run = "run-coverage --no-cov"
[envs.test]
dependencies = [
"coverage[toml]",
"pytest",
"pytest-cov",
"pytest-mock",
]
[envs.test.scripts]
run-coverage = "pytest --cov-config=pyproject.toml --cov=pkg --cov=tests"
run = "run-coverage --no-cov"
the run script would be expanded to:run スクリプトは次のように展開されます:
pytest --cov-config=pyproject.toml --cov=pkg --cov=tests --no-cov
Scripts can also be defined as an array of strings.スクリプトは文字列の配列としても定義できます。
[tool.hatch.envs.style]
detached = true
dependencies = [
"flake8",
"black",
"isort",
]
[tool.hatch.envs.style.scripts]
check = [
"flake8 .",
"black --check --diff .",
"isort --check-only --diff .",
]
fmt = [
"isort .",
"black .",
"check",
]
[envs.style]
detached = true
dependencies = [
"flake8",
"black",
"isort",
]
[envs.style.scripts]
check = [
"flake8 .",
"black --check --diff .",
"isort --check-only --diff .",
]
fmt = [
"isort .",
"black .",
"check",
]
Similar to make, you can ignore the exit code of commands that start with - (a hyphen). For example, the script error defined by the following configuration would halt after the second command with 3 as the exit code:makeと同様に、-(ハイフン)で始まるコマンドの終了コードを無視することができます。例えば、以下の設定で定義されたスクリプトerrorは、終了コード3で2番目のコマンドの後に停止します:
[tool.hatch.envs.test.scripts]
error = [
"- exit 1",
"exit 3",
"exit 0",
]
[envs.test.scripts]
error = [
"- exit 1",
"exit 3",
"exit 0",
]
Extra scripts¶追加スクリプト¶
Individual scripts inherit from parent environments just like options. To guarantee that individual scripts do not override those defined by parent environments, you can use the extra-scripts option instead which is only capable of adding scripts that have not been defined.個々のスクリプトは、オプションと同様に親環境から継承されます。個々のスクリプトが親環境で定義されたものを上書きしないことを保証するために、定義されていないスクリプトのみを追加できるextra-scriptsオプションを使用できます。
Commands¶コマンド¶
All commands are able to use any defined scripts. Also like scripts, context formatting is supported and the exit code of commands that start with a hyphen will be ignored.すべてのコマンドは、定義されたスクリプトを使用できます。また、スクリプトと同様に、コンテキストフォーマットもサポートされており、ハイフンで始まるコマンドの終了コードは無視されます。
Pre-install¶プレインストール¶
You can run commands immediately before environments install your project.プロジェクトを環境がインストールする直前にコマンドを実行できます。
[tool.hatch.envs.<ENV_NAME>]
pre-install-commands = [
"...",
]
[envs.<ENV_NAME>]
pre-install-commands = [
"...",
]
Post-install¶ポストインストール¶
You can run commands immediately after environments install your project.プロジェクトを環境がインストールした直後にコマンドを実行できます。
[tool.hatch.envs.<ENV_NAME>]
post-install-commands = [
"...",
]
[envs.<ENV_NAME>]
post-install-commands = [
"...",
]
Python version¶Pythonバージョン¶
The python option specifies which version of Python to use, or an absolute path to a Python interpreter:pythonオプションは、使用するPythonのバージョンまたはPythonインタプリタへの絶対パスを指定します。
[tool.hatch.envs.<ENV_NAME>]
python = "3.10"
[envs.<ENV_NAME>]
python = "3.10"
All environment types should respect this option.すべての環境タイプは、このオプションを尊重する必要があります。
Supported platforms¶サポートされているプラットフォーム¶
The platforms option indicates the operating systems with which the environment is compatible:platformsオプションは、環境が互換性のあるオペレーティングシステムを示します。
[tool.hatch.envs.<ENV_NAME>]
platforms = ["linux", "windows", "macos"]
[envs.<ENV_NAME>]
platforms = ["linux", "windows", "macos"]
The following platforms are supported:以下のプラットフォームがサポートされています:
linuxlinuxwindowswindowsmacosmacos
If unspecified, the environment is assumed to be compatible with all platforms.指定されていない場合、環境はすべてのプラットフォームと互換性があると見なされます。
Description¶説明¶
The description option is purely informational and is displayed in the output of the env show command:descriptionオプションは純粋に情報的であり、env showコマンドの出力に表示されます。
[tool.hatch.envs.<ENV_NAME>]
description = """
Lorem ipsum ...
"""
[envs.<ENV_NAME>]
description = """
Lorem ipsum ...
"""
Type¶タイプ¶
An environment's type determines which environment plugin will be used for management. The only built-in environment type is virtual, which uses virtual Python environments.環境のtypeは、どの環境プラグインが管理に使用されるかを決定します。組み込みの環境タイプはvirtualのみで、これは仮想Python環境を使用します。