ffcx.formatting
Compiler stage 5: Code formatting.
This module implements the formatting of UFC code from a given dictionary of generated C++ code for the body of each UFC function.
It relies on templates for UFC code available as part of the module ufcx_utils.
Functions
|
Format given code in UFC format. |
|
Write code to files. |
- class ffcx.formatting.CodeBlocks(file_pre: list[tuple[str, str]], integrals: list[tuple[str, str]], forms: list[tuple[str, str]], expressions: list[tuple[str, str]], file_post: list[tuple[str, str]])[source]
Bases:
NamedTupleStorage of code blocks of the form (declaration, implementation).
Blocks for integrals, forms and expressions, and start and end of file output
Create new instance of CodeBlocks(file_pre, integrals, forms, expressions, file_post)
- expressions: list[tuple[str, str]]
Alias for field number 3
- file_post: list[tuple[str, str]]
Alias for field number 4
- file_pre: list[tuple[str, str]]
Alias for field number 0
- forms: list[tuple[str, str]]
Alias for field number 2
- integrals: list[tuple[str, str]]
Alias for field number 1
- class ffcx.formatting.Path(*args, **kwargs)[source]
Bases:
PurePathPurePath subclass that can make system calls.
Path represents a filesystem path but unlike PurePath, also offers methods to do system calls on path objects. Depending on your system, instantiating a Path will return either a PosixPath or a WindowsPath object. You can also instantiate a PosixPath or WindowsPath directly, but cannot instantiate a WindowsPath on a POSIX system or vice versa.
Construct a PurePath from one or several strings and or existing PurePath objects. The strings and path objects are combined so as to yield a canonicalized path, which is incorporated into the new PurePath object.
- absolute()[source]
Return an absolute version of this path by prepending the current working directory. No normalization or symlink resolution is performed.
Use resolve() to get the canonical path to a file.
- exists(*, follow_symlinks=True)[source]
Whether this path exists.
This method normally follows symlinks; to check whether a symlink exists, add the argument follow_symlinks=False.
- expanduser()[source]
Return a new path with expanded ~ and ~user constructs (as returned by os.path.expanduser)
- glob(pattern, *, case_sensitive=None)[source]
Iterate over this subtree and yield all existing files (of any kind, including directories) matching the given relative pattern.
- hardlink_to(target)[source]
Make this path a hard link pointing to the same file as target.
Note the order of arguments (self, target) is the reverse of os.link’s.
- classmethod home()[source]
Return a new path pointing to the user’s home directory (as returned by os.path.expanduser(‘~’)).
- is_file()[source]
Whether this path is a regular file (also True for symlinks pointing to regular files).
- iterdir()[source]
Yield path objects of the directory contents.
The children are yielded in arbitrary order, and the special entries ‘.’ and ‘..’ are not included.
- lchmod(mode)[source]
Like chmod(), except if the path points to a symlink, the symlink’s permissions are changed, rather than its target’s.
- lstat()[source]
Like stat(), except if the path points to a symlink, the symlink’s status information is returned, rather than its target’s.
- open(mode='r', buffering=-1, encoding=None, errors=None, newline=None)[source]
Open the file pointed to by this path and return a file object, as the built-in open() function does.
- read_text(encoding=None, errors=None)[source]
Open the file in text mode, read it, and close the file.
- rename(target)[source]
Rename this path to the target path.
The target path may be absolute or relative. Relative paths are interpreted relative to the current working directory, not the directory of the Path object.
Returns the new Path instance pointing to the target path.
- replace(target)[source]
Rename this path to the target path, overwriting if that path exists.
The target path may be absolute or relative. Relative paths are interpreted relative to the current working directory, not the directory of the Path object.
Returns the new Path instance pointing to the target path.
- resolve(strict=False)[source]
Make the path absolute, resolving all symlinks on the way and also normalizing it.
- rglob(pattern, *, case_sensitive=None)[source]
Recursively yield all existing files (of any kind, including directories) matching the given relative pattern, anywhere in this subtree.
- samefile(other_path)[source]
Return whether other_path is the same or not as this file (as returned by os.path.samefile()).
- stat(*, follow_symlinks=True)[source]
Return the result of the stat() system call on this path, like os.stat() does.
- symlink_to(target, target_is_directory=False)[source]
Make this path a symlink pointing to the target path. Note the order of arguments (link, target) is the reverse of os.symlink.
- touch(mode=438, exist_ok=True)[source]
Create this file with the given access mode, if it doesn’t exist.
- unlink(missing_ok=False)[source]
Remove this file or link. If the path is a directory, use rmdir() instead.
- ffcx.formatting.format_code(code: CodeBlocks) tuple[str, str][source]
Format given code in UFC format. Returns two strings with header and source file contents.