fgen.jinja_environment#

Jinja environment to use while generating wrappers

JINJA_ENV#

JINJA_ENV = <jinja2.environment.Environment object>#

Jinja2 environment to use for template rendering

indent_based_on_first_line#

indent_based_on_first_line(code, indent)[source]#

Indent code based on the indent of the first line.

If the first line does not have indent equal to indent, all the code except the first line will have an indent added such that the first line would have an indent of indent. We exclude the first line so that the indent can be included in the jinja template too, which makes it easier to read what is going on.

Parameters:
  • code (str) – Code to indent

  • indent (str) – Indent to ensure that the first line has

Returns:

str – Indented code

strip_empty_lines#

strip_empty_lines(inp)[source]#

Strip empty lines

More specifically, turn lines that only have whitespace into a single newline character. This is a workaround until we start formatting our Fortran as part of the generation process (magicc/fgen#26).

Parameters:

inp (str) – Input string

Returns:

str – Input string, with all whitespace lines replaced by a single newline character.

get_template_in_directory#

get_template_in_directory(template_name, template_directory, env)[source]#

Get template that is in the directory specified by file_dunder

Parameters:
  • template_name (str) – Name of the template to get

  • template_directory (pathlib.Path) –

    The directory from which to retrieve the template.

    If you want to retrieve a template in the same directory as the file that is calling this function, call get_template_in_directory(template_name, Path(__file__).parent), env).

  • env (jinja2.environment.Environment) – Jinja2 environment to use when loading the template. This must be using a jinja2.loaders.FileSystemLoader loader. The loader must only have one search path.

Returns:

jinja2.environment.Template – Loaded template

post_process_jinja_rendering#

post_process_jinja_rendering(inp)[source]#

Post-process the result from Jinja

This fixes things we can’t work out how to fix with jinja

Parameters:

inp (str) – Result of formatting with jinja

Returns:

str – Post-processed result