Skip to main content

specfile.macro_definitions

CommentOutStyle

class CommentOutStyle(Enum)

Style of commenting out a macro definition.

DNL

Using the %dnl macro.

HASH

Replacing % in %global/%define with #.

OTHER

Prepending the definition with # followed by arbitrary string.

MacroDefinition

class MacroDefinition()

Class that represents a macro definition. Macro definition starts with %global or %define keyword, followed by macro name, optional argument string enclosed in parentheses and macro body.

Attributes:

  • name - Macro name.
  • body - Macro body.
  • is_global - Whether the macro is defined using %global rather than %define.
  • commented_out - Whether the definition is commented out.
  • comment_out_style - Style of commenting out. See CommentOutStyle.
  • valid - Whether the definition is not located in a false branch of a condition.

__init__

def __init__(name: str,
body: str,
is_global: bool,
commented_out: bool,
comment_out_style: CommentOutStyle,
whitespace: Tuple[str, str, str, str],
prefix: str = "",
valid: bool = True,
preceding_lines: Optional[List[str]] = None) -> None

Initializes a macro definition object.

Arguments:

  • name - Macro name.
  • body - Macro body.
  • is_global - Whether the macro is defined using %global rather than %define.
  • commented_out - Whether the definition is commented out.
  • comment_out_style - Style of commenting out. See CommentOutStyle.
  • whitespace - Tuple of whitespace - (preceding the definition, preceding macro name, preceding macro body, following the body).
  • prefix - String preceding the start of the definition.
  • valid - Whether the definition is not located in a false branch of a condition.
  • preceding_lines - Extra lines that precede the definition.

get_position

def get_position(container: "MacroDefinitions") -> int

Gets position of this macro definition in the spec file.

Arguments:

  • container - MacroDefinitions instance that contains this macro definition.

Returns:

Position expressed as line number (starting from 0).

MacroDefinitions

class MacroDefinitions(UserList[MacroDefinition])

Class that represents a list of all macro definitions.

Attributes:

  • data - List of individual macro definitions.

__init__

def __init__(data: Optional[List[MacroDefinition]] = None,
remainder: Optional[List[str]] = None) -> None

Initializes a macro definitions object.

Arguments:

  • data - List of individual macro definitions.
  • remainder - Leftover lines that can't be parsed into macro definitions.

find

def find(name: str, position: Optional[int] = None) -> int

Finds a macro definition with the specified name. If position is not specified, returns the first valid matching macro definiton. If there is no such macro definition, returns the first match, if any. If position is specified and there is a matching macro definition at that position, it is returned, otherwise ValueError is raised.

Arguments:

  • name - Name of the tag to find.
  • position - Optional position in the spec file.

Returns:

Index of the matching tag.

Raises:

  • ValueError - If there is no match.

parse

@classmethod
def parse(cls,
lines: List[str],
with_conditions: bool = False,
context: Optional["Specfile"] = None) -> "MacroDefinitions"

Parses given lines into macro defintions.

Arguments:

  • lines - Lines to parse.
  • with_conditions - Whether to process conditions before parsing and populate the valid attribute.
  • context - Specfile instance that defines the context for macro expansions.

Returns:

New instance of MacroDefinitions class.