Skip to content

Pluginsプラグイン


Hatch utilizes pluggy for its plugin functionality.Hatchはそのプラグイン機能のためにpluggyを利用しています。

Overview概要

All plugins provide registration hooks that return one or more classes that inherit from a particular type interface.すべてのプラグインは、特定のタイプインターフェースから継承する1つ以上のクラスを返す登録フックを提供します。

Each registration hook must be decorated by Hatch's hook marker. For example, if you wanted to create a new kind of environment you could do:各登録フックはHatchのフックマーカーで装飾されなければなりません。例えば、新しい種類の環境を作成したい場合は、次のようにできます:

from hatchling.plugin import hookimpl

from .plugin import SpecialEnvironment


@hookimpl
def hatch_register_environment():
    return SpecialEnvironment

The hooks can return a single class or a list of classes.フックは単一のクラスまたはクラスのリストを返すことができます。

Every class must define an attribute called PLUGIN_NAME that users will select when they wish to use the plugin. So in the example above, the class might be defined like:すべてのクラスは、ユーザーがプラグインを使用したいときに選択する属性としてPLUGIN_NAMEという名前の属性を定義しなければなりません。したがって、上記の例では、クラスは次のように定義されるかもしれません:

...
class SpecialEnvironment(...):
    PLUGIN_NAME = 'special'
    ...

Project configurationプロジェクト設定

NamingNaming

It is recommended that plugin project names are prefixed with hatch-. For example, if you wanted to make a plugin that provides some functionality for a product named foo you might do:プラグインプロジェクト名にはhatch-をプレフィックスとして付けることをお勧めします。例えば、fooという名前の製品に対して何らかの機能を提供するプラグインを作成したい場合は、次のようにできます:

[project]
name = "hatch-foo"

Discovery発見

You'll need to define your project as a Python plugin for Hatch:プロジェクトをHatchのPythonプラグインとして定義する必要があります:

[project.entry-points.hatch]
foo = "pkg.hooks"

The name of the plugin should be the project name (excluding any hatch- prefix) and the path should represent the module that contains the registration hooks.プラグインの名前はプロジェクト名(hatch-プレフィックスを除く)であるべきで、パスは登録フックを含むモジュールを表す必要があります。

Classifier分類子

Add Framework :: Hatch to your project's classifiers to make it easy to search for Hatch plugins:Hatchプラグインを簡単に検索できるようにするために、プロジェクトの分類子Framework :: Hatchを追加してください:

[project]
classifiers = [
  ...
  "Framework :: Hatch",
  ...
]

Typesタイプ

HatchlingHatchling

These are all involved in building projects and therefore any defined dependencies are automatically installed in each build environment.これらはすべてプロジェクトの構築に関与しており、したがって定義された依存関係は各ビルド環境に自動的にインストールされます。

HatchHatch

These must be installed in the same environment as Hatch itself.これらはHatch自体と同じ環境にインストールする必要があります。