Pythonでライブラリを包装してpypeに発表します。


自分で書いたpythonを包装してpypeに配布する必要があれば、他の人は直接pip installを通して対応のカバンをインストールすることができます。下記の教程を参考にしてください。
1.pypeアカウントを登録してtokenを作成する
最初に訪問するhttps://pypi.org/ そしてアカウントを登録します
アカウント設定にジャンプします。
在这里插入图片描述
API token->Add API tokenを選択します。
在这里插入图片描述
token nameを入力してScopeでEntee accountを選択します。(初めてEntee accountを選択する必要があります。)
在这里插入图片描述
その後、ローカルで.pypircファイルを修正する。
入力内容は:

[pypi]
username = __token__
password = {token}
{token}を自分のtokenに変更するだけでいいです。
2.setup.pyとsetup.cfgを作成する。
setup.cfgの内容は

[metadata]
license_files = LICENSE.txt
LICENSE.txtはlicenseファイルで、自分で編纂する必要があります。
setup.pyはルートディレクトリの下で、一例は次の通りです。

from setuptools import setup
import compileall
from os import path
#   readme  ,            
this_directory = path.abspath(path.dirname(__file__))
with open(path.join(this_directory, 'README.md'), encoding='utf-8') as f:
    long_description = f.read()

compileall.compile_dir("src")

setup(
    name='my-python',
    version='1.0.2',
    packages=['src',
              'src.main',
              'src.main.config'],
    url='https://github.com/hTangle',
    license='Apache 2.0',
    author='hTangle',
    author_email='',
    description='',
    keywords='',
    python_requires='>=3.4, <4',
    long_description=long_description,
    long_description_content_type='text/markdown',
    install_requires=['requests']
)
具体的なフィールドの意味は以下の通りです。name:パッケージ名version:バージョン番号は、次のような形でサポートされています。

1.2.0.dev1  # Development release
1.2.0a1     # Alpha Release
1.2.0b1     # Beta Release
1.2.0rc1    # Release Candidate
1.2.0       # Final Release
1.2.0.post1 # Post Release
15.10       # Date based release
23          # Serial release
description:パッケージ説明は、下図のような位置に置かれます。
在这里插入图片描述url:パッケージのリンクは、githubリンクを使用することができます。pypeは自動的に倉庫の情報を取得します。例は以下の通りです。
在这里插入图片描述author:著者license:ライセンスclassifiers:分類、例は以下の通りである。

classifiers=[
    # How mature is this project? Common values are
    #   3 - Alpha
    #   4 - Beta
    #   5 - Production/Stable
    'Development Status :: 3 - Alpha',

    # Indicate who your project is intended for
    'Intended Audience :: Developers',
    'Topic :: Software Development :: Build Tools',

    # Pick your license as you wish (should match "license" above)
    'License :: OSI Approved :: MIT License',

    # Specify the Python versions you support here. In particular, ensure
    # that you indicate whether you support Python 2, Python 3 or both.
    'Programming Language :: Python :: 2',
    'Programming Language :: Python :: 2.7',
    'Programming Language :: Python :: 3',
    'Programming Language :: Python :: 3.6',
    'Programming Language :: Python :: 3.7',
    'Programming Language :: Python :: 3.8',
    'Programming Language :: Python :: 3.9',
],
keywords:キーワードは、論文のキーワードと類似しています。project_urls:一部の項目の他のリンクの例は以下の通りである。

project_urls={
    'Documentation': 'https://packaging.python.org/tutorials/distributing-packages/',
    'Funding': 'https://donate.pypi.org',
    'Say Thanks!': 'http://saythanks.io/to/example',
    'Source': 'https://github.com/pypa/sampleproject/',
    'Tracker': 'https://github.com/pypa/sampleproject/issues',
},
packages:パッケージが必要なディレクトリは、ルートディレクトリを起点として使用できます。find_packages自動でカバンを探します。書き落としに注意してください。install_requires:パケット依存の他のパケットpython_requires:pythonのバージョン需要package_data:必要な追加のファイル、例えば、パッケージはローカルファイルに依存しています。次のように使用できます。

package_data={
    'sample': ['package_data.dat'],
},
3.包装
パッケージコマンドは

python setup.py cmd
cmdは値を取ります
bdist_wheel:create a wheel distribution
bdist_egg:create an「egg」distribution
sdist:create a source distribution(tall,zip file,etc.)
bdist:create a built(binary)distribution
bdist_dumb:create a“dumb”built distribution
bdist_rpm:create an RPM distribution
bdist_windinst:create an executable installer for MS Windows
テイクアウトはtar.gzとなります

python setup.py sdist
包装されたファイルをdistディレクトリでお願いします。
4.アップロード
まずtwineを使ってカバンを検査することができます。

twine check dist/*
出力は以下の通りです
在这里插入图片描述
アップロードコマンドを再実行

twine upload dist/*
ここでPythonでライブラリを梱包してpypeに投稿した記事について紹介します。pypeiの内容については以前の記事を検索したり、下記の関連記事を見たりしてください。これからもよろしくお願いします。