Introduction and use of the Python build tool buildout

Source: Internet
Author: User
Tags plone virtualenv

Came to the new company to work, the first is to put their own environment to build up. Buildout is used as a build tool for Python projects.

So what is Buildout?

Buildout is an automated build tool.
Developed and maintained by the Zope team. The package name is zc.buildout .

buildoutYou can build an independent, dependent environment for your app. Similar to virtualenv , but they are different.
Roughly speaking, buildout the supported features are more automated and specific positioning is different.

First we create a python-independent sandbox, whether it's virtualenv or Miniconda. Install the buildout after you have configured the sandbox:

Pip Install Zc.buildout

Create a configuration file buildout.cfg. The configuration file is the core of the entire build process, where I go directly to a more complete configuration to illustrate the meaning of the field:

[Buildout]develop=. Index= Mirror AddressNewest=falseupdate-versions-file =Versions.cfgextends=versions.cfgrelative-paths =Trueshow-picked-versions =trueversions=Versionsparts=App Test Gen-Thrift[app]recipe=Zc.recipe.egginterpreter=Pythoneggs=zticket gunicorn setuptools tzone.cli ipython miller2 Flake8extra-paths = ${buildout:directory}/gen-Py[gen-Thrift]recipe=Plone.recipe.commandcommand= I can use one command at randomUpdate-command =${:command}[test]recipe=Pbp.recipe.noserunnereggs=${app:eggs} coverage boring mockdefaults=-vd--with-coverage--with-xunit--cover-xml--cover-package=zticket--Boringextra-paths = ${buildout:directory}/gen-py

As you can see, the configuration uses the INI FILE syntax, the details can be seen in the description and wording of refer, here is just a mention.

[Buildout]: This is a necessary session block.

Develop: A thing that is used to manage a development library, which is generally not required. The '. ' symbol is configured here, and the Develop-eggs folder generated when the Buildout command is executed will be empty.

Newest: This parameter is true by default, and if True, the latest version is always checked at buildout, and if False, the version will be updated only if the package does not meet the requirements.

Update-versions-file: Specifies a package-dependent update file. Generally use VERSIONS.CFG to save the required dependencies.

Extended: Specifies the extension configuration.

Relative-path: Enables relative paths.

Show-picked-versions: This field is false by default, and if true, when Buildout finds an up-to-date release and satisfies the requirement declaration, Will re-write a configuration into the Versions.cfg file, that is, the Update-versions-file configuration file. Similar to this format:

# Required by: # opentracing==1.0rc3futures = 3.0.5

Versions: The default is versions more details can refer to here. Http://docs.buildout.org/en/latest/getting-started.html#pinned-versions.

By this point, Buildout's basic configuration is over. Each of the sections below can be understood as an additional app. The app section name is stated by the parts as configured above.

The following is a description of what each parts inside the block.

Under app section:

Recipes: First, each block must contain a recipe project, which is used by the gods to use the tools themselves. A variety of other packages can be downloaded to the PyPI, each with different uses. Perhaps it can be understood here that different plugins can be used. The most commonly used Zc.recipe.egg is the recipe, which can be used to install all kinds of bags and pack them into egg.

Interpreter: Creates an environment that contains eggs and dependencies under the Bin directory.

Eggs: is a list that is used to install one or more setuptools dependent eggs.

Extra-paths: This can be understood as the path that needs to be added to the Sys.path after the application is compiled.

Gen-thrift section below:

Using a plone.recipe.command recipe, this recipe function is described in Https://pypi.python.org/pypi/plone.recipe.command? Build to execute a command.

Command: Commands that need to be executed at build time.

Update-command: The command to execute when the build is updated.

Test section below:

Use the recipe Pbp.recipe.noserunner to view the https://pypi.python.org/pypi/pbp.recipe.noserunner/0.2.6.

Eggs: Similar to the build dependency package above, specify the relevant eggs.

Default: Specifies a testrunner option.

Extra-paths: Also add related Sys.path to the application.

After you've configured the settings, you're ready to start a happy build. After build, you can see that all dependent packages are installed in the folder eggs. Just like this:

If you are careful enough, you can see that these are all folders. But the Sys.path directly add their path, you can import them directly.

Sys.path like this:

You can see that buildout helps us complete a closed environment and automatically implements package management. A little Pip+virtualenv/conda feeling. And this environment can be arbitrarily moved in the same Python interpreter environment after the compilation is complete.

Also, it is important to download the environment, we can reset the global pip and Easy_install source to speed up the package installation.

Modify with Environment variables:

Export Pip_index_url=https://mirror. in. zhihu.com/simple

Modify by configuration file:

~/.pip/pip.conf[global]extra-index-url = Mirror~/= Mirror

In addition, the other thought after adding, above.

Reference:

Http://yabin.me/2017/07/25/buildout Build Tool/buildout build tool

https://www-archive.mozilla.org/projects/cck/docs/WizardMachine/syntax.html INI File Syntax

http://docs.buildout.org/en/latest/reference.html Buildout Official documentation

Introduction and use of the Python build tool buildout

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.