Python module (original) (raw)

This module provides support for finding and building extensions against python installations, be they python 2 or 3.

If you want to build and package Python extension modules using tools compatible with PEP-517, check outmeson-python.

If you are building Python extension modules against a Python interpreter located in a venv or Conda environment, you probably want to setpython.install_env=auto; see Python module options for details.

Added 0.46.0

Functions

find_installation()

pymod.find_installation(name_or_path, ...)

Find a python installation matching name_or_path.

That argument is optional, if not provided then the returned python installation will be the one used to run Meson.

If provided, it can be:

Keyword arguments are the following:

Returns: a python installation

python_installation object

The python_installation object is an external_program, with several added methods.

Methods

path()

str py_installation.path()

(since 0.50.0)

Deprecated in 0.55: use fullpath() instead

Works like the path method of ExternalProgram objects. Was not provided prior to 0.50.0 due to a bug.

full_path()

str py_installation.full_path()

(since 0.55.0)

Works like the full_path() method of ExternalProgram objects: external_program.full_path()

extension_module()

shared_module py_installation.extension_module(module_name, list_of_sources, ...)

Create a shared_module() target that is named according to the naming conventions of the target platform.

All positional and keyword arguments are the same as forshared_module(), excluding name_suffix and name_prefix, and with the addition of the following:

Additionally, the following diverge from shared_module()'s default behavior:

Note that Cython support uses extension_module, see the reference for Cython.

since 0.63.0 extension_module automatically adds a dependency to the library if one is not explicitly provided. To support older versions, the user may need to add dependencies : py_installation.dependency(), see dependency().

Returns: a build_tgt object

dependency()

python_dependency py_installation.dependency(...)

since 0.53.0

This method accepts no positional arguments, and the same keyword arguments as the standard dependency() function. It also supports the following keyword argument:

Returns: a python dependency

install_sources()

void py_installation.install_sources(list_of_files, ...)

Install actual python sources (.py).

Source files to install are given as positional argument, in the same way as forinstall_data(). Supported keyword arguments are:

Since 0.60.0 python.platlibdir and python.purelibdir options can be used to control the default installation path. See Python module options.

get_install_dir()

string py_installation.get_install_dir(...)

Retrieve the directory install_sources() will install to.

It can be useful in cases where install_sources cannot be used directly, for example when using configure_file().

This function accepts no arguments, its keyword arguments are the same as install_sources().

Since 0.60.0 python.platlibdir and python.purelibdir options can be used to control the default installation path. See Python module options.

Returns: A string

language_version()

string py_installation.language_version()

Get the major.minor python version, eg 2.7.

The version is obtained through the sysconfig module.

This function expects no arguments or keyword arguments.

Returns: A string

get_path()

string py_installation.get_path(path_name, fallback)

Get a path as defined by the sysconfig module.

For example:

purelib = py_installation.get_path('purelib')

This function requires at least one argument, path_name, which is expected to be a non-empty string.

If fallback is specified, it will be returned if no path with the given name exists. Otherwise, attempting to read a non-existing path will cause a fatal error.

Returns: A string

has_path()

    bool py_installation.has_path(path_name)

Returns: true if a path named path_name can be retrieved withget_path(), false otherwise.

get_variable()

string py_installation.get_variable(variable_name, fallback)

Get a variable as defined by the sysconfig module.

For example:

py_bindir = py_installation.get_variable('BINDIR', '')

This function requires at least one argument, variable_name, which is expected to be a non-empty string.

If fallback is specified, it will be returned if no variable with the given name exists. Otherwise, attempting to read a non-existing variable will cause a fatal error.

Returns: A string

has_variable()

    bool py_installation.has_variable(variable_name)

Returns: true if a variable named variable_name can be retrieved with get_variable(), false otherwise.

python_dependency object

This dep object subclass will try various methods to obtain the compiler and linker arguments, starting with pkg-config then potentially using information obtained from python's sysconfigmodule.

It exposes the same methods as its parent class.