Python related tasks and macros

<getPythonPath>

Scope: Python projects

Description

The getPythonPath task resolves the python path of an eclipse project. This task reads and parses the python related project artefacts in order to access these pathes. The pythonpath can be resolved to ant's path type or to a string property. The pythonpath can be resolved in a relative (to the given workspace) or absolute manner. In case the pythonpath is resolved to a path type, it can be referenced using the ref-id attribute wherever a pythonpath must be used.

Arguments

The getPythonPath task provides the following arguments:

Argument Description Required
workspaceDirectory Absolute path of the workspace directory Either 'workspaceDirectory' or 'workspaceId' has to be specified
workspaceId The identifier of a defined workspace (see <workspaceDefinition>) Either 'workspaceDirectory' or 'workspaceId' has to be specified
projectName Name of the eclipse project yes
property The name of the property that will hold the resolved path either 'pathId' or 'property' has to be specified
pathId The reference id for the path that will be created either 'pathId' or 'property' has to be specified
pathSeparator The system-dependent path-separator character. This character is used to separate filenames in a sequence of files. no (default: On UNIX systems, this character is ':'; on Microsoft Windows systems it is ';')
dirSeparator The system-dependent default name-separator character. no (default: On UNIX systems the value of this field is '/'; on Microsoft Windows systems it is '\')
relative Determines whether the result path should be resolved relative to the given workspace or absolute no (default: false)
ignoreruntime Boolean value that determines whether a runtime has to be set or not. If set to true you must register a python runtime first. no (default: false)

Example usage

The following example resolves the pythonpath of the project simple.python.project to the property pythonpath. All entries are separated by the default path separator (as defined in java.io.File.separator). You can use the pathSeparator attribute to explicitly specify a character that is used to separate the entries of the pythonpath:

  <ant4eclipse:getPythonPath 
    workspaceDirectory="${workspace}"
    projectName="simple.python.project"
    property="pythonpath"
    ignoreruntime="true"
    pathSeparator=";"
  />

You can also export a pythonpath to an ant path:

  <ant4eclipse:getPythonPath 
    pathId="pythonpath"
    workspaceDirectory="${workspace}"
    ignoreruntime="true"
    projectName="simple.python.project" 
  />

You can use the relative attribute to request a pythonpath that consists of path entries relative to the specified workspace:

  <ant4eclipse:getPythonPath 
    property="pythonpath"
    workspaceDirectory="${workspace}"
    projectName="myProject"
    pathSeparator=";"
    ignoreruntime="true"
    relative="true"
  />

<getPythonSourcePath>

Scope: Python projects

Description

The getPythonSourcePath task resolves the source folders of an eclipse python project. The source folders can be resolved to ant's path-type or to a string property. The path can be resolved in a relative (to the given workspace) or absolute manner.

Arguments

The getPythonClassPath task provides the following arguments:

Argument Description Required
workspaceDirectory Absolute path of the workspace directory Either 'workspaceDirectory' or 'workspaceId' has to be specified
workspaceId The identifier of a defined workspace (see <workspaceDefinition>) Either 'workspaceDirectory' or 'workspaceId' has to be specified
projectName Name of the eclipse project yes
property The name of the property that will hold the resolved path either 'pathId' or 'property' has to be specified
pathId The reference id for the path that will be created either 'pathId' or 'property' has to be specified
pathSeparator The system-dependent path-separator character. This character is used to separate filenames in a sequence of files. no (default: On UNIX systems, this character is ':'; on Microsoft Windows systems it is ';')
dirSeparator The system-dependent default name-separator character. no (default: On UNIX systems the value of this field is '/'; on Microsoft Windows systems it is '\')
relative Determines whether the result path should be resolved relative to the given workspace or absolute no (default: false)
allowMultipleFolders Must set to true to allow multiple source folders. If allowMultipleFolders is false and the result contains multiple folders, an BuildException is thrown. no (default: false)

Example usage

Resolving the source path to an ant path

The following example shows how to resolve the source path of an eclipse python project to an ant path:

  <ant4eclipse:getPythonSourcePath 
    pathId="sourcepath"
    workspaceDirectory="${workspace}" 
    projectName="simple.python.project" 
  />

Resolving the source path to an ant property

If you don't want to have the path as a path object but rather as a string Property, you can use the property parameter instead of the pathId argument. If you export the source path to a property, all its entries are separated by the operating systems default path separator (as defined in java.io.File.separator). You can use the pathSeparator attribute to explicitly specify a character that is used to separate the entries of the source path.

  <ant4eclipse:getPythonSourcePath 
    property="sourcepath"
    workspaceDirectory="${workspace}" 
    projectName="simple.python.project" 
  />

Resolving relative pathes

The entries of the paths are absolute paths by default. You can use the boolean relative argument to receive a path that consists of path entries that are relative to the project directory.

  <ant4eclipse:getPythonSourcePath 
    property="sourcepath"
    workspaceDirectory="${workspace}" 
    projectName="simple.source.project"
    relative="true" 
  />

<pythonContainer>

Scope: Python projects

Description

The pythonContainer type allows to declare python installations where each installation obviously provides an interpreter and a library (the runtime environment).

Arguments

The pythonContainer task provides the following arguments:

Argument Description Required
default The id of the python installation that shall be used as the default. no (Defaults to the first listed installation).

Each installation will be declared using a separate child element pyre within that container element:

Argument Description Required
id The id allowing to identify the installation. yes
location The location to the root of a python installation. yes
sitePackages Boolean value allowing to decide whether site packages (located within the directory site-packages) shall be considered part of the pythonpath or not. no (Default: true)

Currently the following types of python are supported:

Example usage

  <ant4eclipse:pythonContainer default="cpython-2.5">
    <ant4eclipse:pyre id="cpython-2.5" location="/usr/lib/python/cpython/2.5"/>
    <ant4eclipse:pyre id="cpython-2.6" location="/usr/lib/python/cpython/2.6"/>
  </ant4eclipse:pythonContainer>

<pythonDoc>

Scope: Python projects

Description

The pythonDoc task allows to extract api documentation from python source code. Rather than using the internal documentation tools from python this task uses Epydoc which produces a much nicer document structure. This package is bundled as a library of this ant task so it's not necessary to explicitly perform any kind of installation.

Arguments

The pythonDoc task provides the following arguments:

Argument Description Required
sourcedir A directory containing the python source code. yes
destdir The location where the generated api documentation will be stored to. yes
runtime The id of a python runtime used to generate the documentation with. yes

Example usage

Simple generation of python documentation:

  <ant4eclipse:pythonContainer default="cpython-2.5">
    <ant4eclipse:pyre id="cpython-2.5" location="/usr/lib/cpython/2.5"/>
    <ant4eclipse:pyre id="cpython-2.6" location="/usr/lib/cpython/2.6"/>
  </ant4eclipse:pythonContainer>
 
  <ant4eclipse:pythonDoc 
    runtime="cpython-2.6"
    sourcedir="/users/kasimir/python/sample1/sources"
    destdir="/users/kasimir/python/sample1/apidoc"
  />