Browse files

patterns/distribute.rst done.

  • Loading branch information...
1 parent edd0130 commit 62c571f263391a3ede9b789f68781c208f89f13d @dormouse committed Apr 19, 2012
Showing with 64 additions and 96 deletions.
  1. +64 −96 FlaskDocsZhCn0.8/patterns/distribute.rst
@@ -1,62 +1,47 @@
.. _distribute-deployment:
-Deploying with Distribute
+使用 Distribute 部署
-`distribute`_, formerly setuptools, is an extension library that is
-commonly used to (like the name says) distribute Python libraries and
-extensions. It extends distutils, a basic module installation system
-shipped with Python to also support various more complex constructs that
-make larger applications easier to distribute:
-- **support for dependencies**: a library or application can declare a
- list of other libraries it depends on which will be installed
- automatically for you.
-- **package registry**: setuptools registers your package with your
- Python installation. This makes it possible to query information
- provided by one package from another package. The best known feature of
- this system is the entry point support which allows one package to
- declare an "entry point" another package can hook into to extend the
- other package.
-- **installation manager**: `easy_install`, which comes with distribute
- can install other libraries for you. You can also use `pip`_ which
- sooner or later will replace `easy_install` which does more than just
- installing packages for you.
-Flask itself, and all the libraries you can find on the cheeseshop
-are distributed with either distribute, the older setuptools or distutils.
-In this case we assume your application is called
-`` and you are not using a module, but a :ref:`package
-<larger-applications>`. Distributing resources with standard modules is
-not supported by `distribute`_ so we will not bother with it. If you have
-not yet converted your application into a package, head over to the
-:ref:`larger-applications` pattern to see how this can be done.
-A working deployment with distribute is the first step into more complex
-and more automated deployment scenarios. If you want to fully automate
-the process, also read the :ref:`fabric-deployment` chapter.
-Basic Setup Script
+`distribute`_ 的前身是 setuptools ,它是一个扩展库,通常用于分发 Python 库和
+扩展。它的英文名称的就是“分发”的意思。它扩展了 Python 自带的一个基础模块安装
+系统 distutils ,支持多种更复杂的结构,方便了大型应用的分发部署。它的主要特色:
+- **支持依赖** :一个库或者应用可以声明其所依赖的其他库的列表。依赖库将被自动
+ 安装。
+- **包注册** :可以在安装过程中注册包,这样就可以通过一个包查询其他包的信息。
+ 这套系统最有名的功能是“切入点”,即一个包可以定义一个入口,以便于其他包挂接,
+ 用以扩展包。
+- **安装管理** : distribute 中的 `easy_install` 可以为你安装其他库。你也可以
+ 使用早晚会替代 `easy_install` 的 `pip`_ ,它除了安装包还可以做更多的事。
+Flask 本身,以及其他所有在 cheeseshop 中可以找到的库要么是用 distribute 分发的,
+要么是用老的 setuptools 或 distutils 分发的。
+在这里我们假设你的应用名称是 `` ,且没有使用模块,而是一个
+:ref:`包 <larger-applications>` 。 `distribute`_ 不支持分发标准模块,因此我们不
+讨论模块的问题。关于如何把模块转换为包的信息参见 :ref:`larger-applications`
+使用 distribute 将使发布更复杂,也更加自动化。如果你想要完全自动化处理,请同时
+阅读 :ref:`fabric-deployment` 一节。
-Because you have Flask running, you either have setuptools or distribute
-available on your system anyways. If you do not, fear not, there is a
-script to install it for you: ``_. Just download and
-run with your Python interpreter.
+因为你已经安装了 Flask ,所以你应当已经安装了 setuptools 或 distribute 。如果
+没有安装,不用怕,有一个 ``_ 脚本可以帮助你安装。只要下载这个
+脚本,并在你的 Python 解释器中运行就可以了。
-Standard disclaimer applies: :ref:`you better use a virtualenv
+标准声明: :ref:`最好使用 virtualenv <virtualenv>` 。
-Your setup code always goes into a file named `` next to your
-application. The name of the file is only convention, but because
-everybody will look for a file with that name, you better not change it.
+你的设置代码应用放在 `` 文件中,这个文件应当位于应用旁边。这个文件名只是
-Yes, even if you are using `distribute`, you are importing from a package
-called `setuptools`. `distribute` is fully backwards compatible with
-`setuptools`, so it also uses the same import name.
+是的,即使你使用 `distribute` ,你导入的包也是 `setuptools` 。 `distribute` 完全
+向后兼容于 `setuptools` ,因此它使用相同的导入名称。
-A basic `` file for a Flask application looks like this::
+Flask 应用的基础 `` 文件示例如下::
from setuptools import setup
@@ -70,9 +55,8 @@ A basic `` file for a Flask application looks like this::
-Please keep in mind that you have to list subpackages explicitly. If you
-want distribute to lookup the packages for you automatically, you can use
-the `find_packages` function::
+请记住,你必须显式的列出子包。如果你要 distribute 自动为你搜索包,你可以使用
+`find_packages` 函数::
from setuptools import setup, find_packages
@@ -81,84 +65,68 @@ the `find_packages` function::
-Most parameters to the `setup` function should be self explanatory,
-`include_package_data` and `zip_safe` might not be.
-`include_package_data` tells distribute to look for a `` file
-and install all the entries that match as package data. We will use this
-to distribute the static files and templates along with the Python module
-(see :ref:`distributing-resources`). The `zip_safe` flag can be used to
-force or prevent zip Archive creation. In general you probably don't want
-your packages to be installed as zip files because some tools do not
-support them and they make debugging a lot harder.
+大多数 `setup` 的参数可以望文生义,但是 `include_package_data` 和 `zip_safe`
+可以不容易理解。 `include_package_data` 告诉 distribute 要搜索一个
+`` 文件,把文件内容所匹配的所有条目作为包数据安装。可以通过使用这个
+参数分发 Python 模块的静态文件和模板(参见 :ref:`distributing-resources` )。
+`zip_safe` 标志可用于强制或防止创建 zip 压缩包。通常你不会想要把包安装为 zip
.. _distributing-resources:
-Distributing Resources
-If you try to install the package you just created, you will notice that
-folders like `static` or `templates` are not installed for you. The
-reason for this is that distribute does not know which files to add for
-you. What you should do, is to create a `` file next to your
-`` file. This file lists all the files that should be added to
-your tarball::
+如果你尝试安装上文创建的包,你会发现诸如 `static` 或 `templates` 之类的文件夹
+没有被安装。原因是 distribute 不知道要为你添加哪些文件。你要做的是:在你的
+`` 文件旁边创建一个 `` 文件。这个文件列出了所有应当添加到
+tar 压缩包的文件::
recursive-include yourapplication/templates *
recursive-include yourapplication/static *
-Don't forget that even if you enlist them in your `` file, they
-won't be installed for you unless you set the `include_package_data`
-parameter of the `setup` function to `True`!
+不要忘了把 `setup` 函数的 `include_package_data` 参数设置为 `True` !否则即使把
+内容在 `` 文件中全部列出来也没有用。
-Declaring Dependencies
-Dependencies are declared in the `install_requires` parameter as list.
-Each item in that list is the name of a package that should be pulled from
-PyPI on installation. By default it will always use the most recent
-version, but you can also provide minimum and maximum version
-requirements. Here some examples::
+依赖是在 `install_requires` 参数中声明的,这个参数是一个列表。列表中的每一项都是
+一个需要在安装时从 PyPI 获得的包。缺省情况下,总是会获得最新版本的包,但你可以
-I mentioned earlier that dependencies are pulled from PyPI. What if you
-want to depend on a package that cannot be found on PyPI and won't be
-because it is an internal package you don't want to share with anyone?
-Just still do as if there was a PyPI entry for it and provide a list of
-alternative locations where distribute should look for tarballs::
+我前面提到,依赖包都从 PyPI 获得的。但是如果要从别的地方获得包怎么办呢?你只要
-Make sure that page has a directory listing and the links on the page are
-pointing to the actual tarballs with their correct filenames as this is
-how distribute will find the files. If you have an internal company
-server that contains the packages, provide the URL to that server there.
+请确保页面上有一个目录列表,且页面上的链接指向正确的 tar 压缩包。这样
+distribute 就会找到文件了。如果你的包在公司内部网络上,请提供指向服务器的 URL 。
-Installing / Developing
+安装 / 开发
-To install your application (ideally into a virtualenv) just run the
-`` script with the `install` parameter. It will install your
-application into the virtualenv's site-packages folder and also download
-and install all dependencies::
+要安装你的应用(理想情况下是安装到一个 virtualenv ),只要运行带 `install` 参数
+的 `` 脚本就可以了。它会将你的应用安装到 virtualenv 的 site-packages
$ python install
-If you are developing on the package and also want the requirements to be
-installed, you can use the `develop` command instead::
+如果你正开发这个包,同时也希望相关依赖被安装,那么可以使用 `develop` 来代替::
$ python develop
-This has the advantage of just installing a link to the site-packages
-folder instead of copying the data over. You can then continue to work on
-the code without having to run `install` again after each change.
+这样做的好处是只安装一个指向 site-packages 的连接,而不是把数据复制到那里。这样
+在开发过程中就不必每次修改以后再运行 `install` 了。
.. _distribute:

0 comments on commit 62c571f

Please sign in to comment.