Context formatting¶コンテキストフォーマット¶
You can populate configuration with the values of certain supported fields using the syntax of Python's format strings. Each field interprets the modifier part after the colon differently, if at all.特定のサポートされているフィールドの値で構成を埋めるには、Pythonのフォーマット文字列の構文を使用できます。各フィールドは、コロンの後の修飾子部分を異なる方法で解釈します。
Global fields¶グローバルフィールド¶
Any configuration that declares support for context formatting will always support these fields.コンテキストフォーマットのサポートを宣言する任意の構成は、常にこれらのフィールドをサポートします。
Paths¶パス¶
| Fieldフィールド | Description説明 |
|---|---|
rootroot | The root project directoryルートプロジェクトディレクトリ |
homehome | The user's home directoryユーザーのホームディレクトリ |
All paths support the following modifiers:すべてのパスは、次の修飾子をサポートします:
| Modifier修飾子 | Description説明 |
|---|---|
uriuri | The normalized absolute URI path prefixed by file:file: で始まる正規化された絶対URIパス |
realreal | The path with all symbolic links resolvedすべてのシンボリックリンクが解決されたパス |
parentparent | The parent of the preceding path前のパスの親 |
Tipヒント
The parent modifier can be chained and may be combined with either the uri or real modifier, with the latter placed at the end. For example:parent 修飾子はチェーン可能で、uri または real 修飾子と組み合わせることができ、後者が最後に配置されます。例えば:
[tool.hatch.envs.test]
dependencies = [
"example-project @ {root:parent:parent:uri}/example-project",
]
[envs.test]
dependencies = [
"example-project @ {root:parent:parent:uri}/example-project",
]
System separators¶システムセパレーター¶
| Fieldフィールド | Description説明 |
|---|---|
/ | \ on Windows, / otherwiseWindowsでは\、それ以外では/ |
; | ; on Windows, : otherwiseWindowsでは;、それ以外では: |
Environment variables¶環境変数¶
The env field and its modifier allow you to select the value of an environment variable. If the environment variable is not set, you must specify a default value as an additional modifier e.g. {env:PATH:DEFAULT}.env フィールドとその修飾子を使用すると、環境変数の値を選択できます。環境変数が設定されていない場合は、追加の修飾子としてデフォルト値を指定する必要があります。例: {env:PATH:DEFAULT}。
Field nesting¶フィールドのネスト¶
You can insert fields within others. For example, if you wanted a script that displays the value of the environment variable FOO, with a fallback to the environment variable BAR, with its own fallback to the user's home directory, you could do the following:他のフィールド内にフィールドを挿入することができます。例えば、環境変数 FOO の値を表示し、環境変数 BAR にフォールバックし、さらにユーザーのホームディレクトリにフォールバックする スクリプト を作成したい場合、次のようにできます:
[tool.hatch.envs.test.scripts]
display = "echo {env:FOO:{env:BAR:{home}}}"
[envs.test.scripts]
display = "echo {env:FOO:{env:BAR:{home}}}"