[英]Is there an easier way to package with Python?
我今天尝试打包django应用程序。 这是一个大宝贝,使用安装文件,我必须在'package'参数中手动编写所有包和子包。 然后我必须找到一种方法来复制灯具,htmls / Css /图像文件,文件等。
这是一种可怕的工作方式。 我们是计算机科学家,我们自动化,这样做毫无意义。
什么时候我改变我的应用程序结构? 我必须重写setup.py。
有没有更好的办法 ? 一些自动化的工具? 我不敢相信一种语言,而不是像Python这样的开发人员时间,这使得包装成为一件苦差事。
我希望能够最终使用简单的pip安装来安装应用程序。 我知道有关构建,但它并不简单,并且不友好。
至少如果你使用setuptools
(stdlib的distutils
的替代品),你会得到一个名为find_packages()
的很棒的函数,当从包根运行时,会返回一个适合于packages
参数的点符号列表。
这是一个例子:
# setup.py
from setuptools import find_packages, setup
setup(
#...
packages=find_packages(exclude='tests'),
#...
)
ps包装吮吸每种语言和每个系统。 无论你怎么切它都很糟糕。
我今天经历过这种痛苦。 我使用了以下内容,直接从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]])
我认为您正在寻找的工具是Buildout 。 从SlideShare到Pycon视频 ,您可以在很多地方了解它。
您可能想要查看的其他类似或相关工具包括virtualenv,Fabric和PIP 。
我最近在Django部署方法上做了一些研究。
我发现这两个资源非常有用:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.