Environment collector plugins¶環境コレクタープラグイン¶
Environment collectors allow for dynamically modifying environments or adding environments beyond those defined in config. Users can override default values provided by each environment.環境コレクターは、環境を動的に変更したり、configで定義された環境を超えて環境を追加することを可能にします。ユーザーは各環境が提供するデフォルト値を上書きできます。
Known third-party¶既知のサードパーティ¶
- hatch-mkdocs - integrate MkDocs and infer dependencies into an envhatch-mkdocs - MkDocsを統合し、envに依存関係を推測します
Installation¶インストール¶
Any required environment collectors that are not built-in must be manually installed alongside Hatch or listed in the tool.hatch.env.requires array for automatic management:組み込みでない必要な環境コレクターは、Hatchと一緒に手動でインストールするか、tool.hatch.env.requires配列にリストして自動管理する必要があります:
[tool.hatch.env]
requires = [
"...",
]
[env]
requires = [
"...",
]
EnvironmentCollectorInterface ¶EnvironmentCollectorInterface ¶
Example usage:使用例:
from hatch.env.collectors.plugin.interface import EnvironmentCollectorInterface
class SpecialEnvironmentCollector(EnvironmentCollectorInterface):
PLUGIN_NAME = 'special'
...
from hatchling.plugin import hookimpl
from .plugin import SpecialEnvironmentCollector
@hookimpl
def hatch_register_environment_collector():
return SpecialEnvironmentCollector
Source code in src/hatch/env/collectors/plugin/interface.py
class EnvironmentCollectorInterface:
"""
Example usage:
```python tab="plugin.py"
from hatch.env.collectors.plugin.interface import EnvironmentCollectorInterface
class SpecialEnvironmentCollector(EnvironmentCollectorInterface):
PLUGIN_NAME = 'special'
...
```
```python tab="hooks.py"
from hatchling.plugin import hookimpl
from .plugin import SpecialEnvironmentCollector
@hookimpl
def hatch_register_environment_collector():
return SpecialEnvironmentCollector
```
"""
PLUGIN_NAME = ""
"""The name used for selection."""
def __init__(self, root, config):
self.__root = root
self.__config = config
@property
def root(self):
"""
The root of the project tree as a path-like object.
"""
return self.__root
@property
def config(self) -> dict:
"""
```toml config-example
[tool.hatch.env.collectors.<PLUGIN_NAME>]
```
"""
return self.__config
def get_initial_config(self) -> dict[str, dict]: # noqa: PLR6301
"""
Returns configuration for environments keyed by the environment or matrix name.
"""
return {}
def finalize_config(self, config: dict[str, dict]):
"""
Finalizes configuration for environments keyed by the environment or matrix name. This will override
any user-defined settings and any collectors that ran before this call.
This is called before matrices are turned into concrete environments.
"""
def finalize_environments(self, config: dict[str, dict]):
"""
Finalizes configuration for environments keyed by the environment name. This will override
any user-defined settings and any collectors that ran before this call.
This is called after matrices are turned into concrete environments.
"""
PLUGIN_NAME = '' class-attribute instance-attribute ¶PLUGIN_NAME = '' class-attribute instance-attribute ¶
The name used for selection.選択に使用される名前。
root property ¶root property ¶
The root of the project tree as a path-like object.プロジェクトツリーのルートをパスのようなオブジェクトとして表します。
config: dict property ¶config: dict property ¶
[tool.hatch.env.collectors.<PLUGIN_NAME>]
[env.collectors.<PLUGIN_NAME>]
get_initial_config() -> dict[str, dict] ¶get_initial_config() -> dict[str, dict] ¶
Returns configuration for environments keyed by the environment or matrix name.環境またはマトリックス名でキー付けされた環境のための設定を返します。
Source code in src/hatch/env/collectors/plugin/interface.py
def get_initial_config(self) -> dict[str, dict]: # noqa: PLR6301
"""
Returns configuration for environments keyed by the environment or matrix name.
"""
return {}
finalize_config(config: dict[str, dict]) ¶finalize_config(config: dict[str, dict]) ¶
Finalizes configuration for environments keyed by the environment or matrix name. This will override any user-defined settings and any collectors that ran before this call.環境またはマトリックス名でキー付けされた環境のための設定を最終化します。これにより、ユーザー定義の設定やこの呼び出しの前に実行されたコレクターが上書きされます。
This is called before matrices are turned into concrete environments.これは、マトリックスが具体的な環境に変換される前に呼び出されます。
Source code in src/hatch/env/collectors/plugin/interface.py
def finalize_config(self, config: dict[str, dict]):
"""
Finalizes configuration for environments keyed by the environment or matrix name. This will override
any user-defined settings and any collectors that ran before this call.
This is called before matrices are turned into concrete environments.
"""
finalize_environments(config: dict[str, dict]) ¶finalize_environments(config: dict[str, dict]) ¶
Finalizes configuration for environments keyed by the environment name. This will override any user-defined settings and any collectors that ran before this call.環境名でキー付けされた環境のための設定を最終化します。これにより、ユーザー定義の設定やこの呼び出しの前に実行されたコレクターが上書きされます。
This is called after matrices are turned into concrete environments.これは、マトリックスが具体的な環境に変換された後に呼び出されます。
Source code in src/hatch/env/collectors/plugin/interface.py
def finalize_environments(self, config: dict[str, dict]):
"""
Finalizes configuration for environments keyed by the environment name. This will override
any user-defined settings and any collectors that ran before this call.
This is called after matrices are turned into concrete environments.
"""