craftr.ext.compiler.cython

Interface for compiling Cython source code. See also Using Craftr for Cython projects.

class craftr.ext.compiler.cython.CythonCompiler(program=None, detect=True, **kwargs)[source]

Compiler interface for Cython. Note that this class does not provide functionality to actually compile the C/C++ source files generated by Cython.

A small example:

from craftr import path, options
from craftr.ext.compiler.cython import cythonc

c_files = cythonc.compile(
  py_sources = path.glob('mymodule/**/*.pyx'),
  python_version = int(options.get('python_version', 3)),
  fast_fail = True,
  cpp = True,
)
compile(py_sources, outputs=None, frameworks=(), target_name=None, **kwargs)[source]

Compile the specified py_sources files to C or C++ source files.

Parameters:
  • py_sources – A list of .pyx or .py files.
  • outputs – Override the output filenames. If omitted, default output filenames are generated.
  • frameworks – List of additional frameworks.
  • target_name – Alternative target name.
  • include – Additional include directories for Cython.
  • fast_fail – True to enable the --fast-fail flag.
  • cpp – True to translate to C++ source files.
  • embed – Pass --embed to Cython. Note that if multiple files are specfied in “py_sources”, all of them will have a int main() function.
  • additional_flags – List of additional flags for the Cython command.
  • python_version – The Python version to build for (2 or 3). Defaults to 3.

Produces the following meta variables in the returned target:

  • cython_outdir – The common output directory of the Cython source files
compile_project(main=None, sources=[], python_bin='python', cc=None, ld=None, defines=(), **kwargs)[source]

Compile a set of Cython source files into dynamic libraries for the Python version specified with “python_bin”.

Parameters:
  • main – Optional filename of a .pyx file that will be compiled with the --embed option and compiled to an executable file.
  • sources – A list of the .pyx source files.
  • python_bin – The name of the Python executable to compile for.
  • cc – Alternative C/C++ compiler implementation. Defaults to platform.cc
  • ld – Alternative linker implementation. Defaults to platform.ld
  • defines – Additional defines for the compiler invokation.
Returns:

A ProjectResult object

name = 'Cython'
class craftr.ext.compiler.cython.PythonInfo(pybin)[source]

Container class for meta information of an installed Python version. The information is read from the craftr.ext.python module.

fw

The framework retrieved with get_python_framework()

conf

The Python version’s setuptools configuration retrieved with get_python_config_vars.

major_version

Returns the major version number of the Python installation.

craftr.ext.compiler.cython.cythonc = <craftr.ext.compiler.cython.CythonCompiler object>

An instance of the CythonCompiler created with the default arguments.