6.3. Including build files and importing rules

6.3.1. Including build files

include() is a convenient function to help you structure your builds. As you might expect, you can include as many build files as you want. Once you include a build file, it will be parsed and all the rules will be executed, that means that some jobs will be scheduled and global variables will be available for other build files included thereafter (included files are processed in the order in which they are included).

As an example, if your project has two libraries “core” and “ui” that need to be built before you try to link your “beautifulapp”, then you need to include “core” and “ui” before “beautifulapp”. Simple, right?

pyke.include([path [, path_2 ... [, path_n]], export_locals = None)

Includes one or more pyke build files.

You can specify one or more build files or folders, so they will be included and processed after current file.

You can pass pyke build files:

include ('core/build.pyke')
include ('core/construct-the-core.pyke')

As well as folders (it will look for “build.pyke” inside), e.g:

include ('core/')

And you can also pass several folders/files at once, e.g:

include ('core', 'model', 'app', 'view/build-the-view.pyke')
include (['core', 'model', 'app'])

Please note that the build files will be processed in the same order as included, so in last example, from ‘model’ build scripts you can use anything built on ‘core’ module, but not the other way around.

You should also note that each included file will have no global variables, thus, avoiding conflicts on big projects. There are several ways to share variables between build files, but you should probably want to use the global ‘g’ variable.

Another way to import variables from an included file is to pass this function either the “import_all” set to True (so everything will be imported), or “vars_to_import” argument with a regular expression or a list of regular expressions of the variables to import.

Please note that ALL variables defined in the master.pyke are global by design.

6.3.2. Importing rules

It is very handy to import rules from other pyke/python files.

The difference between pyke.importRules() and pyke.include() is that pyke.importRules() executes the python file as if it was inlined in the current file, importing all the variables, functions and classes in the current namespace, whereas pyke.include() does not import variables into the namespace.


Use this function to import rules defined in other pyke or python file.

You can only import one rule file at a time.

For example:

importRules ('myrules.py')
importRules ('rules/arch-%s.py' % g.arch.name)

In fact, the following two lines are fairly similar in behaviour:

from myrules import *
importRules ('myrules.py')

The main difference is that when importing rules with this function, the global ‘g’ variable is available inside myrules.py, as well as everything (functions, classes, ...) that have been defined in the pyke file before that file has been imported.

All variables on that file will be added to the global variables and will be available everywhere (existing variables will be replaced).

Table Of Contents

Previous topic

6.2. Sections

Next topic

6.4. Variables

This Page