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.上傳