4

我今天尝试打包一个 django 应用程序。真是个大宝贝,加上安装文件,我得手动把所有的包和子包都写在'package'参数里。然后我必须找到一种方法来复制夹具、htmls/css/图像文件、文档等。

这是一种糟糕的工作方式。我们是计算机科学家,我们自动化,这样做毫无意义。

当我改变我的应用程序结构时怎么办?我必须重写 setup.py。

有没有更好的办法 ?一些自动化的工具?我无法相信像 Python 这样重视开发人员时间的语言会使打包成为一件苦差事。

我希望最终能够使用简单的 pip 安装来安装应用程序。我知道构建,但它并不简单,而且对 pip 不友好。

4

4 回答 4

5

至少如果你使用setuptools(stdlib 的替代品distutils)你会得到一个很棒的函数find_packages(),当从包根运行时,它会返回一个适合packages参数的点符号的包名称列表。

这是一个例子:

# setup.py

from setuptools import find_packages, setup

setup(
    #...
    packages=find_packages(exclude='tests'),
    #...
)

ps 包装在每一种语言和每一种系统中都很糟糕。不管你怎么切,它都糟透了。

于 2010-10-07T21:02:06.840 回答
1

今天我自己也经历过这种痛苦。我使用了以下内容,直接来自Django 的 setup.py,它会遍历应用程序的文件系统来查找包和数据文件(假设您从不将两者混合):

import os
from distutils.command.install import INSTALL_SCHEMES

def fullsplit(path, result=None):
    """
    Split a pathname into components (the opposite of os.path.join) in a
    platform-neutral way.
    """
    if result is None:
        result = []
    head, tail = os.path.split(path)
    if head == '':
        return [tail] + result
    if head == path:
        return result
    return fullsplit(head, [tail] + result)

# Tell distutils to put the data_files in platform-specific installation
# locations. See here for an explanation:
# http://groups.google.com/group/comp.lang.python/browse_thread/thread/35ec7b2fed36eaec/2105ee4d9e8042cb
for scheme in INSTALL_SCHEMES.values():
    scheme['data'] = scheme['purelib']

# Compile the list of packages available, because distutils doesn't have
# an easy way to do this.
packages, data_files = [], []
root_dir = os.path.dirname(__file__)
if root_dir != '':
    os.chdir(root_dir)
myapp_dir = 'myapp'

for dirpath, dirnames, filenames in os.walk(myapp_dir):
    # Ignore dirnames that start with '.'
    for i, dirname in enumerate(dirnames):
        if dirname.startswith('.'): del dirnames[i]
    if '__init__.py' in filenames:
        packages.append('.'.join(fullsplit(dirpath)))
    elif filenames:
        data_files.append([dirpath, [os.path.join(dirpath, f) for f in filenames]])
于 2010-11-25T19:36:55.650 回答
0

我认为您正在寻找的工具是Buildout从SlideSharePycon 视频,您可以在很多地方了解更多信息。

您可能想要查看的其他类似或相关工具包括virtualenv、Fabric 和 PIP

于 2010-10-08T03:34:43.590 回答
-1

我最近一直在对 Django 部署方法进行一些研究。

我发现这两个资源非常有用:

于 2010-11-25T19:57:03.647 回答