[英]Is there an easier way to package with Python?
I tried to package a django app today. 我今天尝试打包django应用程序。 It's a big baby, and with the setup file, I have to manually write all packages and sub packages in the 'package' parameter.
这是一个大宝贝,使用安装文件,我必须在'package'参数中手动编写所有包和子包。 Then I have to find a way to copy fixtures, htmls / Css / image files, documentations, etc.
然后我必须找到一种方法来复制灯具,htmls / Css /图像文件,文件等。
It's a terrible way to work. 这是一种可怕的工作方式。 We are computer scientists, we automatize, doing this makes no sense.
我们是计算机科学家,我们自动化,这样做毫无意义。
And what when I change my app structure ? 什么时候我改变我的应用程序结构? I have to rewrite the setup.py.
我必须重写setup.py。
Is there a better way ? 有没有更好的办法 ? Some tool to automate that ?
一些自动化的工具? I can't believe a language than value developer time like Python makes packaging such a chore.
我不敢相信一种语言,而不是像Python这样的开发人员时间,这使得包装成为一件苦差事。
I want to be able to eventually install the app using a simple pip install. 我希望能够最终使用简单的pip安装来安装应用程序。 I know about build out, but it's not much simpler, and is not pip friendly.
我知道有关构建,但它并不简单,并且不友好。
At the very least if you use setuptools
(an alternative to the stdlib's distutils
) you get an awesome function called find_packages()
which when ran from the package root returns a list of package names in dot-notation suitable for the packages
parameter. 至少如果你使用
setuptools
(stdlib的distutils
的替代品),你会得到一个名为find_packages()
的很棒的函数,当从包根运行时,会返回一个适合于packages
参数的点符号列表。
Here is an example: 这是一个例子:
# setup.py
from setuptools import find_packages, setup
setup(
#...
packages=find_packages(exclude='tests'),
#...
)
ps Packaging sucks in every language and every system. ps包装吮吸每种语言和每个系统。 It sucks no matter how you slice it.
无论你怎么切它都很糟糕。
I've been through this pain myself today. 我今天经历过这种痛苦。 I used the following, yoinked straight from Django's setup.py , which walks the app's filesystem looking for packages and data files (assuming you never mix the two):
我使用了以下内容,直接从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]])
I think the tool you are looking for is Buildout . 我认为您正在寻找的工具是Buildout 。 There lots of places where you can learn more about it, from SlideShare to Pycon videos .
从SlideShare到Pycon视频 ,您可以在很多地方了解它。
Other similar or related tools which you might want to check out include virtualenv, Fabric, and PIP . 您可能想要查看的其他类似或相关工具包括virtualenv,Fabric和PIP 。
I've been doing a bit of research myself on Django deployment methods recently. 我最近在Django部署方法上做了一些研究。
I found these two resources very useful: 我发现这两个资源非常有用:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.