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

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.

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