分享

[Python模块]SetupTools工具的使用心得(一)

 sven_ 2013-07-22

早就在学习 django 的教程时知道了 SetupTools 这个工具了(因为在安装时还报了错,因为setuptools的版本问题),不过一直没有机会学习和使用。终于在试着发布 EasyWizard 时用了一下。不过在使用的过程中遇到一些问题,最近也解决了。

EasyWizard 中使用的setup.py脚本如下:

import ez_setup # From http://peak./DevCenter/setuptools
ez_setup.use_setuptools()

from SetupTools import setup, find_packages

setup(
    name = "EasyWizard",
    version = "0.1",
    url = ‘http://wiki./moin.cgi/EasyWizard/’,
    author = ‘limodou’,
    author_email = ‘limodou@gmail.com’,
    description = ‘A easy way to create Wizard in wxPython‘,
    license = ‘GPL’,
    packages = find_packages(),
    package_data ={
        ‘test’: ['*.jpg'],
    },
    scripts = ['EasyAdmin.py'],
)

前两行

import ez_setup # From http://peak./DevCenter/setuptools
ez_setup.use_setuptools()

是为了当setuptools不存在时,有了这两个会自动从网上安装所需要的setuptools包。

后面就是安装脚本了。大部分没什么解释的。其中

packages = find_packages(),

会自动查找当前目录下的所有模块。因此只要把setup.py放在你要打包的模块之上即可由find_packages自动来查找要打包的模块。package_data是用来包括应用所用到的其它数据文件。scripts是可以将脚本拷贝到 Python 的Scripts目录下。因此在你安装 EasyWizard 时,EasyAdmin.py 会自动安装到 Python/Scripts 目录下,因此就可以方便地执行 EasyAdmin.py 了。

那么我遇到什么问题呢?就是某些不在模块中的文件,还有上面*.jpg文件并未打进包里去,试来试去都不得其解。可是我在 SetupTools 文档中看到这么一句话:

setuptools enhances the distutils’ default algorithm for source file selection, so that all files managed by CVS or SubVersion in your project tree are included in any source distribution you build. This is a big improvement over having to manually write a MANIFEST.in file and try to keep it in sync with your project. So, if you are using CVS or SubVersion, and your source distributions only need to include files that you’re tracking in revision control, don’t create a a MANIFEST.in file for your project. (And, if you already have one, you might consider deleting it the next time you would otherwise have to change it.)

于是我启动了SubVersion来将我的EasyWizard设置进去(以前没加进去)。这下都解决了,我想要的文件都加进去了,而且连ez_setup.py,README.txt也自动加到包里去了。原来如此。

只不过现在安装时会生成一个.egg文件(就是一个压缩文件),而不是生成一个目录,我现在还知道如何改掉。

不过使用这个工具的确有趣。与之相配套的还有一个easy_install,它可以自动下载包。不过这个SetupTools也可以设置相关的包和版本,如果没有安装的话会自动下载并安装。


    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多