pyccel.codegen.compiling.compilers module#

Module handling everything related to the compilers used to compile the various generated files

class pyccel.codegen.compiling.compilers.Compiler(vendor: str, debug=False)[source]#

Bases: object

Class which handles all compiler options.

This class uses the compiler vendor or a json file to collect all compiler configuration parameters. These are then used to correctly print compiler commands such as shared library compilation commands or executable creation commands.

Parameters:
  • vendor (str) – Name of the family of compilers.

  • debug (bool) – Indicates whether we are compiling in debug mode.

acceptable_bin_paths = None#
compile_module(compile_obj, output_folder, language, verbose)[source]#

Compile a module.

Compile a file containing a module to a .o file.

Parameters:
  • compile_obj (CompileObj) – Object containing all information about the object to be compiled.

  • output_folder (str) – The folder where the result should be saved.

  • language (str) – Language that we are compiling.

  • verbose (int) – Indicates the level of verbosity.

compile_program(compile_obj, output_folder, language, verbose)[source]#

Compile a program.

Compile a file containing a program to an executable.

Parameters:
  • compile_obj (CompileObj) – Object containing all information about the object to be compiled.

  • output_folder (str) – The folder where the result should be saved.

  • language (str) – Language that we are compiling.

  • verbose (int) – Indicates the level of verbosity.

Returns:

The name of the generated executable.

Return type:

str

compile_shared_library(compile_obj, output_folder, language, verbose, sharedlib_modname=None)[source]#

Compile a module to a shared library.

Compile a file containing a module with C-API calls to a shared library which can be called from Python.

Parameters:
  • compile_obj (CompileObj) – Object containing all information about the object to be compiled.

  • output_folder (str) – The folder where the result should be saved.

  • language (str) – Language that we are compiling.

  • verbose (int) – Indicates the level of verbosity.

  • sharedlib_modname (str, optional) – The name of the library that should be generated. If none is provided then it defaults to matching the name of the file.

Returns:

Generated library name.

Return type:

str

property compiler_family#

Get the compiler family.

Get an identifier for the compiler family. This is equal to the compiler-family key in the default compilers or to the stem of the provided JSON compiler file.

export_compiler_info(compiler_export_filename)[source]#

Export the compiler configuration to a json file.

Print the information describing all compiler options to the specified file in json format. This file can be used for debugging purposes or it can be manually modified and fed back to Pyccel to correct compilation problems or request more unusual flags/include directories/etc.

Parameters:

compiler_export_filename (str | Path) – The name of the file where the compiler configuration should be printed.

get_exec(extra_compilation_tools, language=None)[source]#

Obtain the path of the executable based on the specified compilation tools.

The get_exec method is responsible for retrieving the path of the executable based on the specified compilation tools. It is used internally in the Pyccel module. In particular the executable depends on whether MPI is used.

Parameters:
  • extra_compilation_tools (str) – Specifies the compilation tools to be used.

  • language (str, optional) – The language being compiled. This argument should be provided unless this method is called from a method of this class after setting self._language_info.

Returns:

The path of the executable corresponding to the specified compilation tools.

Return type:

str

Raises:

PyccelError – If the compiler executable cannot be found.

property is_debug#

Check if debug mode is activated.

Check if debug mode is activated.

static run_command(cmd, verbose)[source]#

Run the provided command and collect the output.

Run the provided compilation command, collect the output and raise any necessary errors if the file does not compile.

Parameters:
  • cmd (list of str) – The command to run.

  • verbose (int) – Indicates the level of verbosity.

Returns:

The exact command that was run.

Return type:

str

Raises:

RuntimeError – Raises RuntimeError if the file does not compile.

pyccel.codegen.compiling.compilers.get_condaless_search_path(conda_warnings='basic')[source]#

Get a list of paths excluding the conda paths.

Get the value of the PATH variable to be set when searching for the compiler This is the same as the environment PATH variable but without any conda paths.

Parameters:

conda_warnings (str, optional) – Specify the level of Conda warnings to display (choices: off, basic, verbose), Default is ‘basic’.

Returns:

A list of paths excluding the conda paths.

Return type:

str