2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

`poetry build`コマンドで生成されるパッケージには、Pythonバージョンとライセンスに関するclassifiersが自動で生成される

Last updated at Posted at 2023-05-01

環境

  • Python 3.11.2
  • poetry 1.4.2

classifiersとは

PyPIに公開されているパッケージを分類するものです。

Each entry is a string giving a single classification value for the distribution. Classifiers are described in PEP 301, and the Python Package Index publishes a dynamic list of currently defined classifiers.

https://packaging.python.org/en/latest/specifications/core-metadata/#classifier-multiple-use 引用

以下は、PyPIで定義されているclassifiersの一覧です。

Poetryでは、pyproject.toml[tool.poetry]配下classifiersキーで指定できます。

poetry buildコマンド実行時に生成されるclassifiers

Pythonのバージョン情報とラインセンスに関するclassifiersは、pyproject.tomlに記載されているpython requirementとライセンス情報から生成されます。

Note that Python classifiers are still automatically added for you and are determined by your python requirement.
The license property will also set the License classifier automatically.

https://python-poetry.org/docs/pyproject#classifiers 引用

実際に確認してみましょう。
以下のpyproject.tomlを利用してpoetry buildコマンドを実行します。

pyproject.toml
[tool.poetry]
name = "yuji38kwmt-cli"
version = "0.1.0"
authors = ["yuji38kwmt"]
license = "MIT"
classifiers = [
]

packages = [
    { include = "yuji38kwmt_cli" }
]

[tool.poetry.dependencies]
python = "^3.9"
requests = "*"


[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
$ tree
.
├── pyproject.toml
└── yuji38kwmt_cli
    └── __init__.py
$ poetry build
Building yuji38kwmt-cli (0.1.0)
  - Building sdist
  - Built yuji38kwmt_cli-0.1.0.tar.gz
  - Building wheel
  - Built yuji38kwmt_cli-0.1.0-py3-none-any.whl

生成されたwheelファイルの中のMETADATAを表示します。

$ unzip -c  dist/yuji38kwmt_cli-0.1.0-py3-none-any.whl yuji38kwmt_cli-0.1.0.dist-info/METADATA | cat
Archive:  dist/yuji38kwmt_cli-0.1.0-py3-none-any.whl
  inflating: yuji38kwmt_cli-0.1.0.dist-info/METADATA  
Metadata-Version: 2.1
Name: yuji38kwmt-cli
Version: 0.1.0
Summary: yuji38kwmt's CLI
License: MIT
Author: yuji38kwmt
Requires-Python: >=3.9,<4.0
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Requires-Dist: requests

以下のclassifiersが生成されました。

Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11

pyproject.tomlのclassifiersに同じ内容を記載した場合

自動で生成されるclassifierと同じ内容を、pyproject.tomlに記載しても問題はありません。

pyproject.toml
[tool.poetry]
classifiers = [
    "License :: OSI Approved :: MIT License",
    "Programming Language :: Python :: 3",
    "Programming Language :: Python :: 3.9",
    "Programming Language :: Python :: 3.10",
    "Programming Language :: Python :: 3.11"
]

poetry buildは成功します。
ただし、wheelファイル内のMETADATAにはPythonのバージョン情報が重複して出力されます。1
そして、なぜかライセンス情報は重複していません。

$ poetry build --quiet
$ unzip -c  dist/yuji38kwmt_cli-0.1.0-py3-none-any.whl yuji38kwmt_cli-0.1.0.dist-info/METADATA | cat
Archive:  dist/yuji38kwmt_cli-0.1.0-py3-none-any.whl
  inflating: yuji38kwmt_cli-0.1.0.dist-info/METADATA  
Metadata-Version: 2.1
Name: yuji38kwmt-cli
Version: 0.1.0
Summary: yuji38kwmt's CLI
License: MIT
Author: yuji38kwmt
Requires-Python: >=3.9,<4.0
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.9
Requires-Dist: requests

classifiersが重複しているパッケージをPyPIへpublishしても、問題ありません。
たとえば、annofabcli v1.75.2(社内ツール)のMETADATAのclassifiersは、Pythonのバージョン情報が重複しています。

Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Topic :: Utilities

このようなパッケージでも、PyPIの画面上ではclassifiersは重複して表示されません。

image.png

補足: poetryでclassifiersを生成しているコード

poetryは、以下のコードでclassifiersを生成しています。

Pythonの利用可能なバージョンは、以下のコードで定義されています。

したがって、classifiersに新しいPythonバージョンを指定したい場合は、新しいPythonバージョンに対応したPoetryを利用して、poetry buildコマンドを実行する必要があります。

  1. issueで報告しました。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?