How to write setup.py
-
创建一个父目录
mkdir -pv /opt/django-todo
-
copy 刚才新增的 application
todo
到 该目录下cp -r todo /opt/django-todo/
一般开发完成application之后,在
todo
下面会生成__pycache__
和migrations
, 一般会保留migrations
作为应用的初始化; 或者删除不打包到Python package中,安装应用之后可以使用python manage.py makemigrations todo
和python manage.py migrate todo
来初始化;__pycache__
可以删除不做打包 -
新增README.MD 和 setup.py
README.MD 作为项目的详细说明,这里省略,详细可以参考:todo README
setup.py 是打包安装脚本,详细脚本如下:
import os
from setuptools import find_packages, setup
with open(os.path.join(os.path.dirname(__file__), 'README.rst')) as readme:
README = readme.read()
# 使 setup.py 能在任何地方运行
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))
setup(
name='colinws-todo',
version='0.3',
# packages=find_packages(),
packages=['todo'],
include_package_data=True,
license='MIT License',
description='A simple Django Todo List application',
long_description=README,
url='https://blog.colinspace.com/',
author='Colin.Liu',
author_email='colinservice@126.com',
platforms = 'Linux,Unix',
keywords = 'Colin,colinws,todo, todo list, django',
classifiers=[
'Environment :: Web Environment',
'Framework :: Django',
'Framework :: Django :: 1.11',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
],
)
-
编译打包、安装、注册、上传
python setup.py sdist
python setup.py register
python setup.py upload