python代码打包dist并发送到pypi网站的方法

1、编写setup


    
  
  1. #coding=utf-8
  2. import codecs
  3. import os
  4. import sys
  5. try:
  6. from setuptools import setup,find_packages
  7. except:
  8. from distutils.core import setup
  9. '''import the setup lib'''
  10. '''
  11. 定义一个read方法,用来读取目录下的长描述
  12. 我们一般是将README文件中的内容读取出来作为长描述,这个会在PyPI中你这个包的页面上展现出来,
  13. 你也可以不用这个方法,自己手动写内容即可,
  14. PyPI上支持.rst格式的文件。暂不支持.md格式的文件, <BR>.rst文件PyPI会自动把它转为HTML形式显示在你包的信息页面上。
  15. '''
  16. def read(fname):
  17. return codecs.open(os.path.join(os.path.dirname(__file__), fname)).read()
  18. NAME = "FriedRing"
  19. '''
  20. 名字,一般放你包的名字即可
  21. '''
  22. PACKAGES = find_packages(include=[
  23. "FriedRing", "FriedRing.*"
  24. ])
  25. '''
  26. 包含的包,可以多个,这是一个列表
  27. '''
  28. DESCRIPTION = "this is a FriedRing package for get http request and response."
  29. '''
  30. 关于这个包的描述
  31. '''
  32. LONG_DESCRIPTION = read("README.md")
  33. '''
  34. 参见read方法说明
  35. '''
  36. KEYWORDS = "FriedRing python package"
  37. '''
  38. 关于当前包的一些关键字,方便PyPI进行分类。
  39. '''
  40. AUTHOR = "CrissChan"
  41. AUTHOR_EMAIL = "can101208@gmail.com"
  42. '''
  43. 作者的邮件地址
  44. '''
  45. URL = "http://blog.csdn.net/crisschan"
  46. '''
  47. 你这个包的项目地址,如果有,给一个吧,没有你直接填写在PyPI你这个包的地址也是可以的
  48. '''
  49. VERSION = "1.0.8"
  50. '''
  51. 当前包的版本,这个按你自己需要的版本控制方式来
  52. '''
  53. LICENSE = "MIT"
  54. '''
  55. 授权方式,我喜欢的是MIT的方式,你可以换成其他方式
  56. '''
  57. REQUIREMENTS = [i.strip() for i in open("requirement.txt").readlines()]
  58. '''
  59. this grabs the requirements from requirements.txt
  60. '''
  61. setup(
  62. name = NAME,
  63. version = VERSION,
  64. description = DESCRIPTION,
  65. long_description = LONG_DESCRIPTION,
  66. install_requires=REQUIREMENTS,
  67. classifiers=[
  68. "License :: OSI Approved :: MIT License",
  69. "Development Status :: 5 - Production/Stable",
  70. "Environment :: Console",
  71. "Environment :: Console :: Curses",
  72. "Operating System :: MacOS :: MacOS X",
  73. "Operating System :: POSIX",
  74. "Programming Language :: Python",
  75. "Programming Language :: Python :: 2.7",
  76. "Programming Language :: Python :: Implementation :: CPython",
  77. "Programming Language :: Python :: Implementation :: PyPy",
  78. "Topic :: Internet",
  79. "Topic :: Internet :: WWW/HTTP",
  80. "Topic :: Software Development :: Testing"
  81. ],
  82. keywords = KEYWORDS,
  83. author = AUTHOR,
  84. author_email = AUTHOR_EMAIL,
  85. url = URL,
  86. license = LICENSE,
  87. packages = PACKAGES,
  88. include_package_data=True,
  89. zip_safe=True,
  90. entry_points={
  91. 'console_scripts': [
  92. "fr = FriedRing.fr:main"
  93. ]
  94. },
  95. # scripts=["scripts/test.py"],scripts表示将该文件放到 Python的Scripts目录下,可以直接用
  96. )
  97. ## 把上面的变量填入了一个setup()中即可。


2 SHELL进入项目目录
   
 

python setup.py sdist# 产生压缩包
   
 

python setup.py register sdist upload

上传到pypi