Skip to content

Introductionはじめに


Setupセットアップ

Projects can be set up for use by Hatch using the new command.プロジェクトは、new コマンドを使用してHatchによって使用するために設定できます。

New project新しいプロジェクト

Let's say you want to create a project named Hatch Demo. You would run:Hatch Demoという名前のプロジェクトを作成したいとしましょう。次のコマンドを実行します:

hatch new "Hatch Demo"

This would create the following structure in your current working directory:これにより、現在の作業ディレクトリに次の構造が作成されます:

hatch-demo
├── src
│   └── hatch_demo
│       ├── __about__.py
│       └── __init__.py
├── tests
│   └── __init__.py
├── LICENSE.txt
├── README.md
└── pyproject.toml

Tipヒント

There are many ways to customize project generation.プロジェクト生成をカスタマイズする方法はたくさんあります。

Existing project既存のプロジェクト

To initialize an existing project, enter the directory containing the project and run the following:既存のプロジェクトを初期化するには、プロジェクトを含むディレクトリに移動し、次のコマンドを実行します:

hatch new --init

If your project has a setup.py file the command will automatically migrate setuptools configuration for you. Otherwise, this will interactively guide you through the setup process.プロジェクトにsetup.pyファイルがある場合、コマンドは自動的にsetuptoolsの設定を移行します。そうでない場合は、セットアッププロセスを対話形式で案内します。

Project metadataプロジェクトメタデータ

Next you'll want to define more of your project's metadata located in the pyproject.toml file. You can specify things like its license, the supported versions of Python, and URLs referring to various parts of your project, like documentation.次に、pyproject.tomlファイルにあるプロジェクトのメタデータをさらに定義したいと思います。ライセンスサポートされているPythonのバージョン、およびドキュメントなど、プロジェクトのさまざまな部分を参照するURLのようなものを指定できます。

Dependencies依存関係

The last step of the setup process is to define any dependencies that you'd like your project to begin with.セットアッププロセスの最後のステップは、プロジェクトが開始する際に必要な依存関係を定義することです。

Configuration設定

All project-specific configuration recognized by Hatch can be defined in either the pyproject.toml file, or a file named hatch.toml where options are not contained within the tool.hatch table:Hatchによって認識されるすべてのプロジェクト固有の設定は、pyproject.tomlファイルまたはtool.hatchテーブルに含まれないオプションを持つhatch.tomlという名前のファイルのいずれかで定義できます:

[tool.hatch]
option = "..."

[tool.hatch.table1]
option = "..."

[tool.hatch.table2]
option = "..."
option = "..."

[table1]
option = "..."

[table2]
option = "..."

Top level keys in the latter file take precedence when defined in both.後者のファイルで定義されたトップレベルキーは、両方で定義されている場合に優先されます。

Tipヒント

If you want to make your file more compact, you can use dotted keys, turning the above example into:ファイルをよりコンパクトにしたい場合は、ドット付きキーを使用することで、上記の例を次のように変えることができます:

[tool.hatch]
option = "..."
table1.option = "..."
table2.option = "..."
option = "..."
table1.option = "..."
table2.option = "..."