<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>toml</title>
	<atom:link href="https://techgrowup.net/tag/toml/feed/" rel="self" type="application/rss+xml" />
	<link>https://techgrowup.net</link>
	<description>エンジニアを強くする</description>
	<lastBuildDate>Thu, 12 Dec 2024 07:44:11 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0</generator>

<image>
	<url>https://techgrowup.net/wp-content/uploads/2021/05/hp-icon-150x150.png</url>
	<title>toml</title>
	<link>https://techgrowup.net</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Python開発入門38 pyproject.tomlの書き方</title>
		<link>https://techgrowup.net/python-pyproject-toml/</link>
					<comments>https://techgrowup.net/python-pyproject-toml/?noamp=mobile#respond</comments>
		
		<dc:creator><![CDATA[techgrowup]]></dc:creator>
		<pubDate>Thu, 12 Dec 2024 07:44:09 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[プログラミング]]></category>
		<category><![CDATA[pyproject]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[toml]]></category>
		<guid isPermaLink="false">https://techgrowup.net/?p=2198</guid>

					<description><![CDATA[はじめに Pythonプロジェクトをパッケージ化やビルドする際、pyproject.tomlは必須の設定ファイルです。Python 3.11以降では、このファイルが標準として採用され、プロジェクトのビルドツールや依存関係 [&#8230;]]]></description>
										<content:encoded><![CDATA[
<h1 class="wp-block-heading"><strong>はじめに</strong></h1>



<p class="wp-block-paragraph">Pythonプロジェクトをパッケージ化やビルドする際、<strong>pyproject.toml</strong>は必須の設定ファイルです。Python 3.11以降では、このファイルが標準として採用され、プロジェクトのビルドツールや依存関係を明示的に管理することが求められています。</p>



<p class="wp-block-paragraph">この記事では、pyproject.tomlの基本構造や使い方、さらに推奨されるベストプラクティスについて初心者にもわかりやすく解説します。</p>



<h2 class="wp-block-heading"><strong>pyproject.tomlとは</strong></h2>



<h3 class="wp-block-heading"><strong>概要</strong></h3>



<p class="wp-block-paragraph"><strong>pyproject.toml</strong>は、Pythonプロジェクトの<strong>ビルドツールや依存関係を記述するための設定ファイル</strong>です。このファイルは、Pythonエコシステム全体で統一された形式を提供し、プロジェクト管理を効率化します。</p>



<h3 class="wp-block-heading"><strong>pyproject.tomlの主な目的</strong></h3>



<ol class="wp-block-list">
<li><strong>ビルドツールの指定</strong><br><code>setuptools</code>や<code>poetry</code>など、プロジェクトのビルドに必要なツールを記述します。</li>



<li><strong>依存関係の管理</strong><br>プロジェクトで必要なライブラリやバージョンを明示的に記述できます。</li>



<li><strong>プロジェクト情報の提供</strong><br>パッケージの名前、バージョン、ライセンスなど、メタデータを含めることができます。</li>
</ol>



<h2 class="wp-block-heading"><strong>pyproject.tomlの基本構造</strong></h2>



<p class="wp-block-paragraph">pyproject.tomlは、以下のようなセクションで構成されています：</p>



<h3 class="wp-block-heading"><strong><code>[build-system]</code></strong></h3>



<p class="wp-block-paragraph">ビルドツールとその依存関係を指定するセクションです。</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="[build-system]
requires = [&quot;setuptools&gt;=61.0&quot;, &quot;wheel&quot;]
build-backend = &quot;setuptools.build_meta&quot;" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #D4D4D4">[build-system]</span></span>
<span class="line"><span style="color: #9CDCFE">requires</span><span style="color: #D4D4D4"> = [</span><span style="color: #CE9178">&quot;setuptools&gt;=61.0&quot;</span><span style="color: #D4D4D4">, </span><span style="color: #CE9178">&quot;wheel&quot;</span><span style="color: #D4D4D4">]</span></span>
<span class="line"><span style="color: #9CDCFE">build-backend</span><span style="color: #D4D4D4"> = </span><span style="color: #CE9178">&quot;setuptools.build_meta&quot;</span></span></code></pre></div>



<h6 class="wp-block-heading"><strong>設定項目の説明</strong></h6>



<ul class="wp-block-list">
<li><strong><code>requires</code></strong>: ビルドに必要なライブラリをリスト形式で指定します。</li>



<li><strong><code>build-backend</code></strong>: 使用するビルドバックエンドを指定します。</li>
</ul>



<h3 class="wp-block-heading"><strong><code>[tool.&lt;tool_name>]</code></strong></h3>



<p class="wp-block-paragraph">プロジェクトで使用する特定のツールの設定を記述します。例えば、<code>poetry</code>や<code>black</code>の設定を追加できます。</p>



<h6 class="wp-block-heading"><strong>例：Poetryの設定</strong></h6>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="[tool.poetry]
name = &quot;my_project&quot;
version = &quot;0.1.0&quot;
description = &quot;サンプルプロジェクト&quot;
authors = [&quot;Your Name &lt;your.email@example.com&gt;&quot;]" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #D4D4D4">[tool.poetry]</span></span>
<span class="line"><span style="color: #9CDCFE">name</span><span style="color: #D4D4D4"> = </span><span style="color: #CE9178">&quot;my_project&quot;</span></span>
<span class="line"><span style="color: #9CDCFE">version</span><span style="color: #D4D4D4"> = </span><span style="color: #CE9178">&quot;0.1.0&quot;</span></span>
<span class="line"><span style="color: #9CDCFE">description</span><span style="color: #D4D4D4"> = </span><span style="color: #CE9178">&quot;サンプルプロジェクト&quot;</span></span>
<span class="line"><span style="color: #9CDCFE">authors</span><span style="color: #D4D4D4"> = [</span><span style="color: #CE9178">&quot;Your Name &lt;your.email@example.com&gt;&quot;</span><span style="color: #D4D4D4">]</span></span></code></pre></div>



<h3 class="wp-block-heading"><strong><code>[project]</code></strong></h3>



<p class="wp-block-paragraph">Pythonプロジェクトのメタデータを記述します。これは、PEP 621によって定義された標準です。</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="[project]
name = &quot;my_project&quot;
version = &quot;0.1.0&quot;
description = &quot;サンプルプロジェクト&quot;
authors = [
    {name = &quot;Your Name&quot;, email = &quot;your.email@example.com&quot;}
]
license = {text = &quot;MIT&quot;}
dependencies = [&quot;numpy&gt;=1.21&quot;, &quot;pandas&gt;=1.3&quot;]" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #D4D4D4">[project]</span></span>
<span class="line"><span style="color: #9CDCFE">name</span><span style="color: #D4D4D4"> = </span><span style="color: #CE9178">&quot;my_project&quot;</span></span>
<span class="line"><span style="color: #9CDCFE">version</span><span style="color: #D4D4D4"> = </span><span style="color: #CE9178">&quot;0.1.0&quot;</span></span>
<span class="line"><span style="color: #9CDCFE">description</span><span style="color: #D4D4D4"> = </span><span style="color: #CE9178">&quot;サンプルプロジェクト&quot;</span></span>
<span class="line"><span style="color: #9CDCFE">authors</span><span style="color: #D4D4D4"> = [</span></span>
<span class="line"><span style="color: #D4D4D4">    {</span><span style="color: #9CDCFE">name</span><span style="color: #D4D4D4"> = </span><span style="color: #CE9178">&quot;Your Name&quot;</span><span style="color: #D4D4D4">, </span><span style="color: #9CDCFE">email</span><span style="color: #D4D4D4"> = </span><span style="color: #CE9178">&quot;your.email@example.com&quot;</span><span style="color: #D4D4D4">}</span></span>
<span class="line"><span style="color: #D4D4D4">]</span></span>
<span class="line"><span style="color: #9CDCFE">license</span><span style="color: #D4D4D4"> = {</span><span style="color: #9CDCFE">text</span><span style="color: #D4D4D4"> = </span><span style="color: #CE9178">&quot;MIT&quot;</span><span style="color: #D4D4D4">}</span></span>
<span class="line"><span style="color: #9CDCFE">dependencies</span><span style="color: #D4D4D4"> = [</span><span style="color: #CE9178">&quot;numpy&gt;=1.21&quot;</span><span style="color: #D4D4D4">, </span><span style="color: #CE9178">&quot;pandas&gt;=1.3&quot;</span><span style="color: #D4D4D4">]</span></span></code></pre></div>



<h6 class="wp-block-heading"><strong>設定項目の説明</strong></h6>



<ul class="wp-block-list">
<li><strong><code>name</code></strong>: プロジェクト名。</li>



<li><strong><code>version</code></strong>: プロジェクトのバージョン。</li>



<li><strong><code>description</code></strong>: プロジェクトの説明文。</li>



<li><strong><code>authors</code></strong>: 作者情報。辞書形式で記述します。</li>



<li><strong><code>license</code></strong>: ライセンス情報。</li>



<li><strong><code>dependencies</code></strong>: プロジェクトで使用する依存ライブラリ。</li>
</ul>



<h2 class="wp-block-heading"><strong>pyproject.tomlの応用例</strong></h2>



<h3 class="wp-block-heading"><strong>プロジェクトに依存関係を追加する</strong></h3>



<p class="wp-block-paragraph">以下の例では、<code>numpy</code>と<code>pandas</code>を指定しています：</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="[project]
dependencies = [
    &quot;numpy&gt;=1.21&quot;,
    &quot;pandas&gt;=1.3&quot;,
]" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #D4D4D4">[project]</span></span>
<span class="line"><span style="color: #9CDCFE">dependencies</span><span style="color: #D4D4D4"> = [</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #CE9178">&quot;numpy&gt;=1.21&quot;</span><span style="color: #D4D4D4">,</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #CE9178">&quot;pandas&gt;=1.3&quot;</span><span style="color: #D4D4D4">,</span></span>
<span class="line"><span style="color: #D4D4D4">]</span></span></code></pre></div>



<h3 class="wp-block-heading"><strong>開発環境用の依存関係</strong></h3>



<p class="wp-block-paragraph">開発時にのみ必要なライブラリを指定します。例えば、<code>pytest</code>を追加する場合：</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="[project.optional-dependencies]
dev = [&quot;pytest&gt;=6.0&quot;]" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #D4D4D4">[project.optional-dependencies]</span></span>
<span class="line"><span style="color: #9CDCFE">dev</span><span style="color: #D4D4D4"> = [</span><span style="color: #CE9178">&quot;pytest&gt;=6.0&quot;</span><span style="color: #D4D4D4">]</span></span></code></pre></div>



<h3 class="wp-block-heading"><strong>3. フォーマッタやリンターの設定</strong></h3>



<p class="wp-block-paragraph">例えば、<code>black</code>の設定を追加する場合：</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#1E1E1E"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" data-code="[tool.black]
line-length = 88
target-version = [&quot;py311&quot;]" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"><span style="color: #D4D4D4">[tool.black]</span></span>
<span class="line"><span style="color: #9CDCFE">line-length</span><span style="color: #D4D4D4"> = </span><span style="color: #B5CEA8">88</span></span>
<span class="line"><span style="color: #9CDCFE">target-version</span><span style="color: #D4D4D4"> = [</span><span style="color: #CE9178">&quot;py311&quot;</span><span style="color: #D4D4D4">]</span></span></code></pre></div>



<h2 class="wp-block-heading"><strong>pyproject.tomlを使う際の注意点</strong></h2>



<ol class="wp-block-list">
<li><strong>PEP規格を確認</strong><br>PEP 621やPEP 517に準拠して記述することで、互換性を保つことが重要です。</li>



<li><strong>正しい構文を使用</strong><br>TOML形式では、文字列は二重引用符で囲む必要があります。</li>



<li><strong>バージョン管理の徹底</strong><br><code>requires</code>や<code>dependencies</code>で明示的にバージョンを指定すると、依存関係の競合を防げます。</li>
</ol>



<h2 class="wp-block-heading"><strong>pyproject.tomlを活用したプロジェクト管理のベストプラクティス</strong></h2>



<ol class="wp-block-list">
<li><strong>明確な依存関係の定義</strong>
<ul class="wp-block-list">
<li>すべての依存ライブラリを明確に記述し、不要なライブラリを削除する習慣をつけましょう。</li>
</ul>
</li>



<li><strong>環境ごとに設定を分ける</strong>
<ul class="wp-block-list">
<li>開発、テスト、本番環境ごとに<code>optional-dependencies</code>を活用して設定を分離すると便利です。</li>
</ul>
</li>



<li><strong>ドキュメントを添える</strong>
<ul class="wp-block-list">
<li>プロジェクトの<code>README</code>やドキュメントで<code>pyproject.toml</code>の役割や設定方法を説明することで、チーム内での理解が深まります。</li>
</ul>
</li>
</ol>



<h2 class="wp-block-heading"><strong>まとめ</strong></h2>



<p class="wp-block-paragraph">pyproject.tomlは、Pythonプロジェクトを効率的に管理するための強力なツールです。この記事で紹介した基本構造や応用例を活用し、プロジェクトの設定を明確かつ簡潔に保ちましょう。また、PEP規格に従った記述を心がけることで、Pythonエコシステム全体との互換性が向上します。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://techgrowup.net/python-pyproject-toml/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Disk: Enhanced  を使用したページ キャッシュ

Served from: techgrowup.net @ 2026-06-22 17:22:24 by W3 Total Cache
-->