Skip to main content

specfile.tags

get_tag_name_regex

def get_tag_name_regex(name: str) -> str

Contructs regex corresponding to the specified tag name.

Comment

class Comment()

Class that represents a comment.

Attributes:

  • text - Text of the comment.
  • prefix - Comment prefix (hash character usually surrounded by some amount of whitespace).

Comments

class Comments(UserList[Comment])

Class that represents comments associated with a tag, that is consecutive comment lines located directly above a tag definition.

Attributes:

  • data - List of individual comments.

__init__

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

Initializes a comments object.

Arguments:

  • data - List of individual comments.
  • preceding_lines - Extra lines that precede comments associated with a tag.

raw

@property
def raw() -> List[str]

List of comment texts

parse

@classmethod
def parse(cls, lines: List[str]) -> "Comments"

Parses list of lines into comments.

Arguments:

  • lines - List of lines that precede a tag definition.

Returns:

New instance of Comments class.

Tag

class Tag()

Class that represents a spec file tag.

Attributes:

  • name - Name of the tag.
  • value - Literal value of the tag as stored in the spec file.
  • comments - List of comments associated with the tag.

__init__

def __init__(name: str,
value: str,
separator: str,
comments: Comments,
valid: bool = True,
prefix: Optional[str] = None,
suffix: Optional[str] = None,
context: Optional["Specfile"] = None) -> None

Initializes a tag object.

Arguments:

  • name - Name of the tag.
  • value - Literal value of the tag as stored in the spec file.
  • separator - Separator between name and literal value (colon usually surrounded by some amount of whitespace).
  • comments - List of comments associated with the tag.
  • valid - Whether the tag is not located in a false branch of a condition.
  • prefix - Characters preceding the tag on a line.
  • suffix - Characters following the tag on a line.
  • context - Specfile instance that defines the context for macro expansions.

normalized_name

@property
def normalized_name() -> str

Normalized name of the tag. The first character is capitalized and the rest lowercased.

expanded_value

@property
def expanded_value() -> Optional[str]

Value of the tag after expanding macros.

get_position

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

Gets position of this tag in a section.

Arguments:

  • container - Tags instance that contains this tag.

Returns:

Position expressed as line number (starting from 0).

Tags

class Tags(UserList[Tag])

Class that represents all tags in a certain %package section.

Tags can be accessed by index or conveniently by name as attributes:

# print name of the first tag
print(tags[0].name)

# set value of Url tag
tags.url = 'https://example.com'

# remove Source1 tag
del tags.source1

Attributes:

  • data - List of individual tags.

__init__

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

Initializes a tags object.

Arguments:

  • data - List of individual tags.
  • remainder - Leftover lines in a section that can't be parsed into tags.

find

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

Finds a tag with the specified name. If position is not specified, returns the first valid matching tag. If there is no such tag, returns the first match, if any. If position is specified and there is a matching tag 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,
section: Section,
context: Optional["Specfile"] = None) -> "Tags"

Parses a section into tags.

Arguments:

  • section - Section to parse.
  • context - Specfile instance that defines the context for macro expansions.

Returns:

New instance of Tags class.

get_raw_section_data

def get_raw_section_data() -> List[str]

Reconstructs section data from tags.

Returns:

List of lines forming the reconstructed section data.