星期二, 十一月 13, 2007

python distutils 调整目录结构后

项目自动化中谈到对整个目录结构进行调整以利于测试和项目自动化构建,则相应的,distutils 的 setup.py 也需要相应的进行调整。

现在以完成部分的目录结构是这样的:
trunk/
ChangeLog
lib/
tree.py
LICENSE
MANIFEST.in
README
setup.py
test/
caxes/
__init__.py
support.py
test_support.py
test_tree.py
test_tree_complex.py
test_tree.bk
则调整后的 setup.py 为:
#!/usr/bin/python
# -*- encoding: utf-8 -*-

__author__ = "Roc Zhou #周鹏"
__date__ = "13 November 2007"
__version__ = "0.2"
__license__ = "GPL v2.0"

from distutils.core import setup
from distutils import sysconfig

lib_prefix = sysconfig.get_python_lib()

setup(
name = 'caxes',
version = '0.2',
description = """
Some new Python data types such as Tree,
and configuration sharing mechanism implementation.
""",
long_description = """
Some new Python data structure,
can be afforded as APIs for new ways of configuration,
and configuration sharing mechanism implementation.

It's a subproject of uLFS.

uLFS means "Your Manageable, Automatable and Templated Reusable Linux From Scratch",
it's a set of tools to build your own customed Linux distribution with
more managability than raw LFS(Linux From Scratch). Include source package
manager, file system backup and realtime mirror apps, and some assistant data
structure such as Tree writen in Python, etc...
""",
author = "Roc Zhou",
author_email = 'chowroc.z@gmail.com',
platforms = "Platform Independent",
license = "GPL v2.0",
url = "http://crablfs.sourceforge.net",
download_url = "http://sourceforge.net/projects/crablfs",
classifiers = [
"Development Status :: 4 - Beta",
"Environment :: Console",
"Intended Audience :: Developers",
"Intended Audience :: System Administrators",
"License :: OSI Approved :: GNU General Public License (GPL)",
"Natural Language :: English",
"Natural Language :: Chinese (Simplified)",
"Operating System :: POSIX",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python",
"Topic :: Software Development :: Libraries :: Python Modules"
],
py_modules = ["tree"],
package_dir = {"" : "lib", "caxes" : "lib/caxes"},
# data_files = [("%s/test" % lib_prefix, ["test/test_tree*.py", "test/support.py"])],
# data_files = [("%s/test" % lib_prefix, ["test/*.py"]), ("%s/test/caxes" % lib_prefix, ["test/caxes/*.py"])],
data_files = [("%s/test" % lib_prefix, ["test/*.py", "test/caxes"])],
# packages = ['caxes']
)
这里先说明一下 py_modules 和 package_dir 的调整。

之前的定义为:
py_modules = ["tree"]
package_dir = {"caxes" : "lib"}
因为目录结构为:
trunk/
tree.py
lib/
...
但当目录结构调整后,会提示找不到模块 tree 的文件 tree.py,因为这个文件已经不再 trunk 的根目录下了,而是移到了 lib/,此时应该调整 package_dir,增加 "" : "lib"。而原来的 lib/ 变成了 lib/caxes,所以 package_dir 也应该相应变动。

在下面定义 data_files,保证 test/test_tree*.py 被安装到 /usr/lib/python2.4/site-packages/test/,而 test/caxes/ 被拷贝成 /usr/lib/python2.4/site-packages/caxes/,忽略掉 *.bk 文件。此时必须记住要调整 trunk/ 下的 MANIFEST.in 文件:
include *.py
include test/*.py
recursive-include test/caxes *
include README
include ChangeLog
include LICENSE
注意 recursive-include 一行,否真 test/caxes 目录不会被拷贝。

有一点比较奇怪的是,当我使用:
data_files = [("%s/test" % lib_prefix, ["test/test_tree*.py", "test/caxes"])]
却提示找不到文件 test/test_tree*.py。这是为什么呢?

__package__ = "caxes"
__revision__ = [258:259]

没有评论: