python packaging quickstart

https://the-hitchhikers-guide-to-packaging.readthedocs.io/en/latest/index.html

1.項目結構
一個小的python工程包含兩個文件.setup.py文件描述了項目的元信息,.py文件則則源代碼.
在這個示例中,我們將增加__init__.py文件,預示着這個工程將來會有很多模塊.
創建README.txt描述整個工程的概況
創建LICENSE.txt描述聲明

2.描述項目
setup.py是整個項目的核心,有三個字段來描述name,version,packages.如果想在pypi上發佈,name必須是唯一的.packages描述源碼在工程的哪個地方.

from distutils.core import setup

setup(
name=‘TowelStuff’,
version=‘0.1dev’,
packages=[‘towelstuff’,],
)

3.創建第一個發佈版本
python setup.py sdist
將在setup.py的同級目錄下創建一個dist文件夾,裏面的TowelStuff-0.1.tar.gz文件包含了所有的源代碼.
默認,沒有包含所有的文件,只包含了:
1.python源代碼
2.c源代碼
scripts identified by the scripts option
anything that looks like a test script: test/test*.py
Top level files named: README.txt, README, setup.py, or setup.cfg

有兩種方法包含額外的文件:
Use a package which extends Distutils with more functionality. Setuptools and Distribute allow you to include all files checked into your version control system.
Write a top-level MANIFEST.in file. This is a template file which specifies which files (and file patterns) should be included. (TO-DO: link to a MANIFEST.in document)

當使用sdist命令,MANIFEST將會生成

4.在pypi上註冊

5.上傳

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章